/** * 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; }
/** * 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; }