Exemplo n.º 1
0
 public static function getImportantTrainers($where = null, $limit = null, $order = ' i.`order_by`, i.`id` ')
 {
     if (!is_null($where)) {
         $where = 'WHERE ' . $where;
     }
     $getImportantTrainers = TPP::db()->query("SELECT\n\t\t\ti.`id`,\n\t\t\ti.`name`,\n\t\t\ti.`nickname`,\n\t\t\ti.`type`,\n\t\t\ti.`attempts`,\n\t\t\ti.`wins`,\n\t\t\ti.`losses`,\n\t\t\ti.`time`,\n\t\t\ti.`is_rematch`,\n\t\t\ti.`order_by`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titp.`id`,\n\t\t\t\t\titp.`pokemon`,\n\t\t\t\t\titp.`level`,\n\t\t\t\t\titp.`nickname`,\n\t\t\t\t\tIFNULL(itp.`item`, 1)\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titpm.important_trainer_pokemon_id,\n\t\t\t\t\titpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `important_trainer` i\n\t\t\tJOIN `important_trainer_pokemon` itp\n\t\t\t\tON itp.`important_trainer_id` = i.`id`\n\t\t  \tLEFT JOIN `important_trainer_pokemon_move` itpm\n\t\t  \t\tON itpm.`important_trainer_pokemon_id` = itp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY i.`id`\n\t\t\tORDER BY " . $order . $limit);
     if (!$getImportantTrainers) {
         return [];
     }
     $return = [];
     while ($importantTrainer = $getImportantTrainers->fetch()) {
         $newIT = new self();
         $newIT->setAttributes(['id' => (int) $importantTrainer['id'], 'name' => $importantTrainer['name'], 'nickname' => $importantTrainer['nickname'], 'type' => $importantTrainer['type'], 'attempts' => (int) $importantTrainer['attempts'], 'wins' => (int) $importantTrainer['wins'], 'losses' => (int) $importantTrainer['losses'], 'time' => $importantTrainer['time'], 'order_by' => (int) $importantTrainer['order_by'], 'is_rematch' => (bool) $importantTrainer['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($importantTrainer['pokemon'], ['id', 'pokemon', 'level', 'nickname', 'item'])]);
         $moves = [];
         foreach (explode(self::SEPARATOR_1, $importantTrainer['moves']) as $move) {
             $ex = explode(self::SEPARATOR_2, $move);
             $moves[$ex[0]][] = $ex[1];
         }
         foreach ($newIT->pokemon as $p) {
             if (isset($moves[$p->id])) {
                 $p->moves = $p->setMoves($moves[$p->id]);
             }
         }
         $return[] = $newIT;
     }
     return ['importanttrainers' => $return];
 }
Exemplo n.º 2
0
 public static function getEliteFour($where = null, $limit = null, $order = ' e.`order`, e.`id` ')
 {
     if (!is_null($where)) {
         $where = 'WHERE ' . $where;
     }
     $getEliteFour = TPP::db()->query("SELECT\n\t\t\te.`id`,\n\t\t\te.`name`,\n\t\t\te.`type`,\n\t\t\te.`attempts`,\n\t\t\te.`wins`,\n\t\t\te.`losses`,\n\t\t\te.`time`,\n\t\t\te.`is_rematch`,\n\t\t\te.`order`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefp.`id`,\n\t\t\t\t\tefp.`pokemon`,\n\t\t\t\t\tefp.`level`\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefpm.elite_four_pokemon_id,\n\t\t\t\t\tefpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `elite_four` e\n\t\t\tJOIN `elite_four_pokemon` efp\n\t\t\t\tON efp.`elite_four_id` = e.`id`\n\t\t  \tLEFT JOIN `elite_four_pokemon_move` efpm\n\t\t  \t\tON efpm.`elite_four_pokemon_id` = efp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY e.`id`\n\t\t\tORDER BY " . $order . $limit);
     if (!$getEliteFour) {
         return [];
     }
     $return = [];
     $beaten = $count_e4 = 0;
     while ($eliteFour = $getEliteFour->fetch()) {
         $count_e4++;
         if (isset($eliteFour['time']) && $eliteFour['time'] != '') {
             $beaten++;
         }
         $newE4 = new self();
         $newE4->setAttributes(['id' => (int) $eliteFour['id'], 'name' => $eliteFour['name'], 'type' => $eliteFour['type'], 'attempts' => (int) $eliteFour['attempts'], 'wins' => (int) $eliteFour['wins'], 'losses' => (int) $eliteFour['losses'], 'time' => $eliteFour['time'], 'order' => (int) $eliteFour['order'], 'is_rematch' => (bool) $eliteFour['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($eliteFour['pokemon'], ['id', 'pokemon', 'level'])]);
         $moves = [];
         foreach (explode(self::SEPARATOR_1, $eliteFour['moves']) as $move) {
             $ex = explode(self::SEPARATOR_2, $move);
             $moves[$ex[0]][] = $ex[1];
         }
         foreach ($newE4->pokemon as $p) {
             if (isset($moves[$p->id])) {
                 $p->moves = $p->setMoves($moves[$p->id]);
             }
         }
         $return[] = $newE4;
     }
     return ['beaten' => $beaten === $count_e4, 'elitefour' => $return];
 }
Exemplo n.º 3
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         $className = __CLASS__;
         self::$instance = new $className();
     }
     return self::$instance;
 }
Exemplo n.º 4
0
 public static function getAllItems()
 {
     $getItems = TPP::db()->query("\r\n\t\t\tSELECT i.*, it.`name` as `item_type`\r\n\t\t\tFROM `item` i\r\n\t\t\tJOIN `item_type` it\r\n\t\t\tON i.`item_type_id` = it.`id`\r\n\t\t\tWHERE `amount` != 0 OR `amount` IS NULL\r\n\t\t\tORDER BY `item_type_id`, `pc`, IFNULL(`amount`, 99) DESC, `name`") or die(TPP::db()->error);
     while ($item = $getItems->fetch_assoc()) {
         $newItem = new self();
         $newItem->setAttributes($item);
         $return[$item['item_type']][] = $newItem;
     }
     return $return;
 }
Exemplo n.º 5
0
 /**
  * getFacts: Return all facts
  * @return		array		Array of all Fact objects
  */
 public static function getFacts()
 {
     $getFacts = TPP::db()->query("\n\t\t\tSELECT `id`, `name`, `value`, `amount`\n\t\t\tFROM `fact`\n\t\t\tWHERE `order_id` > 0\n\t\t\tORDER BY `order_id`, `id`") or die(TPP::db()->error);
     while ($fact = $getFacts->fetch()) {
         $newFact = new self();
         $newFact->setAttributes($fact);
         $return[] = $newFact;
     }
     return $return;
 }
Exemplo n.º 6
0
 public static function getMilestones()
 {
     $getMilestones = TPP::db()->query("SELECT `id`, `name`, `time` FROM `milestone` WHERE `visible` = 1 ORDER BY `time`") or die(TPP::db()->error);
     while ($mile = $getMilestones->fetch_assoc()) {
         $newMilestone = new self();
         $newMilestone->setAttributes($mile);
         $newMilestone->time = FuncHelp::getDateTime($newMilestone->time);
         $return[] = $newMilestone;
     }
     return $return;
 }
Exemplo n.º 7
0
 /**
  * getCredits: Return all credits
  * @return		array		Array of all Credit objects
  */
 public static function getCredits()
 {
     $getCredits = TPP::db()->query("\r\n\t\t\tSELECT `id`, `name`, `title`, `pokemon`, `quote`, `generations`, `link`\r\n\t\t\tFROM `credits`\r\n\t\t\tWHERE `order_id` > 0\r\n\t\t\tORDER BY `order_id`, `id`") or die(TPP::db()->error);
     while ($credit = $getCredits->fetch_assoc()) {
         $newCredit = new self();
         $newCredit->setAttributes($credit);
         $newCredit->quote = Credit::getQuote($newCredit->quote);
         $newCredit->generations = self::getGenerations($newCredit->generations);
         $return[] = $newCredit;
     }
     return $return;
 }
Exemplo n.º 8
0
 public function getGeneral()
 {
     $getGeneral = TPP::db()->query("SELECT `name`, `value` FROM `general` WHERE `value` != ''") or die(TPP::db()->error);
     $model = new stdClass();
     while ($general = $getGeneral->fetch_assoc()) {
         $model->{$general}['name'] = utf8_encode(stripslashes($general['value']));
     }
     if (isset($model->notice)) {
         $model->notices = $this->getNotices($model->notice);
     }
     return $model;
 }
Exemplo n.º 9
0
 public static function getBoxes()
 {
     $return = [];
     $getBoxes = TPP::db()->query("SELECT `id`, `name`, `scenery`, `active` FROM `box` ORDER BY `id`");
     if (!$getBoxes) {
         return false;
     }
     while ($box = $getBoxes->fetch()) {
         $newBox = new self();
         $newBox->setAttributes($box);
         $return[] = $newBox;
     }
     return $return;
 }
Exemplo n.º 10
0
 public static function getBadges($where = null, $limit = null)
 {
     if (!is_null($where)) {
         $where = 'WHERE ' . $where;
     }
     $getBadges = TPP::db()->query("SELECT\r\n\t\t\tb.`id`,\r\n\t\t\tb.`name`,\r\n\t\t\tb.`time`,\r\n\t\t\tb.`leader`,\r\n\t\t\tb.`attempts`,\r\n\t\t\tGROUP_CONCAT(DISTINCT CONCAT_WS(':', bp.`pokemon`, bp.`level`) SEPARATOR ',') as `leader_pokemon`\r\n\t\t\tFROM `badge` b JOIN `badge_pokemon` bp ON bp.`badge_id` = b.`id`" . $where . " GROUP BY b.`id` ORDER BY `order_id`, `id`" . $limit);
     $obtained = 0;
     while ($badg = $getBadges->fetch_assoc()) {
         $newBadge = new self();
         $newBadge->setAttributes(array('id' => $badg['id'], 'name' => $badg['name'], 'time' => $badg['time'], 'leader' => self::getTrainerForBadge($badg['leader'], $badg['leader_pokemon']), 'attempts' => $badg['attempts']));
         if ($badg['attempts'] > 0) {
             $obtained++;
         }
         $return[] = $newBadge;
     }
     return array('obtained' => $obtained, 'badges' => $return);
 }
Exemplo n.º 11
0
 public function getFields()
 {
     $fields = array();
     $getFields = TPP::db()->query("\r\n\t\tSELECT\r\n\t\t\tf.`name`,\r\n\t\t\tpfe.`pokemon_id`,\r\n\t\t\tpfe.`value`\r\n\t\tFROM\r\n\t\t\t`pokemon_field_eav` pfe,\r\n\t\t\t`field` f\r\n\t\tWHERE\r\n\t\t\tpfe.`pokemon_id` = {$this->id}\r\n\t\tAND\r\n\t\t\tpfe.`field_id` = f.`id`");
     $i = 0;
     while ($fi = $getFields->fetch_assoc()) {
         $fields[$fi['name']] = $fi['value'];
     }
     if (isset($fields['next_move'])) {
         $move = new Move();
         $move->name = $fields['next_move'];
         unset($fields['next_move']);
         if (isset($fields['next_move_level'])) {
             $move->level = $fields['next_move_level'];
             unset($fields['next_move_level']);
         }
         $fields['next_move'] = $move;
     }
     return $fields;
 }
Exemplo n.º 12
0
 public static function getBadges($where = null, $limit = null, $order = ' `order_id`, `id` ')
 {
     if (!is_null($where)) {
         $where = 'WHERE ' . $where;
     }
     $getBadges = TPP::db()->query("SELECT\n\t\t\tb.`id`,\n\t\t\tb.`name`,\n\t\t\tb.`time`,\n\t\t\tb.`leader`,\n\t\t\tb.`type`,\n\t\t\tb.`attempts`,\n\t\t\tGROUP_CONCAT(DISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "', bp.`id`, bp.`pokemon`, bp.`level`) SEPARATOR '" . self::SEPARATOR_1 . "') as `leader_pokemon`\n\t\t\tFROM `badge` b JOIN `badge_pokemon` bp ON bp.`badge_id` = b.`id`" . $where . " GROUP BY b.`id` ORDER BY " . $order . $limit);
     $obtained = 0;
     $return = [];
     if ($getBadges) {
         while ($badg = $getBadges->fetch()) {
             $newBadge = new self();
             $newBadge->setAttributes(['id' => (int) $badg['id'], 'name' => $badg['name'], 'time' => $badg['time'], 'type' => $badg['type'], 'leader' => self::getTrainerForBadge($badg['leader'], $badg['leader_pokemon']), 'attempts' => (int) $badg['attempts']]);
             if (isset($badg['time']) && $badg['time'] != '') {
                 $obtained++;
             }
             $return[] = $newBadge;
         }
     } else {
         $obtained = '?';
     }
     return ['obtained' => $obtained, 'badges' => $return];
 }
Exemplo n.º 13
0
<?php

$time = microtime(true);
prioIncludes();
includes();
new Init();
if (TPP_DEBUG) {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    set_error_handler("exception_error_handler", E_ALL);
}
TPP::initializeConnection(new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE . TWITCHVERSION));
$site = new SiteController();
$site->actionIndex();
echo '<h1>loaded in ' . round(microtime(true) - $time, 7) . ' secs</h1>';
exit;
function prioIncludes()
{
    $priorityIncludes = array('helpers' => array('ErrorHandler'), 'controllers' => array('Controller'), 'models' => array('TPP', 'Model'));
    foreach ($priorityIncludes as $key => $prio) {
        foreach ($prio as $pr) {
            include_once $key . '/' . $pr . '.php';
        }
    }
}
function includes()
{
    $includes = array('controllers', 'models', 'helpers');
    foreach ($includes as $inc) {
        foreach (glob($inc . "/*.php") as $filename) {
            include_once $filename;