Example #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;
     }
 }
Example #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');
 }
Example #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;
 }
Example #4
0
 public function getList($mode = TG_LIST_ALL, $order_by = null, $order_dir = 'asc')
 {
     $game = Game::getCurrent();
     if (empty($order_by)) {
         $order_by = 'last_name';
     }
     $db = $this->getListDB($mode, $order_by, $order_dir);
     $student = $db->getTable($this->table);
     $users = $db->addTable('users');
     $users->addField('email');
     $users->addField('username');
     $conditional = $db->createConditional($student->getField('user_id'), $users->getField('id'));
     $db->joinResources($student, $users, $conditional);
     // if game show if they won lottery
     if ($game) {
         $lottery = $db->addTable('tg_lottery');
         $lottery->addField('winner');
         $lottery->addField('picked_up');
         $s_l_cond = $db->createConditional($student->getField('id'), $lottery->getField('student_id'));
         $db->joinResources($student, $lottery, $s_l_cond, 'left');
     }
     $limit = filter_input(INPUT_GET, 'limit', FILTER_SANITIZE_NUMBER_INT);
     if (empty($limit)) {
         $limit = 50;
     }
     $search = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING);
     if (!empty($search)) {
         $c1 = $db->createConditional($student->getField('first_name'), "%{$search}%", 'like');
         $c2 = $db->createConditional($student->getField('last_name'), "%{$search}%", 'like');
         $c3 = $db->createConditional($users->getField('username'), "%{$search}%", 'like');
         $c4 = $db->createConditional($c1, $c2, 'or');
         $c5 = $db->createConditional($c3, $c4, 'or');
         $db->addConditional($c5);
     }
     $db->setLimit($limit);
     $result = $db->select();
     return $result;
 }
Example #5
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;
 }
Example #6
0
 private function updateKickoff()
 {
     $game = Factory::getCurrent();
     $kickoff_unix = $this->getUnix('date');
     if ($game->getPickupDeadline() > $kickoff_unix) {
         $json['error'] = 'Kickoff deadline must proceed the pickup deadline.';
         $json['success'] = false;
     } else {
         $game->setKickoff($kickoff_unix);
         Factory::saveResource($game);
         $json['success'] = true;
     }
     return $json;
 }
Example #7
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;
 }