/** * @param ItemSet|null $itemSet Prepare the parser to use a specified ItemSet */ public function __construct(ItemSet $itemSet = null) { $api = ApiManager::getAPI(); $this->summonerSpellList = $api->staticData()->getSummonerSpells('all'); $this->itemList = $api->staticData()->getItems('all'); $this->itemSet = $itemSet == null ? new ItemSet() : $itemSet; }
/** * Return the items of an given Block * @param Block $block * * @return ItemBlock[] */ public static function findAllByBlock(Block $block) { $id = $block->getId(); $pdo = DatabaseManager::getConnection(); $stmt = $pdo->prepare("SELECT * FROM itemblock WHERE id_block = :id"); $stmt->bindParam(':id', $id, \PDO::PARAM_INT); $stmt->execute(); $array = $stmt->fetchAll(); if ($array == false) { return []; } $items = []; $api = ApiManager::getAPI(); foreach ($array as $data) { $item = new ItemBlock(); $item->setId($data['id']); $item->setItem($api->staticData()->getItem($data['item'], 'all')); $item->setCount(new \SplInt((int) $data['count'])); $item->setBlock($block); $items[] = $item; } return $items; }
private function displayItemSet(ItemSet $itemSet) { $twig = $this->twigInit(); $template = $twig->loadTemplate('itemSet.html.twig'); $api = ApiManager::getAPI(); $champions = $api->staticData()->getChampions(); $champions->sortByName(); echo $template->render(['itemSet' => $itemSet, 'version' => $api->staticData()->version()[0], 'champions' => $champions]); }
/** * Return the list of Blocks of a given itemset * @param ItemSet $itemSet * * @return Block[] */ public static function findAllByItemSet(ItemSet $itemSet) { $id = $itemSet->getId(); $pdo = DatabaseManager::getConnection(); $stmt = $pdo->prepare("SELECT * FROM block WHERE id_itemset = :id"); $stmt->bindParam(':id', $id, \PDO::PARAM_INT); $stmt->execute(); $array = $stmt->fetchAll(); if ($array == false) { return []; } $blocks = []; foreach ($array as $data) { $block = new Block(); $block->setId($data['id']); $block->setType($data['type']); $block->setRecMath(new \SplBool($data['recMath'] == 1 ? true : false)); $block->setMinSummonerLevel(new \SplInt((int) $data['minSummonerLevel'])); $block->setMaxSummonerLevel(new \SplInt((int) $data['maxSummonerLevel'])); $api = ApiManager::getAPI(); if ($data['showIfSummonerSpell'] != 0) { $block->setShowIfSummonerSpell($api->staticData()->getSummonerSpell($data['showIfSummonerSpell'], 'all')); } if ($data['hideIfSummonerSpell'] != 0) { $block->setHideIfSummonerSpell($api->staticData()->getSummonerSpell($data['hideIfSummonerSpell'], 'all')); } $block->setComment($data['comment']); $block->setItemSet($itemSet); $block->setItems(ItemBlock::findAllByBlock($block)); $blocks[] = $block; } return $blocks; }
/** * Parse the array to add data to the current ItemSet * This is used to parse data from database * @param array $data */ private function parseArray(array $data) { $this->setId($data['id']); $this->setTitle($data['title']); $this->setType(ItemSetType::getItemSetType($data['type'])); $this->setMap(Map::getMap($data['map'])); $this->setMode(Mode::getMode($data['mode'])); $this->setPriority(new \SplBool($data['priority'] == 1 ? true : false)); $this->setSortrank(new \SplInt((int) $data['sortrank'])); $this->setComment($data['comment']); if ($data['champion'] != 0) { $this->setChampion(ApiManager::getAPI()->staticData()->getChampion($data['champion'], 'all')); } //No blocks as they are loading when needed }