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; }
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; }