private function apply() { $lottery = new \tailgate\Factory\Lottery(); $game_id = filter_input(INPUT_POST, 'game_id', FILTER_SANITIZE_NUMBER_INT); $student = StudentFactory::getCurrentStudent(); $student_id = $student->getId(); $lottery->apply($student_id, $game_id); }
protected function getJsonView($data, \Request $request) { $json = array(); $command = $request->getVar('command'); $factory = new Factory(); $lotteryFactory = new \tailgate\Factory\Lottery(); switch ($command) { case 'list': $game = Factory::getCurrent(); if ($game) { if ($game->getLotteryRun()) { $json['available_spots'] = count(\tailgate\Factory\Lottery::getAvailableSpots()); $lottery = new \tailgate\Factory\Lottery(); $json['winners'] = $lottery->getTotalWinners($game->getId()); $json['claimed'] = $lottery->totalSpotsClaimed($game->getId()); } else { $json['available_spots'] = $lotteryFactory->totalAvailableSpots(); } } break; case 'getCurrent': $json = $factory->getCurrentAsArray(); break; case 'getAvailableSpots': $json = array('available_spots' => $factory->totalAvailableSpots()); break; case 'unixtime': $json['unixtime'] = strtotime(filter_input(INPUT_GET, 'date', FILTER_SANITIZE_STRING)); break; default: throw new \Exception('Unknown command'); } $view = new \View\JsonView($json); return $view; }
public static function userStatusSidebar() { $game = Factory::getCurrent(); if (empty($game)) { $vars['current_game'] = 'No game scheduled. Check back later.'; } else { $vars['current_game'] = Factory::getGameStatus($game); } $vars['student_status'] = \tailgate\Factory\Lottery::getStudentStatus(); $template = new \Template(); $template->addVariables($vars); $template->setModuleTemplate('tailgate', 'User/sidebar.html'); $content = $template->get(); \Layout::add($content, 'tailgate', 'user_info'); }
private function assign() { $spot_id = filter_input(INPUT_POST, 'spotId', FILTER_SANITIZE_NUMBER_INT); $student_id = filter_input(INPUT_POST, 'studentId', FILTER_SANITIZE_NUMBER_INT); $game = \tailgate\Factory\Game::getCurrent(); if (!\tailgate\Factory\Game::isAfterPickup()) { throw new \Exception('Cannot assign spots until after pickup.'); } if (\tailgate\Factory\Lottery::spotPickedUp($spot_id)) { return false; } else { \tailgate\Factory\Lottery::assignStudent($student_id, $spot_id); return true; } }
/** * Number of student submissions to this lottery * @return integer */ private function getTotalSubmissions() { $factory = new Factory(); $current_game = \tailgate\Factory\Game::getCurrentId(); if (empty($current_game)) { $submissions = 0; } else { $submissions = $factory->getTotalSubmissions($current_game); } return (int) $submissions; }
public function ban($student_id, $reason) { $student = new Resource(); self::loadByID($student, $student_id); $student->setBanned(true); $student->setBannedReason(filter_var($reason, FILTER_SANITIZE_STRING)); $student->setIneligibleReason('Banned'); $student->stampBanned(); $student->setEligible(false); self::saveResource($student); Lottery::removeStudentWin($student_id, Game::getCurrentId()); }
private function confirmWinner() { $game = \tailgate\Factory\Game::getCurrent(); $hash = filter_input(INPUT_GET, 'hash', FILTER_SANITIZE_STRING); $template = new \Template(); $factory = new Factory(); $template->setModuleTemplate('tailgate', 'User/confirmation.html'); $template->add('button_color', 'primary'); if ($game->getPickupDeadline() < time()) { $template->add('message_color', 'danger'); $template->add('message', 'Sorry, the confirmation deadline for this lottery has passed.'); $template->add('url', \Server::getSiteUrl()); $template->add('label', 'Go back to home page'); $content = $template->get(); return $content; } $confirm = $factory->confirm($hash); if ($confirm) { $template->add('message_color', 'success'); $template->add('message', 'Lottery win confirmed!'); if (!\Current_User::isLogged()) { $template->add('url', \Server::getSiteUrl() . 'admin/'); $template->add('label', 'Log in to pick your lot'); } else { $template->add('url', \Server::getSiteUrl() . 'tailgate/'); $template->add('label', 'Go to your status page and pick a spot'); } } else { $template->add('message_color', 'danger'); $template->add('message', 'Sorry, could not confirm your lottery win. Contact us if you are having trouble.'); $template->add('url', \Server::getSiteUrl()); $template->add('label', 'Go back to home page'); } $content = $template->get(); return $content; }