/**
  * Parse a block from an array
  * @param array $data
  *
  * @return Block|null
  */
 private function parseBlock(array $data)
 {
     $block = new Block();
     $block->setItemSet($this->itemSet);
     //Type
     if (isset($data['type'])) {
         $block->setType($data['type']);
     } else {
         $block->setType("Block");
     }
     //RecMath
     if (isset($data['recMath'])) {
         $block->setRecMath(new \SplBool(@(bool) $data['recMath']));
     }
     //MinSummonerLevel
     if (isset($data['minSummonerLevel'])) {
         $block->setMinSummonerLevel(new \SplInt(@(int) $data['minSummonerLevel']));
     }
     //MaxSummonerLevel
     if (isset($data['maxSummonerLevel'])) {
         $block->setMaxSummonerLevel(new \SplInt(@(int) $data['maxSummonerLevel']));
     }
     //showIfSummonerSpell
     if (isset($data['showIfSummonerSpell'])) {
         $spell = $this->summonerSpellList->getSpell($data['showIfSummonerSpell']);
         if ($spell != null) {
             $block->setShowIfSummonerSpell($spell);
         }
     }
     //hideIfSummonerSpell
     if (isset($data['hideIfSummonerSpell'])) {
         $spell = $this->summonerSpellList->getSpell($data['hideIfSummonerSpell']);
         if ($spell != null) {
             $block->setHideIfSummonerSpell($spell);
         }
     }
     //Comments
     if (isset($data['comment'])) {
         $block->setComment($data['comment']);
     }
     if (isset($data['items'])) {
         ksort($data['items']);
         $block->setItems($this->parseItems($data['items'], $block));
     }
     if (empty($block->getItems())) {
         return null;
     }
     return $block;
 }
 /**
  * Parse a block from an array
  * @param array $json
  *
  * @return Block|null null if empty
  */
 private function parseBlock(array $json)
 {
     $block = new Block();
     $block->setItemSet($this->itemSet);
     //Type
     if (isset($json['type'])) {
         $block->setType($json['type']);
     } else {
         $block->setType("Block");
     }
     //RecMath
     if (isset($json['recMath'])) {
         $block->setRecMath(new \SplBool(@(bool) $json['recMath']));
     }
     //MinSummonerLevel
     if (isset($json['minSummonerLevel'])) {
         $block->setMinSummonerLevel(new \SplInt(@(int) $json['minSummonerLevel']));
     }
     //MaxSummonerLevel
     if (isset($json['maxSummonerLevel'])) {
         $block->setMaxSummonerLevel(new \SplInt(@(int) $json['maxSummonerLevel']));
     }
     //showIfSummonerSpell
     if (isset($json['showIfSummonerSpell'])) {
         $spell = $this->summonerSpellList->getSpellFromKey($json['showIfSummonerSpell']);
         if ($spell != null) {
             $block->setShowIfSummonerSpell($spell);
         }
     }
     //hideIfSummonerSpell
     if (isset($json['hideIfSummonerSpell'])) {
         $spell = $this->summonerSpellList->getSpellFromKey($json['hideIfSummonerSpell']);
         if ($spell != null) {
             $block->setHideIfSummonerSpell($spell);
         }
     }
     foreach ($json['items'] as $item) {
         $i = $this->parseItem($item, $block);
         if ($i != null) {
             $block->addItem($i);
         }
     }
     if (empty($block->getItems())) {
         return null;
     }
     return $block;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }