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