public static function getAllChallenges() { if (!self::$allFetched) { $items = query(__CLASS__)->where(array('year' => Year::current()))->sort('name')->selectMultiple(); self::$cache = array(); foreach ($items as $item) { self::$cache[$item->id] = $item; } self::$allFetched = true; } return self::$cache; }
/** * Test the creation methods. */ function test_creation() { $epochYear = Year::epoch(); $this->assertEqual(strtolower(get_class($epochYear)), 'year'); $this->assertEqual($epochYear->dayOfYear(), 1); $this->assertEqual($epochYear->daysInYear(), 365); $duration = $epochYear->duration(); $this->assertTrue($duration->isEqualTo(Duration::withDays(365))); $this->assertEqual($epochYear->startYear(), 1901); $current = Year::current(); $this->assertEqual($current->startYear(), $this->currentYear); $aYear = Year::withYear(1999); $this->assertEqual($aYear->startYear(), 1999); $aYear = Year::withYear(2005); $this->assertEqual($aYear->startYear(), 2005); $aYear = Year::starting(DateAndTime::withYearDay(1982, 25)); $this->assertEqual($aYear->startYear(), 1982); $this->assertEqual($aYear->dayOfYear(), 25); $this->assertEqual($aYear->daysInYear(), 365); }
if (key_exists('remove', $_POST) && $position >= POSITION_ADMIN) { $winner_id = $_POST['winner_id']; $action = 'remove'; } else { if (key_exists('claim', $_POST)) { $code = $_POST['code']; $action = 'claim'; } } } } } // ACTION switch ($action) { case 'new': $challenge = new Challenge(array('year' => Year::current(), 'name' => $challenge_name, 'points' => $challenge_points, 'code' => $challenge_code)); $challenge->doAdd("Created challenge {$challenge_name} successfully."); break; case 'delete': $challenge = Challenge::getChallenge($challenge_id); foreach ($challenge->getWinners() as $winner) { $winner->doRemove(); } $challenge->doRemove("Deleted challenge successfully."); break; case 'add': $winner = new ChallengeWinner(array('team' => $team_id, 'challenge' => $challenge_id)); $winner->doAdd("Added challenge winner successfully."); break; case 'remove': $winner = ChallengeWinner::getChallengeWinner($winner_id);
foreach ($prefixes as $prefix) { $formDistance = $prefix . 'Distance'; $formDirection = $prefix . 'Direction'; $formCity = $prefix . 'City'; $isNull = $formData[$formDistance] == null || $formData[$formDirection] == null || $formData[$formCity] == null; if ($isNull) { $formData[$formDistance] = null; $formData[$formDirection] = null; $formData[$formCity] = null; } } return $formData; } switch ($action) { case 'new': $clue = new Clue(array('year' => Year::current(), 'name' => $clue_name, 'time' => $clue_time)); $clue->doAdd('Created clue successfully.'); break; case 'edit': $clue = Clue::getClue($clue_id); $form_data = setNullIfEmpty($_POST); $form_data = coagulateTimes($form_data, array('', 'start', 'hint', 'answer')); $form_data = coagulateLocs($form_data, array('start', 'hint', 'answer')); $clue->makeChanges($form_data); $clue->doUpdate('Edited clue successfully.'); break; case 'delete': $clue = Clue::getClue($clue_id); foreach ($clue->getClueStates() as $clueState) { $clueState->doRemove(); }
/** * Create a new instance. aMonth is an Integer or a String * * @param string $anIntOrStrMonth * @return object Duration * @access public * @since 5/13/05 * @static */ static function withMonth($anIntOrStrMonth) { $currentYear = Year::current(); $month = Month::withMonthYear($anIntOrStrMonth, $currentYear->startYear()); $obj = $month->duration(); return $obj; }
$team_id = $_POST['id']; $team_name = $_POST['text']; $action = 'rename'; } } } } } // ACTION $position = Session::defaultPosition(); if ($position < POSITION_ADMIN) { $action = null; } switch ($action) { case 'new': $team = new Team(array('year' => Year::current(), 'name' => $team_name)); $team->doAdd("Created team {$team_name} successfully."); break; case 'delete': $team = Team::getTeam($team_id); $team->doRemove("Deleted team successfully."); break; case 'add': $user = Person::getPersonBySUNetID($sunetid); if ($user) { $user->makeChanges(array('team' => $team_id)); $user->doUpdate("Added user {$sunetid} successfully."); } else { add_notification("No user with SUNetID {$sunetid} exists!"); } break;
public function getCurrentClue() { Clue::getAllClues(); $clueStates = query('ClueState')->where(array('team' => $this->id))->selectMultiple(); if (!$clueStates) { return query('Clue')->where(array('year' => Year::current()))->sort('time')->limit(1)->selectSingle(); } $currentClue = head($clueStates)->getClue(); foreach ($clueStates as $clueState) { $clue = $clueState->getClue(); if ($clue && (!$currentClue || $clue->getRawTime() > $currentClue->getRawTime())) { $currentClue = $clue; } } return $currentClue; }