コード例 #1
0
 /**
  * @test
  */
 public function removeVotingFromObjectStorageHoldingVotings()
 {
     $voting = new \Visol\EasyvoteEducation\Domain\Model\Voting();
     $votingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('detach'), array(), '', FALSE);
     $votingsObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($voting));
     $this->inject($this->subject, 'votings', $votingsObjectStorageMock);
     $this->subject->removeVoting($voting);
 }
 /**
  * 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);
 }
コード例 #3
0
 /**
  * Sets panel state to beginning (currentState => empty) and removes all votes from all votingOptions from all votings
  *
  * @param Panel $panel
  * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
  */
 protected function resetPanel(Panel $panel)
 {
     $panel->setCurrentState('');
     foreach ($panel->getVotings() as $voting) {
         /** @var $voting \Visol\EasyvoteEducation\Domain\Model\Voting */
         foreach ($voting->getVotingOptions() as $votingOption) {
             /** @var $votingOption \Visol\EasyvoteEducation\Domain\Model\VotingOption */
             $votingOption->getVotes()->removeAll($votingOption->getVotes());
             $this->votingOptionRepository->update($votingOption);
         }
     }
     $this->persistenceManager->persistAll();
 }
コード例 #4
0
 /**
  * Check if the currently logged in user is the owner of a panel
  *
  * @param Panel $panel
  * @return bool
  */
 public function isCurrentUserOwnerOfPanel(Panel $panel)
 {
     if ($communityUser = $this->getLoggedInUser()) {
         if ($panel->getCommunityUser() === $communityUser) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #5
0
 /**
  * @param Panel $panel
  */
 public function processVotingResult(Panel $panel)
 {
     $voting = $panel->getCurrentVoting();
     $votesCount = 0;
     foreach ($voting->getVotingOptions() as $votingOption) {
         /** @var \Visol\EasyvoteEducation\Domain\Model\VotingOption $votingOption */
         $votesCountForVotingOption = $votingOption->getVotes()->count();
         $votingOption->setCachedVotes($votesCountForVotingOption);
         $votesCount = $votesCount + $votesCountForVotingOption;
         $this->votingOptionRepository->update($votingOption);
     }
     $this->persistenceManager->persistAll();
     // $votesCount is complete
     foreach ($voting->getVotingOptions() as $votingOption) {
         /** @var \Visol\EasyvoteEducation\Domain\Model\VotingOption $votingOption */
         if ($votesCount > 0) {
             $votingResult = round($votingOption->getCachedVotes() / $votesCount, 5) * 100;
             $votingOption->setCachedVotingResult((int) $votingResult);
         } else {
             $votingOption->setCachedVotingResult(0);
         }
         $this->votingOptionRepository->update($votingOption);
     }
     $this->persistenceManager->persistAll();
 }
コード例 #6
0
 /**
  * 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();
                     }
                 }
             }
         }
     }
 }