src/Service/CompanyEventInfosService.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\AffiliatedEventApplication;
  4. use App\Entity\Company;
  5. use App\Entity\Event;
  6. use App\Entity\Specialist;
  7. use App\Entity\User;
  8. use App\Repository\EventRepository;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Doctrine\ORM\NonUniqueResultException;
  11. use Doctrine\ORM\NoResultException;
  12. use Symfony\Component\Security\Core\Security;
  13. class CompanyEventInfosService
  14. {
  15.     /**
  16.      * @var Security
  17.      */
  18.     private $security;
  19.     /**
  20.      * @var EventRepository
  21.      */
  22.     private $eventRepository;
  23.     /**
  24.      * @var EntityManagerInterface
  25.      */
  26.     private $em;
  27.     public function __construct(Security $securityEntityManagerInterface $em)
  28.     {
  29.         $this->security $security;
  30.         $this->em $em;
  31.         $this->eventRepository $this->em->getRepository(Event::class);
  32.         $this->affiliatedEventApplicationRepo $this->em->getRepository(AffiliatedEventApplication::class);
  33.     }
  34.     /**
  35.      * Get the count for the current events for a specialist
  36.      * @return int
  37.      */
  38.     public function getCurrentEventsCount(): int
  39.     {
  40.         $result 0;
  41.         $user $this->security->getUser();
  42.         if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){
  43.             try {
  44.                 $result intval($this->eventRepository->getCompanyCurrentEventsQueryBuilder($user->getCompany())
  45.                     ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  46.             } catch (NoResultException|NonUniqueResultException $e) {
  47.                 $result 0;
  48.             }
  49.         }
  50.         return $result;
  51.     }
  52.     /**
  53.      * Get the count for the postulated events for a specialist
  54.      * @return int
  55.      */
  56.     public function getAwaitSpecialist(): int
  57.     {
  58.         $result 0;
  59.         $user $this->security->getUser();
  60.         if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){
  61.             try {
  62.                 $result intval($this->eventRepository->getCompanyAwaitSpecialistEventsQueryBuilder($user->getCompany())
  63.                     ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  64.             } catch (NoResultException|NonUniqueResultException $e) {
  65.                 $result 0;
  66.             }
  67.         }
  68.         return $result;
  69.     }
  70.     /**
  71.      * Get the count for the available events for a specialist
  72.      * @return int
  73.      */
  74.     public function getAvailableEventsCount(): int
  75.     {
  76.         $result 0;
  77.         $user $this->security->getUser();
  78.         if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){
  79.             $company $this->em->getRepository(Company::class)->find($user->getCompany()->getId());
  80.             try {
  81.                 $result intval($this->eventRepository->getCompanySpecialistEventsQueryBuilder($company)
  82.                     ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  83.             } catch (NoResultException|NonUniqueResultException $e) {
  84.                 $result 0;
  85.             }
  86.         }
  87.         return $result;
  88.     }
  89.      /**
  90.      * Get the count for the available affiliated event applications for a specialist
  91.      * @return int
  92.      */
  93.     public function getAffiliatedEventsApplicationCount(): int
  94.     {
  95.         $result 0;
  96.         $user $this->security->getUser();
  97.         if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){
  98.             $company $this->em->getRepository(Company::class)->find($user->getCompany()->getId());
  99.             try {
  100.                 $result intval($this->affiliatedEventApplicationRepo->getAffiliatedEventsForCompanyQueryBuilder($company)
  101.                     ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  102.             } catch (NoResultException|NonUniqueResultException $e) {
  103.                 $result 0;
  104.             }
  105.         }
  106.         return $result;
  107.     }
  108. }