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; }
/** * Returns array with student's full name * @param integer $electionId * @param integer $bannerId * @return type */ public static function getStudentVoteInformation($electionId, $bannerId) { $db = \phpws2\Database::getDB(); $vc = $db->addTable('elect_vote_complete'); $vc->addFieldConditional('electionId', $electionId); $vc->addFieldConditional('bannerId', $bannerId); $result = $db->select(); if (empty($result)) { return null; } $student = StudentFactory::getStudentByBannerId($bannerId); return array('student' => $student->getFullName()); }