Ejemplo n.º 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]);
 }
Ejemplo n.º 2
0
 public static function generate(array $params)
 {
     $code = Lib\Url::Get('code', null);
     $action = array_shift($params);
     if ($action === 'logout') {
         $user = Api\User::getCurrentUser();
         if ($user) {
             $user->logout();
             header('Location: /brackets/');
         }
     }
     if ($code) {
         $success = Api\User::authenticateUser($code);
         if ($success) {
             $redirect = Lib\Url::Get('state', '/');
             header('Location: ' . $redirect);
             exit;
         } else {
             Lib\Display::addKey('content', 'We were unable to verify your account at this time or your account age does not meet the requirements.');
         }
     } else {
         $obj = new stdClass();
         $obj->loginUrl = Api\User::getLoginUrl(Lib\Url::Get('redirect'));
         // Do a mobile check
         if (preg_match('/iphone|android|windows phone/i', $_SERVER['HTTP_USER_AGENT'])) {
             $obj->loginUrl = str_replace('authorize', 'authorize.compact', $obj->loginUrl);
         }
         $obj->originalUrl = Lib\Url::Get('redirect');
         Lib\Display::addKey('page', 'login');
         Lib\Display::addKey('title', 'Login' . DEFAULT_TITLE_SUFFIX);
         Lib\Display::renderAndAddKey('content', 'login', $obj);
     }
 }
Ejemplo n.º 3
0
 public static function generate(array $params)
 {
     $action = is_array($params) ? array_shift($params) : null;
     Lib\Display::setLayout('admin');
     $user = self::_checkLogin();
     if ($user) {
         self::$_user = $user;
         Lib\Display::addKey('user', $user);
         $message = null;
         $force = false;
         if (Lib\Url::GetBool('created')) {
             $message = ['message' => 'Bracket was created successfully!', 'type' => 'success'];
             $force = true;
         }
         if (Lib\Url::GetBool('edited')) {
             $message = ['message' => 'Bracket was updated successfully!', 'type' => 'success'];
             $force = true;
         }
         // If there's an action, check for that page controller and use it
         if ($action && class_exists('Controller\\Admin\\' . $action, true)) {
             call_user_func(['Controller\\Admin\\' . $action, 'generate'], $params);
         } else {
             // Show the rollup page
             self::_main($message, $force);
         }
     }
 }
Ejemplo n.º 4
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)]);
     }
 }
Ejemplo n.º 5
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]);
     }
 }
Ejemplo n.º 6
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]);
     }
 }
Ejemplo n.º 7
0
 public static function generate(array $params)
 {
     $page = array_shift($params);
     $page = $page ?: 'about';
     $path = VIEW_PATH . '/' . $page . '.md';
     $out = 'Uh oh... that doesn\'t seem to exist...';
     if (is_readable($path)) {
         $file = file_get_contents($path);
         $out = Lib\Michelf\Markdown::defaultTransform($file);
     }
     Lib\Display::addKey('page', 'static');
     Lib\Display::renderAndAddKey('content', 'static', $out);
 }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
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);
         }
     }
 }
Ejemplo n.º 11
0
 protected static function _enableAd()
 {
     Lib\Display::addKey('showAd', true);
     Lib\Display::addKey('isMobile', preg_match('/(iphone|android)/i', $_SERVER['HTTP_USER_AGENT']));
 }
Ejemplo n.º 12
0
 public static function generate(array $params)
 {
     Lib\Display::setLayout('landing');
     Lib\Display::addKey('rounds', Api\Round::getRandomCompletedRounds(30));
     Lib\Display::addKey('phrase', static::$_phrases[rand() % count(static::$_phrases)]);
 }