<?phpnamespace App\Service;use App\Entity\AffiliatedEventApplication;use App\Entity\Company;use App\Entity\Event;use App\Entity\Invoice;use App\Entity\User;use App\Repository\EventRepository;use App\Repository\InvoiceRepository;use Doctrine\ORM\EntityManagerInterface;use Doctrine\ORM\NonUniqueResultException;use Doctrine\ORM\NoResultException;use Symfony\Component\Security\Core\Security;class CompanyEventInfosService{ /** * @var Security */ private $security; /** * @var EventRepository */ private $eventRepository; /** * @var InvoiceRepository */ private $invoiceRepository; /** * @var EntityManagerInterface */ private $em; public function __construct(Security $security, EntityManagerInterface $em) { $this->security = $security; $this->em = $em; $this->eventRepository = $this->em->getRepository(Event::class); $this->affiliatedEventApplicationRepo = $this->em->getRepository(AffiliatedEventApplication::class); $this->invoiceRepository = $this->em->getRepository(Invoice::class); } /** * Permet de récupérer le User du Security et de récupérer toutes ses datas * @return ?User */ private function getUser(): ?User { $user = $this->security->getUser(); return $user; } /** * Get the count for the current events for a specialist * @return int */ public function getCurrentEventsCount(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($user instanceof User){ try { $result = intval($this->eventRepository->getCompanyCurrentEventsQueryBuilder($user->getCompany()) ->select('COUNT(event)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; } /** * Get the count for the current events for a specialist * @return int */ public function getFinalizedInvoiceCount(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($user instanceof User){ try { $result = intval($this->invoiceRepository->getFinalisedInvoicesForCompany($user->getCompany()) ->select('COUNT(i)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; } /** * Get the count for the current events for a specialist * @return int */ public function getUnFinalizedInvoiceCount(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($user instanceof User){ try { $result = intval($this->invoiceRepository->getUnFinalisedInvoicesForCompany($user->getCompany()) ->select('COUNT(i)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; } /** * Get the count for the postulated events for a specialist * @return int */ public function getAwaitSpecialist(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($this->security->isGranted(User::ROLE_COMPANY) && $user instanceof User){ try { $result = intval($this->eventRepository->getCompanyAwaitSpecialistEventsQueryBuilder($user->getCompany()) ->select('COUNT(event)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; } /** * Get the count for the available events for a specialist * @return int */ public function getAvailableEventsCount(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($user instanceof User){ try { $result = intval($this->eventRepository->getCompanySpecialistEventsQueryBuilder($user->getCompany()) ->select('COUNT(event)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; } /** * Get the count for the available affiliated event applications for a specialist * @return int */ public function getAffiliatedEventsApplicationCount(): int { $result = 0; if($this->security->isGranted(User::ROLE_COMPANY)) { $user = $this->getUser(); if ($user instanceof User){ try { $result = intval($this->affiliatedEventApplicationRepo->getAffiliatedEventsForCompanyQueryBuilder($user->getCompany()) ->select('COUNT(event)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } } return $result; }}