예제 #1
0
 private function getVotingData()
 {
     $election = Factory::getCurrent();
     // If there's no election going on, then return empty data
     if (empty($election)) {
         return array('hasVoted' => false, 'election' => null, 'single' => array(), 'multiple' => array(), 'referendum' => array(), 'unqualified' => array());
     }
     // Check if student has voted already
     $hasVoted = $this->student->hasVoted($election['id']);
     // If already voted, return minimal voting info
     if ($hasVoted) {
         return array('hasVoted' => true, 'election' => $election, 'single' => array(), 'multiple' => array(), 'referendum' => array(), 'unqualified' => array());
     }
     // Assemble the voting data
     $single = \election\Factory\Single::getListWithTickets($election['id']);
     $multiple = \election\Factory\Multiple::getListWithCandidates($election['id']);
     if (!empty($multiple)) {
         $unqualified = \election\Factory\Multiple::filter($multiple, $this->student);
     } else {
         $unqualified = array();
     }
     $referendum = \election\Factory\Referendum::getList($election['id']);
     $voting_data = array('hasVoted' => false, 'election' => $election, 'single' => $single, 'multiple' => $multiple, 'referendum' => $referendum, 'unqualified' => $unqualified, 'supportLink' => \PHPWS_Settings::get('election', 'supportLink'));
     return $voting_data;
 }
예제 #2
0
 protected function getJsonView($data, \Request $request)
 {
     if (!$request->isVar('command')) {
         throw new \Exception('Unknown Single ballot command');
     }
     $json = array('success' => true);
     $command = $request->getVar('command');
     switch ($command) {
         case 'list':
             $json = Factory::getList(Factory::pullGetInteger('electionId'));
             break;
     }
     $view = new \View\JsonView($json);
     return $view;
 }
예제 #3
0
 public static function post()
 {
     $candidateId = self::pullPostInteger('candidateId');
     $candidate = self::build($candidateId, new Resource());
     $type = self::pullPostString('type');
     if ($type == 'ticket') {
         $candidate->setTicketId((int) self::pullPostInteger('ticketId'));
     } elseif ($type === 'multiple') {
         $candidate->setMultipleId((int) self::pullPostInteger('multipleId'));
     } else {
         throw new \Exception('Unknown candidate type');
     }
     $ticket_id = $candidate->getTicketId();
     $multiple_id = $candidate->getMultipleId();
     if ((int) $ticket_id === 0 && (int) $multiple_id === 0) {
         throw new \Exception('Missing candidate foreign key');
     }
     /**
      * If this is a new candidate make sure the election
      * is not ongoing or the person doesn't have rights.
      */
     if (!$candidateId) {
         if ($ticket_id) {
             $election_id = Ticket::getElectionId($ticket_id);
         } else {
             $election_id = Multiple::getElectionId($multiple_id);
         }
         if (!Election::allowChange($election_id)) {
             throw new \Exception('Cannot create new candidate in active election');
         }
     }
     $candidate->setFirstName(ucfirst(self::pullPostString('firstName')));
     $candidate->setLastName(ucfirst(self::pullPostString('lastName')));
     $candidate->setTitle(self::pullPostString('title'));
     if (!empty($_FILES)) {
         $picture = self::savePicture($_FILES[0], $candidate);
         if ($candidate->getId()) {
             self::deletePicture($candidate);
         }
         $candidate->setPicture($picture);
     }
     self::saveResource($candidate);
     return true;
 }