/**
  * @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;
 }
 /**
  * @test
  */
 public function getDateReturnsInitialValueForDateTime()
 {
     $this->assertEquals(NULL, $this->subject->getDate());
 }