예제 #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
 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;
 }