protected function getJsonView($data, \Request $request) { if (!$request->isVar('command')) { throw new \Exception('Unknown Election command'); } $json = array('success' => true); $command = $request->getVar('command'); switch ($command) { case 'list': $json = Factory::getList(); break; case 'getElection': $json = $this->getElection($request->getVar('electionId')); break; case 'getElectionTypes': echo Factory::getFilterTypes(); exit; break; case 'checkConflict': $json = Factory::checkForConflict(Factory::pullGetInteger('startDate'), Factory::pullGetInteger('endDate'), Factory::pullGetInteger('electionId')); break; case 'findVote': $json = Factory::getStudentVoteInformation(Factory::pullGetInteger('electionId'), Factory::pullGetInteger('searchFor')); break; } $view = new \View\JsonView($json); return $view; }
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; }