Beispiel #1
0
 public static function generate(array $params)
 {
     $active = array_shift($params) !== 'past';
     $brackets = Lib\Cache::fetch(function () use($active) {
         $allBrackets = Api\Bracket::getAll();
         // Filter out active/completed brackets
         $brackets = [];
         foreach ($allBrackets as $bracket) {
             if ($active && ($bracket->state == BS_ELIMINATIONS || $bracket->state == BS_VOTING || $bracket->state == BS_NOMINATIONS)) {
                 $bracket->title = Api\Round::getBracketTitleForActiveRound($bracket);
                 $brackets[] = $bracket;
             }
             if (!$active && $bracket->state == BS_FINAL) {
                 $brackets[] = $bracket;
             }
         }
         // Check for card images
         foreach ($brackets as $bracket) {
             if (is_readable('./images/bracket_' . $bracket->id . '_card.jpg')) {
                 $bracket->cardImage = '/images/bracket_' . $bracket->id . '_card.jpg';
             } else {
                 $bracket->entrants = Api\Character::getRandomCharacters($bracket, 9);
             }
         }
         return $brackets;
     }, 'Controller::Brackets_displayBrackets_' . ($active ? 'active' : 'completed'));
     Lib\Display::addKey('page', 'brackets');
     $title = $active ? 'Current Brackets' : 'Past Brackets';
     Lib\Display::renderAndAddKey('content', 'bracketsView', ['brackets' => $brackets, 'title' => $title]);
 }
Beispiel #2
0
 protected static function _main($message = null, $force = false)
 {
     $out = new stdClass();
     $out->brackets = Api\Bracket::getUserOwnedBrackets(self::$_user, $force);
     // If there's no message passed directly, check for one from cache
     $message = !$message ? self::_getStashedMessage() : $message;
     if ($out->brackets) {
         // Check for card images
         foreach ($out->brackets as $bracket) {
             if (is_readable('./images/bracket_' . $bracket->id . '_card.jpg')) {
                 $bracket->cardImage = '/images/bracket_' . $bracket->id . '_card.jpg';
             } else {
                 $bracket->entrants = Api\Character::getRandomCharacters($bracket, 9);
             }
         }
         // Sort the brackets by reverse date
         usort($out->brackets, function ($a, $b) {
             return $a->state == BS_FINAL || $a->state > $b->state ? 1 : -1;
         });
         // Decorate each bracket with some information about what phase it can
         // safely move to. Mostly this is for eliminations
         foreach ($out->brackets as $bracket) {
             $bracket->title = Api\Round::getBracketTitleForActiveRound($bracket);
             $bracket->nextIsFinal = $bracket->title === 'Title Match';
             // Get the title of the next round
             $nextRounds = Api\Round::getNextRounds($bracket);
             $bracket->nextTitle = null;
             if ($nextRounds) {
                 $bracket->nextTitle = str_replace(['Voting - ', 'Eliminations - '], '', Api\Round::getBracketTitleForRound($bracket, $nextRounds[0]));
             }
             // This is a dumb catch all while I work out issues in the stored procedure
             $bracket->nextTitle = $bracket->nextTitle ?: 'Next Round';
             if ($bracket->state == BS_ELIMINATIONS) {
                 // Should query all the brackets at once, but I'm feeling lazy tonight...
                 $result = Lib\Db::Query('SELECT MIN(round_group) AS current_group, MAX(round_group) AS last_group FROM `round` WHERE bracket_id = :bracketId AND round_final = 0', [':bracketId' => $bracket->id]);
                 if ($result && $result->count) {
                     $row = Lib\Db::Fetch($result);
                     // If the eliminations are on the last group, don't show the
                     // advance button
                     if ($row->current_group == $row->last_group) {
                         $bracket->showStart = true;
                     } else {
                         $bracket->showAdvance = true;
                     }
                 }
             }
         }
     }
     if ($message) {
         $out->message = $message;
     }
     Lib\Display::renderAndAddKey('content', 'admin/brackets', $out);
 }
Beispiel #3
0
 private static function _getBracketCharacters()
 {
     $retVal = null;
     $bracketId = Lib\Url::GetInt('bracketId', null);
     $count = Lib\Url::GetInt('count', null);
     if ($bracketId) {
         //If $count has a value, get random characters from the given bracket
         if ($count) {
             $bracket = \Api\Bracket::getById($bracketId);
             if ($bracket) {
                 //3 levels of IFs. This is getting rediculous
                 $retVal = \Api\Character::getRandomCharacters($bracket, $count);
             }
         } else {
             $retVal = \Api\Character::getByBracketId($bracketId);
         }
     }
     return $retVal;
 }