public function downloadAction($args = []) { if (!empty($args)) { $itemSet = ItemSet::findById($args['id']); if ($itemSet) { header('Content-disposition: attachment; filename="' . $itemSet->getTitle() . '.json"'); header('Content-type: application/json'); echo $itemSet->toJson(); } else { $twig = $this->twigInit(); $template = $twig->loadTemplate('404.html.twig'); echo $template->render([]); } } else { $twig = $this->twigInit(); $template = $twig->loadTemplate('404.html.twig'); echo $template->render([]); } }
/** * 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; }
/** * Give the list of item set * @return ItemSet[] list of ItemSet */ public static function findAll() { $array = []; $pdo = DatabaseManager::getConnection(); $stmt = $pdo->prepare("SELECT * FROM itemset ORDER BY id DESC "); $stmt->execute(); while ($data = $stmt->fetch()) { $itemSet = new ItemSet(); $itemSet->parseArray($data); $array[] = $itemSet; } return $array; }