src/Controller/AdherentController.php line 147

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Adherent;
  4. use App\Form\AdherentType;
  5. use App\Repository\AdherentRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use \Knp\Component\Pager\PaginatorInterface;
  11. use \App\Services\AppSevices;
  12. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  13. /**
  14.  * @Route("/user/adherent")
  15.  */
  16. class AdherentController extends AbstractController {
  17.     /**
  18.      * @Route("/Admin/", name="app_adherent_index", methods={"GET"})
  19.      */
  20.     public function index(Request $requestPaginatorInterface $paginatorAppSevices $services): Response {
  21.         $nom = ($request->query->get('nom')) == "" "all" $request->get('nom');
  22.         $prenom = ($request->query->get('prenom')) == "" "all" $request->get('prenom');
  23.         $numAd = ($request->query->get('numAd')) == "" "all" $request->get('numAd');
  24.         $email = ($request->query->get('email')) == "" "all" $request->get('email');
  25.         $usersListQuery $services->getAdherents(array("nom" => $nom"prenom" => $prenom"email" => $email"numAd" => $numAd
  26.                 ))->getQuery();
  27.         $adherents $paginator->paginate($usersListQuery$request->query->getInt('page'1), 89);
  28.         return $this->render('adherent/index.html.twig', [
  29.                     'adherents' => $adherents,
  30.         ]);
  31.     }
  32.     /**
  33.      * @Route("/Admin/adType", name="app_adherent_indexAdherent", methods={"GET"})
  34.      */
  35.     public function indexAdherent(Request $requestPaginatorInterface $paginatorAppSevices $services): Response {
  36.         $nom = ($request->query->get('nom')) == "" "all" $request->get('nom');
  37.         $prenom = ($request->query->get('prenom')) == "" "all" $request->get('prenom');
  38.         $numAd = ($request->query->get('numAd')) == "" "all" $request->get('numAd');
  39.         $email = ($request->query->get('email')) == "" "all" $request->get('email');
  40.         $adherents $services->getAdherents([])->getQuery()->getResult();
  41.         $arrayresult = array();
  42.         $typePrestation=$services->getTypePrestations([])->getQuery()->getResult();
  43.              $i=0;
  44.         foreach ($adherents as $adherent) {
  45.          
  46.             $types $services->getByTypePrestation(['id' => $adherent->getId()]);
  47.             $dette$services->getSumDette(['id' => $adherent->getId()]);
  48.             
  49.             if($types){
  50.             foreach ($types as $value) {
  51.                 $arrayresult[$i]['adeherent'] = $adherent;
  52.                 $arrayresult[$i]['prestation'][$value['lib']] = $value;
  53.                   $arrayresult[$i]['dette'] = $dette;
  54.             
  55.             }}
  56.             else{
  57.               $arrayresult[$i]['adeherent'] = $adherent;
  58.                $arrayresult[$i]['prestation'] = array();  
  59.                     $arrayresult[$i]['dette'] = $dette;
  60.             }
  61.                 $i++;
  62.         }
  63.         
  64.              $i=0;
  65.         foreach ($adherents as $adherent) {
  66.          
  67.             $types $services->getSumPrestation(['id' => $adherent->getId()]);
  68.             $dette$services->getSumDette(['id' => $adherent->getId()]);
  69.             
  70.         
  71.     
  72.               $arrayresult2[$i]['adeherent'] = $adherent;
  73.                $arrayresult2[$i]['p'] = $types;  
  74.                     $arrayresult2[$i]['d'] = $dette;
  75.             
  76.                 $i++;
  77.         }
  78. //        dump($arrayresult2);die();
  79. //        dump($arrayresult);die();
  80.         return $this->render('adherent/indexStat.html.twig', [
  81.                     'adherents' => $arrayresult,"type"=>$typePrestation,'adherents2' => $arrayresult2
  82.         ]);
  83.     }
  84.     /**
  85.      * @Route("/Admin/new", name="app_adherent_new", methods={"GET", "POST"})
  86.      * @Route("/Admin/{id}/edit", name="app_adherent_edit", methods={"GET", "POST"})
  87.      */
  88.     public function new(Request $requestAdherent $adherent nullAdherentRepository $adherentRepositoryUserPasswordHasherInterface $passwordHasherAppSevices $serviece): Response {
  89.         if (!$adherent) {
  90.             $adherent = new Adherent();
  91.             $type 'i';
  92.         } else {
  93.             $type 'u';
  94.         }
  95.         if (in_array('ROLE_ADMIN'$serviece->getUser()->getRoles(), true)) {
  96.             $form $this->createForm(AdherentType::class, $adherent);
  97.         } else {
  98.             $form $this->createForm(\App\Form\AdherentType_1::class, $adherent);
  99.         }
  100.         $form->handleRequest($request);
  101.         if ($form->isSubmitted() && $form->isValid()) {
  102.             if ($type == 'i') {
  103.                 $user = new \App\Entity\User();
  104.                 $hashedPassword $passwordHasher->hashPassword(
  105.                         $user,
  106.                         "Amicale2023"
  107.                 );
  108.                 $user->setPassword($hashedPassword);
  109.             } else {
  110.                 $user $adherent->getUserCompte();
  111.             }
  112.             $arrayRole[] = $request->get('role');
  113.             if ($request->get('username') != $user->getUsername()) {
  114.                 $user->setUsername($request->get('username'));
  115.             }
  116.             if ($arrayRole[0] && $arrayRole[0] != $user->getRoles()[0]) {
  117.                 $user->setRoles($arrayRole);
  118.             }
  119.        $adherent->setUserCompte($user);
  120.             $adherent->getUserCompte()->setEmailCompte($adherent->getEmail());
  121.      
  122.             $adherentRepository->add($adherenttrue);
  123.             return $this->redirectToRoute('app_adherent_show', ["id" => $adherent->getId()], Response::HTTP_SEE_OTHER);
  124.         }
  125.         return $this->renderForm('adherent/new.html.twig', [
  126.                     'adherent' => $adherent,
  127.                     'form' => $form,
  128.         ]);
  129.     }
  130.     /**
  131.      * @Route("/{id}", name="app_adherent_show", methods={"GET"})
  132.      */
  133.     public function show(Adherent $adherentAppSevices $services): Response {
  134.         $anne $services->getAnneExercice(['sort' => 'u.annee''order' => 'desc'])->setMaxResults(1)->getQuery()->getOneOrNullResult();
  135.         $total $services->getSumPrestationTotal(['etat' => 'Total''id' => $adherent->getId()]);
  136.         $types $services->getByTypePrestation(['id' => $adherent->getId(), 'anne' => $anne->getId()]);
  137.         return $this->render('adherent/show.html.twig', [
  138.                     'adherent' => $adherent'type' => $types'total' => $total
  139.         ]);
  140.     }
  141.     /**
  142.      * @Route("/Admin/{id}", name="app_adherent_delete", methods={"POST"})
  143.      */
  144.     public function delete(Request $requestAdherent $adherentAdherentRepository $adherentRepository): Response {
  145.         if ($this->isCsrfTokenValid('delete' $adherent->getId(), $request->request->get('_token'))) {
  146.             $adherentRepository->remove($adherenttrue);
  147.         }
  148.         return $this->redirectToRoute('app_adherent_index', [], Response::HTTP_SEE_OTHER);
  149.     }
  150. }