Exemplo n.º 1
0
 public static function generate(array $params)
 {
     $bracket = Api\Bracket::getBracketByPerma(array_shift($params));
     if ($bracket) {
         Lib\Display::addKey('page', 'characters');
         $content = Lib\Display::renderAndAddKey('content', 'characters', (object) ['bracket' => $bracket, 'characters' => Api\Character::getByBracketId($bracket->id)]);
     }
 }
Exemplo n.º 2
0
 public static function generate(array $params)
 {
     $bracket = Api\Bracket::getBracketByPerma(array_shift($params));
     if ($bracket) {
         Lib\Display::addKey('page', 'characters');
         Lib\Display::addKey('title', $bracket->name . ' Entrants' . DEFAULT_TITLE_SUFFIX);
         $hasSource = $bracket->hasSourceLabel();
         $hasSeed = $bracket->state == BS_VOTING || $bracket->state == BS_FINAL;
         $content = Lib\Display::renderAndAddKey('content', 'characters', (object) ['bracket' => $bracket, 'characters' => Api\Character::getByBracketId($bracket->id), 'hasSource' => $hasSource, 'hasSeed' => $hasSeed, 'hasSorter' => $hasSource || $hasSeed]);
     }
 }
Exemplo n.º 3
0
 public static function generate(array $params)
 {
     $perma = array_shift($params);
     $bracket = Api\Bracket::getBracketByPerma($perma);
     if ($bracket) {
         // TODO - get full voting stats
         $entrantStats = Api\Stats::getEntrantPerformanceStats($bracket);
         Lib\Display::addKey('page', 'stats');
         Lib\Display::addKey('title', 'Stats for ' . $bracket->name . DEFAULT_TITLE_SUFFIX);
         Lib\Display::renderAndAddKey('content', 'stats', ['entrants' => $entrantStats, 'bracket' => $bracket]);
     }
 }
Exemplo n.º 4
0
 public static function generate(array $params)
 {
     $perma = array_shift($params);
     $bracket = Api\Bracket::getBracketByPerma($perma);
     if ($bracket) {
         $bracket->results = $bracket->getResults();
         $user = Api\User::getCurrentUser();
         if ($user) {
             $bracket->userVotes = $bracket->getVotesForUser($user);
         }
         Lib\Display::addKey('page', 'results');
         Lib\Display::renderAndAddKey('content', 'results', $bracket);
     }
 }
Exemplo n.º 5
0
 public static function generate(array $params)
 {
     self::_checkLogin();
     $bracket = Api\Bracket::getBracketByPerma(array_shift($params));
     self::_enableAd();
     if ($bracket) {
         $bracket->nameLabel = $bracket->nameLabel ?: 'Character name';
         $bracket->sourceLabel = $bracket->sourceLabel ?: 'Source';
         $bracket->sourceLabel = $bracket->sourceLabel === 'NO_SOURCE' ? false : $bracket->sourceLabel;
         $out = (object) ['rules' => Lib\Michelf\Markdown::defaultTransform($bracket->rules), 'bracket' => $bracket];
         Lib\Display::addKey('page', 'nominate');
         Lib\Display::renderAndAddKey('content', 'nominate', $out);
     }
 }
Exemplo n.º 6
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);
         }
     }
 }
Exemplo n.º 7
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);
 }