예제 #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
 public static function delete($singleId)
 {
     if (empty($singleId)) {
         throw new \Exception('Missing id');
     }
     $single = self::build($singleId, new Resource());
     if (!Election::allowChange($single->getElectionId())) {
         throw new \Exception('Cannot delete ballot in ongoing election');
     }
     $single->setActive(false);
     self::saveResource($single);
 }
예제 #3
0
 public static function delete($ticketId)
 {
     if (empty($ticketId)) {
         throw new \Exception('Missing ticket id');
     }
     $ticket = self::build($ticketId, new Resource());
     $electionId = self::getElectionId($ticket->getId());
     if (!Election::allowChange($electionId)) {
         throw new \Exception('Cannot delete a ticket in ongoing election');
     }
     $ticket->setActive(false);
     self::saveResource($ticket);
 }
예제 #4
0
 public static function delete($referendumId)
 {
     if (empty($referendumId)) {
         throw new \Exception('Missing id');
     }
     $referendum = self::build($referendumId, new Resource());
     $electionId = $referendum->getElectionId();
     if (!Election::allowChange($electionId)) {
         throw new \Exception('Cannot referendum in ongoing election');
     }
     $referendum->setActive(false);
     self::saveResource($referendum);
 }
예제 #5
0
 private function routeCommand($request)
 {
     $command = $request->shiftCommand();
     // Get the current election
     $election = \election\Factory\Election::getCurrent();
     // If there's no current election, redirect to friendly error message
     if ($election === false) {
         $command = 'NoOpenElections';
     }
     $provider = \election\Factory\StudentProviderFactory::getProvider();
     $studentId = $provider->pullStudentId();
     try {
         if (preg_match('/^9\\d{8}/', $studentId)) {
             $student = \election\Factory\StudentFactory::getStudentByBannerId($studentId);
         } else {
             $student = \election\Factory\StudentFactory::getStudentByUsername($studentId);
         }
     } catch (\Guzzle\Http\Exception\BadResponseException $ex) {
         $controller = new User\NotAllowed($this->getModule());
         $controller->setMessage('We could not pull your student record.');
         return $controller;
     } catch (\Guzzle\Http\Exception\CurlException $ex) {
         $controller = new User\ServerError($this->getModule());
         $controller->setMessage('Please contact the site administrator and try again later.');
         return $controller;
     }
     if (!$student->isEligibleToVote()) {
         $controller = new User\NotAllowed($this->getModule());
         $controller->setMessage('No credit hours or not an undergraduate student.');
         return $controller;
     }
     // If there's an election going on, check to see if this student has already voted in it
     if ($election !== false && $student->hasVoted($election['id'])) {
         $command = 'AlreadyVoted';
     }
     // Default command name is 'Election'
     if (empty($command)) {
         $command = 'Election';
     }
     $className = 'election\\Controller\\User\\' . $command;
     if (!class_exists($className)) {
         throw new \Exception('Unknown command: ' . $className);
     }
     $controller = new $className($this->getModule());
     $controller->setStudent($student);
     return $controller;
 }
예제 #6
0
 private function saveDates()
 {
     $electionId = Factory::pullPostInteger('electionId');
     $election = Factory::build($electionId, new Resource());
     $startDate = Factory::pullPostInteger('startDate');
     $endDate = Factory::pullPostInteger('endDate');
     $election->setStartDate($startDate, false);
     $election->setEndDate($endDate, false);
     Factory::saveResource($election);
 }
예제 #7
0
 private static function categoryListingByType()
 {
     $json = Election::getFilterTypes();
     if (empty($json)) {
         throw new \Exception('Missing election types');
     }
     $types = json_decode($json, true);
     foreach ($types['electionTypes'] as $cat) {
         foreach ($cat['subcategory'] as $sub) {
             $sub['unqualified'] = $cat['unqualified'];
             $categories[$sub['type']] = $sub;
         }
     }
     return $categories;
 }
예제 #8
0
 public static function delete($candidateId)
 {
     if (empty($candidateId)) {
         throw new \Exception('Missing id');
     }
     $candidate = self::build($candidateId, new Resource());
     $election_id = self::getElectionId($candidate);
     if (!Election::allowChange($election_id)) {
         throw new \Exception('Cannot delete candidate in active election');
     }
     $candidate->setActive(false);
     self::saveResource($candidate);
 }