示例#1
0
 private static function _getCurrentRounds()
 {
     $retVal = null;
     $bracketId = Lib\Url::GetInt('bracketId', null);
     if ($bracketId) {
         $retVal = \Api\Round::getCurrentRounds($bracketId);
     }
     return $retVal;
 }
示例#2
0
 public static function generate(array $params)
 {
     $user = self::_checkLogin();
     self::_enableAd();
     $perma = array_shift($params);
     $bracket = Api\Bracket::getBracketByPerma($perma);
     if ($bracket->start <= time() && ($bracket->state == BS_ELIMINATIONS || $bracket->state == BS_VOTING || $bracket->state == BS_WILDCARD)) {
         $cacheKey = 'CurrentRound_' . $bracket->id . '_' . $user->id;
         $out = Lib\Cache::fetch(function () use($user, $bracket) {
             $out = new stdClass();
             $out->userId = $user->id;
             $out->round = Api\Round::getCurrentRounds($bracket->id);
             $out->title = Api\Round::getBracketTitleForActiveRound($bracket);
             return $out;
         }, $cacheKey, CACHE_MEDIUM);
         if ($out) {
             $out->bracket = $bracket;
             $template = $out->bracket->state == BS_ELIMINATIONS ? 'eliminations' : 'voting';
             if ($bracket->state != BS_ELIMINATIONS) {
                 $entrantSwap = Lib\TestBucket::get('entrantSwap');
                 if ($entrantSwap !== 'control') {
                     foreach ($out->round as $round) {
                         // Interesting side effect that I had not considered before:
                         // When TestBucket initializes, it's setting the random seed for the entire RNG (duh).
                         // That means the following random line will produce a static set of results, so the
                         // user experience won't be wonky.
                         if ($entrantSwap === 'flip' || $entrantSwap === 'random' && rand() % 2 === 0) {
                             $round = self::_flipEntrants($round);
                         }
                     }
                 }
             }
             Lib\Display::addKey('page', 'vote');
             Lib\Display::addKey('title', $bracket->name . ' - Voting' . DEFAULT_TITLE_SUFFIX);
             Lib\Display::renderAndAddKey('content', $template, $out);
         }
     }
 }
示例#3
0
 /**
  * Refreshes various generic caches. This is expensive; use sparingly
  */
 protected static function _refreshCaches(Api\Bracket $bracket = null)
 {
     Lib\Cache::setDisabled(true);
     // Refresh the main collections
     Api\Bracket::getAll();
     Api\Bracket::getUserOwnedBrackets(self::$_user);
     \Controller\Brackets::generate(['past']);
     \Controller\Brackets::generate([]);
     // Refresh a single bracket if specified
     if ($bracket) {
         Api\Bracket::getBracketByPerma($bracket->perma);
         Api\Round::getCurrentRounds($bracket->id);
         $bracket->getResults();
     }
     Lib\Cache::setDisabled(false);
 }
示例#4
0
 /**
  * Advances a standard bracket tier
  */
 private function _advanceBracket()
 {
     $rounds = Round::getCurrentRounds($this->id, true);
     if (count($rounds) > 1) {
         for ($i = 0, $count = count($rounds); $i < $count; $i += 2) {
             // Get the round winners
             $winner1 = $rounds[$i]->getWinnerId();
             $winner2 = $rounds[$i + 1]->getWinnerId();
             // Create the round for the next tier
             $newRound = new Round();
             $newRound->bracketId = $this->id;
             $newRound->tier = $rounds[$i]->tier + 1;
             $newRound->group = $rounds[$i]->group;
             $newRound->order = $i / 2;
             $newRound->character1Id = $winner1;
             $newRound->character2Id = $winner2;
             $newRound->sync();
             // Finalize the current tier
             $rounds[$i]->getVoteCount();
             $rounds[$i]->final = true;
             $rounds[$i]->sync();
             $rounds[$i + 1]->getVoteCount();
             $rounds[$i + 1]->final = true;
             $rounds[$i + 1]->sync();
         }
     } else {
         if (count($rounds) === 1) {
             $round = $rounds[0];
             $round->getVoteCount();
             $round->final = true;
             $round->sync();
             $this->winner = $round->getWinner();
             $this->winnerCharacterId = $this->winner->id;
             $this->state = BS_FINAL;
             $this->sync();
         }
     }
     // Clear the results cache
     Lib\Cache::Set('Api:Bracket:getResults_' . $this->id, false, 1);
 }