/**
  * Convert an item block from array to our models
  * @param array $data
  * @param Block $block
  * @return ItemBlock[]
  */
 private function parseItems(array $data, Block $block)
 {
     $items = [];
     $last = -1;
     foreach ($data as $id) {
         if ($id != $last) {
             $itemBlock = new ItemBlock();
             $itemBlock->setBlock($block);
             $item = $this->itemList->getItem($id);
             if ($item != null) {
                 $itemBlock->setItem($item);
                 $itemBlock->setCount(new \SplInt(1));
                 $items[] = $itemBlock;
                 $last = $id;
             }
         } else {
             $add = end($items);
             $add->setCount(new \SplInt((int) $add->getCount() + 1));
         }
     }
     return $items;
 }
 /**
  * Convert an item block from array json to our models
  * @param array $json
  * @param Block $block
  * @return ItemBlock|null null if empty
  */
 private function parseItem(array $json, Block $block)
 {
     $itemBlock = new ItemBlock();
     $itemBlock->setBlock($block);
     //Item concerned
     if (isset($json['id'])) {
         $item = $this->itemList->getItem(@(int) $json['id']);
         if ($item != null) {
             $itemBlock->setItem($item);
         } else {
             return null;
         }
     } else {
         return null;
     }
     //Count
     if (isset($json['count'])) {
         $itemBlock->setCount(new \SplInt(@(int) $json['count']));
     }
     return $itemBlock;
 }
 /**
  * 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;
 }