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]; }
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]; }
public static function getTrainerForBadge($leader, $pokemon_string) { $trainer = new Trainer(); $trainer->setName($leader); $trainer->setPokemon($trainer->getPokemonForTrainer($pokemon_string, ['id', 'pokemon', 'level'], true)); return $trainer; }