<?php //Style echo '<style>body{font-family:Sans-serif;color:#900;font-size:.9em;max-width:500px;margin:10% auto 30% auto; padding:20px;border-radius:15px;border:1px solid #890;box-shadow:0 10px 20px #999}h1{font-size:5em;margin:0 0 10px 0}</style>'; // Constants define('WEB_PATH', str_replace('\\', '/', strpos(__DIR__, 'phar://') !== false ? dirname(str_replace('phar://', '', __DIR__)) . '/' : __DIR__ . '/')); define('RPHAR', strpos(WEB_PATH, 'phar://') !== false ? WEB_PATH : false); define('URL', $url = 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI'])); // Defaults error_reporting(E_ALL ^ E_STRICT); setlocale(LC_ALL, 'pt_BR'); date_default_timezone_set('America/Sao_Paulo'); // Error/Exception set set_exception_handler('exception'); //Include DB include APP_PATH . 'lib/db.php'; // Data base configuration $db = new Lib\Db(['dsn' => 'mysql:host=localhost;charset=utf8', 'user' => 'root', 'passw' => 'root#123456']); //Runing ... $r = $db->query(file_get_contents(CONFIG_PATH . 'install.sql')); //Success: exit('<h1>Sucesso!</h1><p>Instalação terminada!!</p><p>Agora, exclua o arquivo de instalação <i>(' . __FILE__ . ')</i><br>antes de acessar o site (<a href="' . URL . '">' . URL . '</a>)</p>'); //Data base exception function exception($e) { if (get_class($e) == 'PDOException') { exit('<h1>Oops!!</h1>' . $e->getMessage() . '<br><br><b>Verifique a configuração de acesso ao banco de dados</b><br>Indique um usuário (root?!) que tenha permissão para criar banco de dados, tabelas, etc.<br><br><i>Obs: configuração na linha <b>26</b> do arquivo </i>' . __FILE__); } }
<?php require 'config.php'; require 'lib/aal.php'; // Disable caching Lib\Cache::setDisabled(true); // Get all brackets that need to be updated $brackets = Api\Bracket::queryReturnAll(['advanceHour' => gmdate('G'), 'state' => ['in' => [BS_ELIMINATIONS, BS_VOTING]]]); if ($brackets && count($brackets)) { foreach ($brackets as $bracket) { echo 'Advancing ', $bracket->name, '...'; $bracket->advance(); Api\Bracket::getBracketByPerma($bracket->perma); echo 'DONE', PHP_EOL; } } // Reorder the brackets based upon participation Lib\Db::Query('CALL proc_UpdateBracketScores'); // Clean out old brackets Lib\Db::Query('CALL proc_CleanBrackets'); // Refresh caches Api\Bracket::getAll();
<?php require 'lib/aal.php'; $db = Lib\Mongo::getDatabase(); $characterRankingInfo = $db->characterRankingInfo; $result = Lib\Db::Query('SELECT * FROM `character` WHERE bracket_id = 6 AND (SELECT COUNT(1) FROM round WHERE round_tier > 0 AND (round_character1_id = character_id OR round_character2_id = character_id)) > 0'); while ($row = Lib\Db::Fetch($result)) { $character = new Api\Character($row); echo $character->name, '...'; $obj = new stdClass(); $obj->characterId = (int) $character->id; $obj->performance = round($character->getAverageRoundPerformance(true) * 100); $obj->alsoVotedFor = $character->getCharactersAlsoVotedFor(false, true); $obj->sameSourceVotes = $character->getCharactersAlsoVotedFor(true, true); // JSON encode/decode the object to strip private keys $obj = json_decode(json_encode($obj)); // Check for this character in the collection so we can update the existing record. This is intentionally // done after the JSON bullshit above to make sure the object is correctly represented $record = $characterRankingInfo->findOne(['characterId' => $character->id]); if ($record) { $obj->_id = $record['_id']; } $characterRankingInfo->save($obj); echo 'DONE', PHP_EOL; }
function getPercentTimesVotedFor($char, $users) { $retVal = 0; $query = 'SELECT round_id FROM round WHERE round_character1_id = :id OR round_character2_id = :id'; $result = Lib\Db::Query('SELECT COUNT(1) AS total, SUM(CASE WHEN character_id = :id THEN 1 ELSE 0 END) AS character_votes FROM votes WHERE round_id IN (' . $query . ') AND user_id IN (' . implode(',', $users) . ')', [':id' => $char->id]); if ($result && $result->count) { $row = Lib\Db::Fetch($result); $retVal = (int) $row->character_votes / (int) $row->total; } return $retVal; }
<?php //Style echo '<style>body{font-family:Sans-serif;color:#900;font-size:.9em;max-width:500px;margin:10% auto 30% auto; padding:20px;border-radius:15px;border:1px solid #890;box-shadow:0 10px 20px #999}h1{font-size:5em;margin:0 0 10px 0}</style>'; // Constants define('ROOT', str_replace('\\', '/', strpos(__DIR__, 'phar://') !== false ? dirname(str_replace('phar://', '', __DIR__)) . '/' : __DIR__ . '/')); define('RPHAR', strpos(ROOT, 'phar://') !== false ? ROOT : false); define('URL', $url = 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI'])); // Defaults error_reporting(E_ALL ^ E_STRICT); setlocale(LC_ALL, 'pt_BR'); date_default_timezone_set('America/Sao_Paulo'); // Error/Exception set set_exception_handler('exception'); //Include DB include ROOT . '.app/lib/db.php'; // Data base configuration $db = new Lib\Db(['dsn' => 'mysql:host=localhost;charset=utf8', 'user' => 'root', 'passw' => 'root#123456']); //Runing ... $r = $db->query(file_get_contents(ROOT . '.app/config/install.sql')); //Success: exit('<h1>Sucesso!</h1><p>Instalação terminada!!</p><p>Agora, exclua o arquivo de instalação <i>(' . __FILE__ . ')</i><br>antes de acessar o site (<a href="' . URL . '">' . URL . '</a>)</p>'); //Data base exception function exception($e) { if (get_class($e) == 'PDOException') { exit('<h1>Oops!!</h1>' . $e->getMessage() . '<br><br><b>Verifique a configuração de acesso ao banco de dados</b><br>Indique um usuário (root?!) que tenha permissão para criar banco de dados, tabelas, etc.<br><br><i>Obs: configuração na linha <b>26</b> do arquivo </i>' . __FILE__); } }