/**
  * One week, two weeks and one month before a panel, the teacher organizing the panel
  * is reminded of the upcoming panel.
  *
  * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
  */
 public function sendReminderForPanelsCommand()
 {
     $reminders = array('oneweek', 'twoweeks', 'onemonth');
     foreach ($reminders as $reminder) {
         $affectedPanels = $this->panelRepository->findPanelsWithinDateConstraintWithoutReminderEmailSent($reminder);
         $this->outputLine('Panels due in ' . $reminder . ': ' . count($affectedPanels));
         foreach ($affectedPanels as $panel) {
             /** @var $panel \Visol\EasyvoteEducation\Domain\Model\Panel */
             if (is_null($panel->getDate())) {
                 // If panel has not date, we don't send a reminder (obviously)
                 return TRUE;
             }
             $this->outputLine($panel->getDate()->format('Y-m-d') . ' | ' . $panel->getTitle() . ' | Sending reminder to ' . $panel->getCommunityUser()->getEmail());
             // Send reminder e-mail to teacher
             /** @var \Visol\Easyvote\Service\TemplateEmailService $templateEmail */
             $templateEmail = $this->objectManager->get('Visol\\Easyvote\\Service\\TemplateEmailService');
             $templateEmail->addRecipient($panel->getCommunityUser());
             $templateEmail->setTemplateName('panelReminder' . ucfirst($reminder) . 'Teacher');
             $templateEmail->setExtensionName('easyvote_education');
             $templateEmail->assign('panel', $panel);
             $templateEmail->enqueue();
             $setter = 'setReminder' . ucfirst($reminder) . 'Sent';
             $panel->{$setter}(TRUE);
             $this->panelRepository->update($panel);
             $this->persistenceManager->persistAll();
         }
     }
 }
 /**
  * @param Panel $panel
  * @return boolean
  */
 public function isPanelInvitationAllowedForPanel(Panel $panel)
 {
     if (count($panel->getPanelInvitations()) > 0) {
         // If a panel already has invitations, it is allowed to have invitations (quite logical, isn't it :-)?)
         return TRUE;
     }
     $cityOfPanel = $panel->getCity();
     if ($cityOfPanel instanceof \Visol\Easyvote\Domain\Model\City) {
         // panelLimit is either NULL or an integer
         $panelLimitForKanton = $cityOfPanel->getKanton()->getPanelLimit();
         if (is_integer($panelLimitForKanton)) {
             $existingPanelsInKanton = $this->panelRepository->countPanelsWithInvitationsByKanton($panel->getCity()->getKanton());
             if ($existingPanelsInKanton >= $panelLimitForKanton) {
                 return FALSE;
             }
         }
     }
     if ($panel->getDate() instanceof \DateTime) {
         $panelTimestamp = $panel->getDate()->getTimestamp();
         $allowedTimestampStart = 1438387200;
         $allowedTimestampEnd = 1445205599;
         if ($panelTimestamp < $allowedTimestampStart || $panelTimestamp > $allowedTimestampEnd) {
             // The panel doesn't take place between August 1, 2015 and October 18, 2015
             return FALSE;
         }
     }
     // return false if all panels are reached or existing panels don't have a city set
     return TRUE;
 }
 /**
  * @param Panel $panel
  * @return boolean
  */
 public function isPanelInvitationAllowedForPanel(Panel $panel)
 {
     if (count($panel->getPanelInvitations()) > 0) {
         // If a panel already has invitations, it is allowed to have invitations (quite logical, isn't it :-)?)
         return true;
     }
     $cityOfPanel = $panel->getCity();
     if ($cityOfPanel instanceof \Visol\Easyvote\Domain\Model\City) {
         // panelLimit is either NULL or an integer
         $panelLimitForKanton = $cityOfPanel->getKanton()->getPanelLimit();
         if (is_integer($panelLimitForKanton)) {
             $existingPanelsInKanton = $this->panelRepository->countPanelsWithInvitationsByKanton($panel->getCity()->getKanton());
             if ($existingPanelsInKanton >= $panelLimitForKanton) {
                 return false;
             }
         }
         if ($cityOfPanel->getKanton()->getPanelAllowedFrom() instanceof \DateTime) {
             // Panel has a date restriction
             if ($panel->getDate() instanceof \DateTime) {
                 $panelTimestamp = $panel->getDate()->getTimestamp();
                 $panelAllowedFromTimeStamp = $cityOfPanel->getKanton()->getPanelAllowedFrom()->getTimestamp();
                 if ($cityOfPanel->getKanton()->getPanelAllowedTo() instanceof \DateTime) {
                     // We also have an end date restriction
                     $panelAllowedToTimeStamp = $cityOfPanel->getKanton()->getPanelAllowedTo()->getTimestamp();
                     if ($panelTimestamp < $panelAllowedFromTimeStamp || $panelTimestamp > $panelAllowedToTimeStamp) {
                         // The panel doesn't take place in the given timeframe
                         return false;
                     }
                 } else {
                     if ($panelTimestamp < $panelAllowedFromTimeStamp) {
                         // Panel is too early
                         return false;
                     }
                 }
             } else {
                 // There is a date restriction, but panel has no date, so we can't know if invitations are allowed
                 return false;
             }
         }
         if ($cityOfPanel->getKanton()->getPanelAllowedTo() instanceof \DateTime) {
             // If there is only an end date restriction
             if ($panel->getDate() instanceof \DateTime) {
                 $panelTimestamp = $panel->getDate()->getTimestamp();
                 $panelAllowedToTimeStamp = $cityOfPanel->getKanton()->getPanelAllowedTo()->getTimestamp();
                 if ($panelTimestamp > $panelAllowedToTimeStamp) {
                     // Panel is too late
                     return false;
                 }
             }
         }
     }
     // return false if all panels are reached or existing panels don't have a city set
     return true;
 }