src/Service/CompanyEventInfosService.php line 38

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\Invoice;
  7. use App\Entity\User;
  8. use App\Repository\EventRepository;
  9. use App\Repository\InvoiceRepository;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Doctrine\ORM\NonUniqueResultException;
  12. use Doctrine\ORM\NoResultException;
  13. use Symfony\Component\Security\Core\Security;
  14. class CompanyEventInfosService
  15. {
  16.     /**
  17.      * @var Security
  18.      */
  19.     private $security;
  20.     /**
  21.      * @var EventRepository
  22.      */
  23.     private $eventRepository;
  24.     /**
  25.      * @var InvoiceRepository
  26.      */
  27.     private $invoiceRepository;
  28.     /**
  29.      * @var EntityManagerInterface
  30.      */
  31.     private $em;  
  32.     public function __construct(Security $securityEntityManagerInterface $em)
  33.     {
  34.         $this->security $security;
  35.         $this->em $em;
  36.         $this->eventRepository $this->em->getRepository(Event::class);
  37.         $this->affiliatedEventApplicationRepo $this->em->getRepository(AffiliatedEventApplication::class);
  38.         $this->invoiceRepository $this->em->getRepository(Invoice::class);
  39.     }
  40.     /**
  41.      * Permet de récupérer le User du Security et de récupérer toutes ses datas
  42.      * @return ?User
  43.      */
  44.     private function getUser(): ?User
  45.     {
  46.         $user $this->security->getUser();
  47.         return $user;
  48.     }
  49.     /**
  50.      * Get the count for the current events for a specialist
  51.      * @return int
  52.      */
  53.     public function getCurrentEventsCount(): int
  54.     {
  55.         $result 0;
  56.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  57.             $user $this->getUser();
  58.             if ($user instanceof User){
  59.                 try {
  60.                     $result intval($this->eventRepository->getCompanyCurrentEventsQueryBuilder($user->getCompany())
  61.                         ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  62.                 } catch (NoResultException|NonUniqueResultException $e) {
  63.                     $result 0;
  64.                 }
  65.             }
  66.         }
  67.         return $result;
  68.     }
  69.     /**
  70.      * Get the count for the current events for a specialist
  71.      * @return int
  72.      */
  73.     public function getFinalizedInvoiceCount(): int
  74.     {
  75.         $result 0;
  76.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  77.             $user $this->getUser();
  78.             if ($user instanceof User){
  79.                 try {
  80.                     $result intval($this->invoiceRepository->getFinalisedInvoicesForCompany($user->getCompany())
  81.                         ->select('COUNT(i)')->getQuery()->getSingleScalarResult());
  82.                 } catch (NoResultException|NonUniqueResultException $e) {
  83.                     $result 0;
  84.                 }
  85.             }
  86.         }
  87.         return $result;
  88.     }
  89.     /**
  90.      * Get the count for the current events for a specialist
  91.      * @return int
  92.      */
  93.     public function getUnFinalizedInvoiceCount(): int
  94.     {
  95.         $result 0;
  96.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  97.             $user $this->getUser();
  98.             if ($user instanceof User){
  99.                 try {
  100.                     $result intval($this->invoiceRepository->getUnFinalisedInvoicesForCompany($user->getCompany())
  101.                         ->select('COUNT(i)')->getQuery()->getSingleScalarResult());
  102.                 } catch (NoResultException|NonUniqueResultException $e) {
  103.                     $result 0;
  104.                 }
  105.             }
  106.         }
  107.         return $result;
  108.     }
  109.     /**
  110.      * Get the count for the postulated events for a specialist
  111.      * @return int
  112.      */
  113.     public function getAwaitSpecialist(): int
  114.     {
  115.         $result 0;
  116.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  117.             $user $this->getUser();
  118.             if ($this->security->isGranted(User::ROLE_COMPANY) && $user instanceof User){
  119.                 try {
  120.                     $result intval($this->eventRepository->getCompanyAwaitSpecialistEventsQueryBuilder($user->getCompany())
  121.                         ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  122.                 } catch (NoResultException|NonUniqueResultException $e) {
  123.                     $result 0;
  124.                 }
  125.             }
  126.         }
  127.         return $result;
  128.     }
  129.     /**
  130.      * Get the count for the available events for a specialist
  131.      * @return int
  132.      */
  133.     public function getAvailableEventsCount(): int
  134.     {
  135.         $result 0;
  136.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  137.             $user $this->getUser();
  138.             if ($user instanceof User){
  139.                 try {
  140.                     $result intval($this->eventRepository->getCompanySpecialistEventsQueryBuilder($user->getCompany())
  141.                         ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  142.                 } catch (NoResultException|NonUniqueResultException $e) {
  143.                     $result 0;
  144.                 }
  145.             }
  146.         }
  147.         return $result;
  148.     }
  149.     /**
  150.      * Get the count for the available affiliated event applications for a specialist
  151.      * @return int
  152.      */
  153.     public function getAffiliatedEventsApplicationCount(): int
  154.     {
  155.         $result 0;
  156.         if($this->security->isGranted(User::ROLE_COMPANY)) {
  157.             $user $this->getUser();
  158.             if ($user instanceof User){
  159.                 try {
  160.                     $result intval($this->affiliatedEventApplicationRepo->getAffiliatedEventsForCompanyQueryBuilder($user->getCompany())
  161.                         ->select('COUNT(event)')->getQuery()->getSingleScalarResult());
  162.                 } catch (NoResultException|NonUniqueResultException $e) {
  163.                     $result 0;
  164.                 }
  165.             }
  166.         }
  167.         return $result;
  168.     }
  169. }