/**
  * Get all parties that are (still) available for the current panel
  * For each panel, a party can only be added in one panelInvitation
  * This method is called by Select2 AJAX to ensure only available parties can be added
  *
  * @param Panel $panel
  * @return string
  */
 public function getAvailablePartiesForPanelAction(Panel $panel)
 {
     $parties = $this->partyRepository->findYoungParties();
     // Build an array containing all parties that are already part of existing panelInvitations
     $unavailableParties = array();
     foreach ($panel->getPanelInvitations() as $panelInvitation) {
         /** @var PanelInvitation $panelInvitation */
         foreach ($panelInvitation->getAllowedParties() as $unavailableParty) {
             /** @var \Visol\Easyvote\Domain\Model\Party $unavailableParty */
             $unavailableParties[] = $unavailableParty->getUid();
         }
     }
     $returnArray['results'] = array();
     foreach ($parties as $party) {
         /** @var $party \Visol\Easyvote\Domain\Model\Party */
         // If current party was used before, it may not be used again
         if (in_array($party->getUid(), $unavailableParties)) {
             continue;
         }
         $returnArray['results'][] = array('id' => $party->getUid(), 'text' => $party->getTitle(), 'shortTitle' => $party->getShortTitle());
     }
     $returnArray['more'] = FALSE;
     return json_encode($returnArray);
 }
 /**
  * Send an invitiation to all politicians affected by a panel
  * Affected by a panel means:
  * a) Living in the Kanton a panel takes place
  * b) Are politicians of a Party that is allowed for a Panel invitation
  *
  * @param Panel $panel
  */
 public function sentMailAboutPanelToAffectedPoliticians(Panel $panel)
 {
     if (is_null($panel->getCity())) {
         return FALSE;
     }
     if (count($panel->getPanelInvitations())) {
         foreach ($panel->getPanelInvitations() as $panelInvitation) {
             /** @var $panelInvitation \Visol\EasyvoteEducation\Domain\Model\PanelInvitation */
             if (count($panelInvitation->getAllowedParties())) {
                 foreach ($panelInvitation->getAllowedParties() as $party) {
                     /** @var $party \Visol\Easyvote\Domain\Model\Party */
                     $demand = [];
                     $demand['kanton'] = $panel->getCity()->getKanton()->getUid();
                     $partyMembers = $this->communityUserRepository->findPoliticiansByPartyAndDemand($party, $demand);
                     foreach ($partyMembers as $partyMember) {
                         /** @var $partyMember \Visol\Easyvote\Domain\Model\CommunityUser */
                         // Send information e-mail to politician
                         /** @var \Visol\Easyvote\Service\TemplateEmailService $templateEmail */
                         $templateEmail = $this->objectManager->get('Visol\\Easyvote\\Service\\TemplateEmailService');
                         $templateEmail->addRecipient($partyMember);
                         $templateEmail->setTemplateName('panelCreatePolitician');
                         $templateEmail->setExtensionName('easyvoteeducation');
                         $templateEmail->assign('panel', $panel);
                         $templateEmail->enqueue();
                     }
                 }
             }
         }
     }
 }