Beispiel #1
0
 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;
     }
 }
Beispiel #2
0
 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');
 }
Beispiel #3
0
 protected function deactivate($factory, $id)
 {
     $game = \tailgate\Factory\Game::getCurrent();
     if (!empty($game) && $game->getSignupStart() < time()) {
         throw \Exception('Lots cannot be deactivated after game signup has started.');
     }
     $factory->deactivate($id);
     $db = \Database::getDB();
     $tbl = $db->addTable('tg_spot');
     $tbl->addValue('active', 0);
     $tbl->addFieldConditional('lot_id', $id);
     $db->update();
     $view = new \View\JsonView(array('success' => true));
     $response = new \Response($view);
     return $response;
 }
Beispiel #4
0
 public function getHtmlView($data, \Request $request)
 {
     if (!$request->isVar('command')) {
         throw new \Exception('Bad command');
     }
     $command = $request->getVar('command');
     switch ($command) {
         case 'pickup':
             $content = Factory::pickup(GameFactory::getCurrentId());
             break;
         case 'winners':
             $content = Factory::winners(GameFactory::getCurrentId());
             break;
         case 'spotReport':
             $content = Factory::spotReport(GameFactory::getCurrentId());
             break;
         default:
             throw new \Exception('Unknown report command');
     }
     $view = new \View\HtmlView($content);
     return $view;
 }
Beispiel #5
0
 public static function assignStudent($student_id, $spot_id)
 {
     $game_id = Game::getCurrentId();
     $lot_id = Spot::getLotIdFromId($spot_id);
     self::removeUnclaimedSpot($spot_id);
     $lottery = self::getLotteryByStudentId($student_id);
     if (!$lottery) {
         $lottery = new Resource();
         $lottery->setGameId($game_id);
         $lottery->setStudentId($student_id);
     }
     $lottery->setLotId($lot_id);
     $lottery->setSpotId($spot_id);
     $lottery->setPickedUp(true);
     $lottery->setWinner(true);
     self::saveResource($lottery);
     return true;
 }
Beispiel #6
0
 public function confirm($hash)
 {
     $game = GameFactory::getCurrent();
     $db = \Database::getDB();
     $t = $db->addTable('tg_lottery');
     $t->addFieldConditional('game_id', $game->getId());
     $t->addFieldConditional('confirmation', $hash);
     $t->addValue('confirmed', 1);
     $result = (bool) $db->update();
     if ($result) {
         return true;
     }
     // if already confirmed, return true
     $t->addFieldConditional('confirmed', 1);
     $result = $db->select();
     return (bool) $result;
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
0
 private function changeDate()
 {
     $factory = new Factory();
     $game_id = filter_input(INPUT_POST, 'game_id', FILTER_SANITIZE_NUMBER_INT);
     $kickoff = filter_input(INPUT_POST, 'kickoff', FILTER_SANITIZE_STRING);
     $signup_start = filter_input(INPUT_POST, 'signup_start', FILTER_SANITIZE_STRING);
     $signup_end = filter_input(INPUT_POST, 'signup_end', FILTER_SANITIZE_STRING);
     $pickup_deadline = filter_input(INPUT_POST, 'pickup_deadline', FILTER_SANITIZE_STRING);
     $game = new Resource();
     $game->setId($game_id);
     $factory->load($game);
     if (!empty($kickoff)) {
         $game->setKickoff(strtotime($kickoff));
     } elseif (!empty($signup_start)) {
         $game->setSignupStart(strtotime($signup_start));
     } elseif (!empty($signup_end)) {
         $game->setSignupEnd(strtotime($signup_end));
     } elseif (!empty($pickup_deadline)) {
         $game->setPickupDeadline(strtotime($pickup_deadline));
     } else {
         throw new \Exception('Date not sent');
     }
     $factory->save($game);
     $garray = $game->getStringVars();
     $garray = $factory->addVisitorInformation($garray);
     $view = new \View\JsonView($garray);
     return $view;
 }
Beispiel #9
0
 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());
 }
Beispiel #10
0
 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;
 }