Ejemplo n.º 1
0
 public function notify($game_id = 0)
 {
     if (empty($game_id)) {
         $game = GameFactory::getCurrent();
         $game_id = $game->getId();
     }
     $db = \Database::getDB();
     $tbl = $db->addTable('tg_lottery');
     $tbl->addFieldConditional('game_id', $game_id);
     $tbl->addFieldConditional('emailed', 0);
     $lottery_submissions = $db->select();
     if (empty($lottery_submissions)) {
         return 0;
     }
     $game = Game::getById($game_id);
     $count = 0;
     foreach ($lottery_submissions as $row) {
         $count++;
         $db->clearConditional();
         $tbl->resetValues();
         try {
             if ($row['winner'] == '1') {
                 $this->sendWinnerEmail($row, $game);
             } else {
                 $this->sendLoserEmail($row, $game);
             }
         } catch (\Exception $e) {
             $log = 'Email to student #' . $row['student_id'] . ' failed: ' . $e->getMessage();
             \PHPWS_Core::log($log, 'tailgate_email.log');
             throw $e;
         }
         $tbl->addFieldConditional('id', $row['id']);
         $tbl->addValue('emailed', 1);
         $db->update();
     }
     $game->setLotteryRun(true);
     GameFactory::saveResource($game);
     return $count;
 }
Ejemplo n.º 2
0
 public static function getAvailableSpots($game_id = 0, $lot_id = 0, $allow_reserved = false, $include_unclaimed = false, $active_only = true)
 {
     if (empty($game_id)) {
         $factory = new GameFactory();
         $game = GameFactory::getCurrent();
         if (empty($game)) {
             return null;
         }
         $game_id = $game->getId();
     } else {
         $game = GameFactory::getById($game_id);
     }
     $db2 = \Database::getDB();
     $lotteryTable = $db2->addTable('tg_lottery');
     $lotteryTable->addFieldConditional('game_id', $game_id);
     $lotteryTable->addFieldConditional('spot_id', 0, '!=');
     if ($include_unclaimed) {
         $lotteryTable->addFieldConditional('picked_up', 0, '!=');
     }
     $lotteryTable->addField('spot_id');
     $db = \Database::getDB();
     $spotTable = $db->addTable('tg_spot');
     $lotTable = $db->addTable('tg_lot');
     if ($active_only) {
         $lotTable->addFieldConditional('active', 1);
     }
     $lot_id = (int) $lot_id;
     if ($lot_id) {
         $spotTable->addFieldConditional('lot_id', $lot_id);
     }
     $lotTable->addField('title', 'lot_title');
     $spotTable->addOrderBy('lot_id');
     $spotTable->addOrderBy('number');
     $spotTable->addField('number');
     $spotTable->addField('id');
     $spotTable->addField('lot_id');
     $spotTable->addField('sober');
     $spotTable->addField('reserved');
     $spotTable->addFieldConditional('active', 1);
     if (!$allow_reserved) {
         $spotTable->addFieldConditional('reserved', 0);
     }
     $cond = $db->createConditional($spotTable->getField('lot_id'), $lotTable->getField('id'), '=');
     $db->joinResources($spotTable, $lotTable, $cond);
     $expression = new \Database\Expression('(' . $db2->selectQuery() . ')');
     $spotTable->addFieldConditional('id', $expression, 'not in');
     return $db->select();
 }