src/Service/ClubHandler.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\Club;
  4. use App\Entity\Company;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\Security\Core\Security;
  8. class ClubHandler
  9. {
  10.     public function __construct(
  11.         private readonly EntityManagerInterface $em,
  12.         private RequestStack $requestStack,
  13.         private Security $security,
  14.     ) {
  15.     }
  16.     public function getCompanies(Club $club, array $params) : array {
  17.         return $this->em->getRepository(Company::class)->getCompaniesFromClub($club$params);
  18.     }
  19.     public function getNearestClub(array $params) : array {
  20.         return $this->em->getRepository(Club::class)->getClubLocalize($params);
  21.     }
  22.     public function getCurrentBoClub() : ?Club {
  23.         $session $this->requestStack->getSession();
  24.         $user $this->security->getUser();
  25.         $currentBoClubId $session->get('currentBoClubId');
  26.         if ($currentBoClubId) {
  27.             return $this->em->getRepository(Club::class)->find($currentBoClubId);
  28.         }
  29.         $clubs $this->em->getRepository(Club::class)->findManagedClubsByUser($user);
  30.         $currentBoClub sizeof($clubs) > $clubs[0] : null;
  31.         if ($currentBoClub) {
  32.             $session->set('currentBoClubId'$currentBoClub->getId());
  33.         }
  34.         return $currentBoClub;
  35.     }
  36.     public function setCurrentBoClub(int $boClubId) : ?Club {
  37.         $session $this->requestStack->getSession();
  38.         $currentBoClub $this->em->getRepository(Club::class)->find($boClubId);
  39.         if ($currentBoClub) {
  40.             $session->set('currentBoClubId'$currentBoClub->getId());
  41.         }
  42.         return $currentBoClub;
  43.     }
  44. }