<?phpnamespace App\Service;use App\Entity\AffiliatedEventApplication;use App\Entity\Company;use App\Entity\Event;use App\Entity\Specialist;use App\Entity\User;use App\Repository\EventRepository;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 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); } /** * Get the count for the current events for a specialist * @return int */ public function getCurrentEventsCount(): int { $result = 0; $user = $this->security->getUser(); if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){ 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 postulated events for a specialist * @return int */ public function getAwaitSpecialist(): int { $result = 0; $user = $this->security->getUser(); if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){ 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; $user = $this->security->getUser(); if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){ $company = $this->em->getRepository(Company::class)->find($user->getCompany()->getId()); try { $result = intval($this->eventRepository->getCompanySpecialistEventsQueryBuilder($company) ->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; $user = $this->security->getUser(); if ($user instanceof User && $this->security->isGranted(User::ROLE_COMPANY)){ $company = $this->em->getRepository(Company::class)->find($user->getCompany()->getId()); try { $result = intval($this->affiliatedEventApplicationRepo->getAffiliatedEventsForCompanyQueryBuilder($company) ->select('COUNT(event)')->getQuery()->getSingleScalarResult()); } catch (NoResultException|NonUniqueResultException $e) { $result = 0; } } return $result; }}