src/EventSubscriber/CalendarSubscriber.php line 43
<?phpnamespace App\EventSubscriber;use CalendarBundle\CalendarEvents;use CalendarBundle\Entity\Event;use CalendarBundle\Event\CalendarEvent;use Symfony\Bundle\SecurityBundle\Security;use Symfony\Component\EventDispatcher\EventSubscriberInterface;//use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;use App\Repository\TheCaseActionsRepository;class CalendarSubscriber implements EventSubscriberInterface{// private UrlGeneratorInterface $router;private TheCaseActionsRepository $TheCaseActionsRepository;private Encryptor $encryptor;private Security $security;public function __construct(TheCaseActionsRepository $TheCaseActionsRepository,/* UrlGeneratorInterface $router,*/Encryptor $encryptor,Security $security) {$this->TheCaseActionsRepository = $TheCaseActionsRepository;// $this->router = $router;$this->encryptor = $encryptor;$this->security = $security;}public static function getSubscribedEvents(): array{return [CalendarEvents::SET_DATA => 'onCalendarSetData',];}public function onCalendarSetData(CalendarEvent $calendar): void{$LawOffice = $this->security->getUser()->getLawOffice();$start = $calendar->getStart();$end = $calendar->getEnd();$filters = $calendar->getFilters();//dd($calendar);//Get CaseAction by LawOffice Repository$CaseActionsAt = $this->TheCaseActionsRepository->createQueryBuilder('TheCaseActions')->where('TheCaseActions.ActionAt BETWEEN :StartAt and :EndAt')->innerJoin('TheCaseActions.theCase', 'theCase', 'WITH', 'TheCaseActions.theCase = theCase.id')->andWhere('theCase.LawOffice = :LawOffice')->andWhere('theCase.FileStatus not in (:FileStatus)')->andWhere('TheCaseActions.IsDeleted <> :IsDeleted')->Select('COUNT(TheCaseActions.id) NbreActions','TheCaseActions.ActionAt')->setParameter('StartAt', $start->format('Y-m-d H:i:s'))->setParameter('EndAt', $end->format('Y-m-d H:i:s'))->setParameter('LawOffice', $LawOffice)->setParameter('IsDeleted', true)->setParameter('FileStatus',['2000'])->groupBy('TheCaseActions.ActionAt')->orderBy('TheCaseActions.ActionAt', 'DESC');$CaseActionsAt = $CaseActionsAt->getQuery()->getResult();//dd($CaseActionsAt);foreach ($CaseActionsAt as $CaseAction) {//dd($CaseAction['NbreActions']);//case $CaseAction['NbreActions'] case 1,2,3$Title = $this->TitleCalendar($CaseAction['NbreActions']);$CaseActionAtEvent = new Event($Title,$CaseAction['ActionAt'],null // If the end date is null or not defined, an all day event is created.);/** Add custom options to events** For more information see: https://fullcalendar.io/docs/event-object* and: https://github.com/fullcalendar/fullcalendar/blob/master/src/core/options.ts*/$CaseActionAtEvent->setOptions(['backgroundColor' => 'red','borderColor' => 'red',]);$CaseActionAtEvent->addOption('id', $this->encryptor->encrypt($CaseAction['ActionAt']->format('Y-m-d H:i:s')));// finally, add the event to the CalendarEvent to fill the calendar$calendar->addEvent($CaseActionAtEvent);}$CaseActionsNext = $this->TheCaseActionsRepository->createQueryBuilder('TheCaseActions')->where('TheCaseActions.ActionNextAt >= :DateNow')->innerJoin('TheCaseActions.theCase', 'theCase', 'WITH', 'TheCaseActions.theCase = theCase.id')->andWhere('theCase.LawOffice = :LawOffice')->andWhere('TheCaseActions.IsDeleted <> :IsDeleted')->select('COUNT(TheCaseActions.id) NbreActions','TheCaseActions.ActionNextAt')->andWhere('TheCaseActions.ActionNextAt BETWEEN :StartAt and :EndAt')->setParameter('StartAt', $start->format('Y-m-d H:i:s'))->setParameter('EndAt', $end->format('Y-m-d H:i:s'))->setParameter('DateNow', new \DateTime('now'))->setParameter('LawOffice', $LawOffice)->setParameter('IsDeleted', true)->groupBy('TheCaseActions.ActionNextAt')->orderBy('TheCaseActions.ActionNextAt', 'DESC')->getQuery()->getResult();foreach ($CaseActionsNext as $CaseAction) {$Title = $this->TitleCalendar($CaseAction['NbreActions']);$CaseActionNextAtEvent = new Event($Title,$CaseAction['ActionNextAt'],null // If the end date is null or not defined, an all day event is created.);$CaseActionNextAtEvent->setOptions(['backgroundColor' => 'green','borderColor' => 'green',]);$CaseActionNextAtEvent->addOption('id', $this->encryptor->encrypt($CaseAction['ActionNextAt']->format('Y-m-d H:i:s')));$calendar->addEvent($CaseActionNextAtEvent);}}public function TitleCalendar($Number): string{$Title = $Number;if ($Number == 1) {$Title .= 'جلسة';}elseif ($Number == 2) {$Title = 'جلستين';}elseif ($Number <= 10) {$Title .= ' جلسات';}elseif ($Number >= 11) {$Title .= ' جلسة';}return $Title;}}