src/Controller/Adherent/HomeController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Adherent;
  3. use App\Controller\AbstractController;
  4. use App\Entity\Section;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class HomeController extends AbstractController
  8. {
  9.     #[Route(name'home')]
  10.     public function home()
  11.     {
  12.         return $this->redirectToRoute('dashboard');
  13.     }
  14.     #[Route('/espace-membre'name'dashboard')]
  15.     #[IsGranted('ROLE_USER')]
  16.     public function dashboard()
  17.     {
  18.         $user $this->getUser();
  19.         $family $user->getPerson()->getFamily();
  20.         if (null === $family) {
  21.             return $this->redirectToRoute('registration_family');
  22.         }
  23.         $persons $family->getPersons();
  24.         $registrations $family->getActiveRegistrations();
  25.         $groupedRegistrations = [];
  26.         foreach ($registrations as $registration) {
  27.             $section $registration->getSeason()->getSection();
  28.             $sectionId $section->getId();
  29.             if (!isset($groupedRegistrations[$sectionId])) {
  30.                 $groupedRegistrations[$sectionId] = $section;
  31.                 $section->registrations = [];
  32.             }
  33.             $groupedRegistrations[$sectionId]->registrations[] = $registration;
  34.         }
  35.         ksort($groupedRegistrations);
  36.         $noRegistrationsPersons = [];
  37.         foreach ($persons as $person) {
  38.             if ($person->getActiveRegistrations()->count() === 0) {
  39.                 $noRegistrationsPersons[] = $person;
  40.             }
  41.         }
  42.         return $this->render('adherent/dashboard/home.html.twig', [
  43.             'sections'                => $groupedRegistrations,
  44.             'no_registration_persons' => $noRegistrationsPersons,
  45.             'family'                  => $family,
  46.             'benefactor_section'      => $this->em->getRepository(Section::class)->findDefaultBenefactorTunnel(),
  47.         ]);
  48.     }
  49.     #[Route('/member'name'member')]
  50.     #[IsGranted('ROLE_ADHERENT')]
  51.     public function member()
  52.     {
  53.         return $this->render('admin/show_user.html.twig');
  54.     }
  55. }