diff --git a/src/AppBundle/Client/Rebrickable/Converter/PartPropertyNameConverter.php b/src/AppBundle/Client/Rebrickable/Converter/PartPropertyNameConverter.php index 415ce0a..3a14c63 100644 --- a/src/AppBundle/Client/Rebrickable/Converter/PartPropertyNameConverter.php +++ b/src/AppBundle/Client/Rebrickable/Converter/PartPropertyNameConverter.php @@ -17,7 +17,6 @@ class PartPropertyNameConverter implements NameConverterInterface case 'part_name': return 'name'; case 'part_id': return 'id'; case 'part_type_id': return 'typeId'; - case 'rb_color_id': return 'colorId'; default: return $propertyName; } } diff --git a/src/AppBundle/Client/Rebrickable/Entity/Part.php b/src/AppBundle/Client/Rebrickable/Entity/Part.php index 27a52ec..f26e8d5 100644 --- a/src/AppBundle/Client/Rebrickable/Entity/Part.php +++ b/src/AppBundle/Client/Rebrickable/Entity/Part.php @@ -22,6 +22,12 @@ class Part * @var string */ private $name; + /** + * Part type 1 = normal part, 2 = spare part. + * + * @var int + */ + private $type; /** * Year the part first appeared in sets. * @@ -40,28 +46,12 @@ class Part * @var string */ private $category; - - /** - * Part category/type id matching getPartTypes method values. - * - * @var int - */ - private $typeId; - /** * Array of colors the part appears in. * * @var array */ private $colors; - - /** - * Part color id matching getColors method values. - * - * @var - */ - private $colorId; - /** * Array of related Part IDs used by external systems. * @@ -101,6 +91,22 @@ class Part $this->id = $id; } + /** + * @return int + */ + public function getType() + { + return $this->type; + } + + /** + * @param int $type + */ + public function setType($type) + { + $this->type = $type; + } + /** * @return int */ @@ -132,7 +138,6 @@ class Part { $this->name = $name; } - /** * @return mixed */ @@ -180,7 +185,6 @@ class Part { $this->category = $category; } - /** * @return mixed */ @@ -196,7 +200,6 @@ class Part { $this->colors = $colors; } - /** * @return mixed */ diff --git a/src/AppBundle/Client/Rebrickable/Rebrickable.php b/src/AppBundle/Client/Rebrickable/Rebrickable.php index 177faf1..c2977c7 100644 --- a/src/AppBundle/Client/Rebrickable/Rebrickable.php +++ b/src/AppBundle/Client/Rebrickable/Rebrickable.php @@ -74,7 +74,8 @@ class Rebrickable { $encoders = array(new JsonEncoder()); $nameConverter = new PartPropertyNameConverter(); - $normalizers = array(new ObjectNormalizer(null, $nameConverter), new ArrayDenormalizer()); + $objectNormalizer = new ObjectNormalizer(null, $nameConverter); + $normalizers = array($objectNormalizer, new ArrayDenormalizer()); $serializer = new Serializer($normalizers, $encoders); return $serializer; @@ -100,7 +101,23 @@ class Rebrickable $serializer = $this->getSerializer(); $partsSTD = json_decode($data, true)[0]['parts']; - return $data ? $serializer->denormalize($partsSTD, Part::class.'[]', self::FORMAT) : null; + if ($data) { + $parts = $serializer->denormalize($partsSTD, Part::class.'[]', self::FORMAT); + foreach ($parts as $key => &$part) { + $part->setCategory($this->getPartTypes()[$partsSTD[$key]['part_type_id']]); + $part->setColors([ + 0 => [ + 'color_name' => $partsSTD[$key]['color_name'], + 'rb_color_id' => $partsSTD[$key]['rb_color_id'], + 'ldraw_color_id' => $partsSTD[$key]['ldraw_color_id'], + ], + ]); + } + + return $data; + } + + return null; } /**