From 83992cdcdd8f2d07081f91f3fae429d2bc94fd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Mon, 6 Feb 2017 01:33:46 +0100 Subject: [PATCH 1/3] migrate rebrickable api to v3 --- app/Resources/views/part/detail.html.twig | 2 +- app/config/services.yml | 2 +- .../Converter/PartPropertyNameConverter.php | 23 -- .../Converter/PropertyNameConverter.php | 27 ++ .../Api/Client/Rebrickable/Entity/Color.php | 211 +++------------- .../Api/Client/Rebrickable/Entity/Part.php | 237 +++++++----------- .../Rebrickable/Entity/PartCategory.php | 69 +++++ .../Api/Client/Rebrickable/Entity/Set.php | 119 +++++++-- .../Api/Client/Rebrickable/Entity/Theme.php | 75 ++++++ .../Api/Client/Rebrickable/Rebrickable.php | 69 ----- .../Api/Client/Rebrickable/Rebrickable_v3.php | 67 +++++ .../Api/Manager/RebrickableManager.php | 184 +++++++------- 12 files changed, 560 insertions(+), 525 deletions(-) delete mode 100644 src/AppBundle/Api/Client/Rebrickable/Converter/PartPropertyNameConverter.php create mode 100644 src/AppBundle/Api/Client/Rebrickable/Converter/PropertyNameConverter.php create mode 100644 src/AppBundle/Api/Client/Rebrickable/Entity/PartCategory.php create mode 100644 src/AppBundle/Api/Client/Rebrickable/Entity/Theme.php delete mode 100644 src/AppBundle/Api/Client/Rebrickable/Rebrickable.php create mode 100644 src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php diff --git a/app/Resources/views/part/detail.html.twig b/app/Resources/views/part/detail.html.twig index b6461a2..c3a5f29 100644 --- a/app/Resources/views/part/detail.html.twig +++ b/app/Resources/views/part/detail.html.twig @@ -7,7 +7,7 @@ {{ dump(localPart) }}
- + {% endblock %} diff --git a/app/config/services.yml b/app/config/services.yml index 5814f07..21eb13b 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -3,7 +3,7 @@ services: class: AppBundle\Api\Client\Brickset\Brickset arguments: ['%brickset_apikey%'] client.rebrickable: - class: AppBundle\Api\Client\Rebrickable\Rebrickable + class: AppBundle\Api\Client\Rebrickable\Rebrickable_v3 arguments: ['%rebrickable_apikey%'] manager.brickset: diff --git a/src/AppBundle/Api/Client/Rebrickable/Converter/PartPropertyNameConverter.php b/src/AppBundle/Api/Client/Rebrickable/Converter/PartPropertyNameConverter.php deleted file mode 100644 index 7b79762..0000000 --- a/src/AppBundle/Api/Client/Rebrickable/Converter/PartPropertyNameConverter.php +++ /dev/null @@ -1,23 +0,0 @@ -rb_color_id; + return $this->id; } /** - * @param int $rb_color_id + * @param int $id */ - public function setRbColorId($rb_color_id) + public function setId($id) { - $this->rb_color_id = $rb_color_id; - } - - /** - * @return array - */ - public function getLdrawColorId() - { - return $this->ldraw_color_id; - } - - /** - * @param array $ldraw_color_id - */ - public function setLdrawColorId($ldraw_color_id) - { - $this->ldraw_color_id = $ldraw_color_id; - } - - /** - * @return array - */ - public function getBricklinkColorId() - { - return $this->bricklink_color_id; - } - - /** - * @param array $bricklink_color_id - */ - public function setBricklinkColorId($bricklink_color_id) - { - $this->bricklink_color_id = $bricklink_color_id; - } - - /** - * @return array - */ - public function getBrickowlColorId() - { - return $this->brickowl_color_id; - } - - /** - * @param array $brickowl_color_id - */ - public function setBrickowlColorId($brickowl_color_id) - { - $this->brickowl_color_id = $brickowl_color_id; + $this->id = $id; } /** * @return string */ - public function getColorName() + public function getName() { - return $this->color_name; + return $this->name; } /** - * @param string $color_name + * @param string $name */ - public function setColorName($color_name) + public function setName($name) { - $this->color_name = $color_name; - } - - /** - * @return int - */ - public function getNumParts() - { - return $this->num_parts; - } - - /** - * @param int $num_parts - */ - public function setNumParts($num_parts) - { - $this->num_parts = $num_parts; - } - - /** - * @return int - */ - public function getNumSets() - { - return $this->num_sets; - } - - /** - * @param int $num_sets - */ - public function setNumSets($num_sets) - { - $this->num_sets = $num_sets; - } - - /** - * @return int - */ - public function getYear1() - { - return $this->year1; - } - - /** - * @param int $year1 - */ - public function setYear1($year1) - { - $this->year1 = $year1; - } - - /** - * @return int - */ - public function getYear2() - { - return $this->year2; - } - - /** - * @param int $year2 - */ - public function setYear2($year2) - { - $this->year2 = $year2; + $this->name = $name; } /** @@ -225,10 +70,26 @@ class Color } /** - * @param string $rgbl + * @param string $rgb */ public function setRgb($rgb) { $this->rgb = $rgb; } + + /** + * @return bool + */ + public function isIsTrans() + { + return $this->isTrans; + } + + /** + * @param bool $isTrans + */ + public function setIsTrans($isTrans) + { + $this->isTrans = $isTrans; + } } diff --git a/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php b/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php index 000446b..103e624 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php +++ b/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php @@ -5,17 +5,11 @@ namespace AppBundle\Api\Client\Rebrickable\Entity; class Part { /** - * Part ID. + * Part ID number. * * @var int */ - private $id; - /** - * Quantity of part in set returned from getSetParts. - * - * @var int - */ - private $qty; + private $number; /** * Part Name. * @@ -23,72 +17,89 @@ class Part */ private $name; /** - * Part type 1 = normal part, 2 = spare part. + * Part category id. * * @var int */ - private $type; + private $categoryId; + /** * Year the part first appeared in sets. * * @var int */ - private $year1; + private $yearFrom; /** * Year the part was last seen in sets. * * @var int */ - private $year2; - /** - * Part category/type description. - * - * @var string - */ - private $category; + private $yearTo; /** * Array of colors the part appears in. * * @var array */ - private $colors; - /** - * Array of related Part IDs used by external systems. - * - * @var array - */ - private $external_part_ids; + private $externalIds; /** * Rebrickable URL to the Part Details page. * * @var string */ - private $part_url; + private $url; /** * Rebrickable URL of the main part image (tries to use most common color). * * @var string */ - private $part_img_url; + private $imgUrl; - public function __construct() + /** + * @return int + */ + public function getPartNum() { + return $this->partNum; + } + + /** + * @param int $partNum + */ + public function setPartNum($partNum) + { + $this->partNum = $partNum; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; } /** * @return int */ - public function getId() + public function getCategoryId() { - return $this->id; + return $this->categoryId; } /** - * @param $part_id + * @param int $categoryId */ - public function setId($id) + public function setCategoryId($categoryId) { - $this->id = $id; + $this->categoryId = $categoryId; } /** @@ -110,144 +121,80 @@ class Part /** * @return int */ - public function getQty() + public function getYearFrom() { - return $this->qty; + return $this->yearFrom; } /** - * @param $qty + * @param int $yearFrom */ - public function setQty($qty) + public function setYearFrom($yearFrom) { - $this->qty = $qty; + $this->yearFrom = $yearFrom; + } + + /** + * @return int + */ + public function getYearTo() + { + return $this->yearTo; + } + + /** + * @param int $yearTo + */ + public function setYearTo($yearTo) + { + $this->yearTo = $yearTo; + } + + /** + * @return array + */ + public function getExternalIds() + { + return $this->externalIds; + } + + /** + * @param array $externalIds + */ + public function setExternalIds($externalIds) + { + $this->externalIds = $externalIds; } /** * @return string */ - public function getName() + public function getUrl() { - return $this->name; + return $this->url; } /** - * @param mixed $name + * @param string $url */ - public function setName($name) + public function setUrl($url) { - $this->name = $name; + $this->url = $url; } /** - * @return mixed + * @return string */ - public function getYear1() + public function getImgUrl() { - return $this->year1; + return $this->imgUrl; } /** - * @param mixed $year1 + * @param string $imgUrl */ - public function setYear1($year1) + public function setImgUrl($imgUrl) { - $this->year1 = $year1; - } - - /** - * @return mixed - */ - public function getYear2() - { - return $this->year2; - } - - /** - * @param mixed $year2 - */ - public function setYear2($year2) - { - $this->year2 = $year2; - } - - /** - * @return mixed - */ - public function getCategory() - { - return $this->category; - } - - /** - * @param mixed $category - */ - public function setCategory($category) - { - $this->category = $category; - } - - /** - * @return mixed - */ - public function getColors() - { - return $this->colors; - } - - /** - * @param mixed $colors - */ - public function setColors($colors) - { - $this->colors = $colors; - } - - /** - * @return mixed - */ - public function getExternalPartIds() - { - return $this->external_part_ids; - } - - /** - * @param mixed $external_part_ids - */ - public function setExternalPartIds($external_part_ids) - { - $this->external_part_ids = $external_part_ids; - } - - /** - * @return mixed - */ - public function getPartUrl() - { - return $this->part_url; - } - - /** - * @param mixed $part_url - */ - public function setPartUrl($part_url) - { - $this->part_url = $part_url; - } - - /** - * @return mixed - */ - public function getPartImgUrl() - { - return $this->part_img_url; - } - - /** - * @param $part_img_url - */ - public function setPartImgUrl($part_img_url) - { - $this->part_img_url = $part_img_url; + $this->imgUrl = $imgUrl; } } diff --git a/src/AppBundle/Api/Client/Rebrickable/Entity/PartCategory.php b/src/AppBundle/Api/Client/Rebrickable/Entity/PartCategory.php new file mode 100644 index 0000000..269b394 --- /dev/null +++ b/src/AppBundle/Api/Client/Rebrickable/Entity/PartCategory.php @@ -0,0 +1,69 @@ +id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getPartCount() + { + return $this->partCount; + } + + /** + * @param int $partCount + */ + public function setPartCount($partCount) + { + $this->partCount = $partCount; + } +} diff --git a/src/AppBundle/Api/Client/Rebrickable/Entity/Set.php b/src/AppBundle/Api/Client/Rebrickable/Entity/Set.php index 0c71222..a02891b 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Entity/Set.php +++ b/src/AppBundle/Api/Client/Rebrickable/Entity/Set.php @@ -9,41 +9,58 @@ class Set * * @var int */ - protected $set_id; + private $number; /** * Set description. * * @var string */ - protected $name; + private $name; /** - * Number of sets the part appears in. + * Year of set release. * * @var int */ - protected $num_parts; - + private $year; /** - * Set constructor. + * Count of parts in set. + * + * @var int */ - public function __construct() - { - } + private $numParts; + /** + * Rebrickable internal theme id. + * + * @var int + */ + private $themeId; + /** + * Rebrickable URL of the main set image. + * + * @var string + */ + private $imgUrl; + /** + * Rebrickable URL to the Set Details page. + * + * @var string + */ + private $url; /** * @return int */ - public function getSetId() + public function getNumber() { - return $this->set_id; + return $this->number; } /** - * @param int $set_id + * @param int $number */ - public function setSetId($set_id) + public function setNumber($number) { - $this->set_id = $set_id; + $this->number = $number; } /** @@ -65,16 +82,80 @@ class Set /** * @return int */ - public function getNumParts() + public function getYear() { - return $this->num_parts; + return $this->year; } /** - * @param int $num_parts + * @param int $year */ - public function setNumParts($num_parts) + public function setYear($year) { - $this->num_parts = $num_parts; + $this->year = $year; + } + + /** + * @return int + */ + public function getNumParts() + { + return $this->numParts; + } + + /** + * @param int $numParts + */ + public function setNumParts($numParts) + { + $this->numParts = $numParts; + } + + /** + * @return int + */ + public function getThemeId() + { + return $this->themeId; + } + + /** + * @param int $themeId + */ + public function setThemeId($themeId) + { + $this->themeId = $themeId; + } + + /** + * @return string + */ + public function getImgUrl() + { + return $this->imgUrl; + } + + /** + * @param string $imgUrl + */ + public function setImgUrl($imgUrl) + { + $this->imgUrl = $imgUrl; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + */ + public function setUrl($url) + { + $this->url = $url; } } diff --git a/src/AppBundle/Api/Client/Rebrickable/Entity/Theme.php b/src/AppBundle/Api/Client/Rebrickable/Entity/Theme.php new file mode 100644 index 0000000..5bb9088 --- /dev/null +++ b/src/AppBundle/Api/Client/Rebrickable/Entity/Theme.php @@ -0,0 +1,75 @@ +id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getParentId() + { + return $this->parentId; + } + + /** + * @param int $parentId + */ + public function setParentId($parentId) + { + $this->parentId = $parentId; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } +} diff --git a/src/AppBundle/Api/Client/Rebrickable/Rebrickable.php b/src/AppBundle/Api/Client/Rebrickable/Rebrickable.php deleted file mode 100644 index 03b412e..0000000 --- a/src/AppBundle/Api/Client/Rebrickable/Rebrickable.php +++ /dev/null @@ -1,69 +0,0 @@ -client = new Client(['base_uri' => self::BASE_URI]); - $this->apiKey = $apiKey; - } - - /** - * @param $method - * @param $parameters - * - * @return null|string - */ - public function call($method, $parameters = []) - { - $parameters['query']['key'] = $this->apiKey; - $parameters['query']['format'] = self::FORMAT; - - try { - $response = $this->client->request('GET', $method, $parameters); - - if ($response->getStatusCode() === 200) { - $content = $response->getBody()->getContents(); - if ($content === 'INVALIDKEY') { - //TODO - throw new LogicException('Invalid API Key'); - } elseif ($content === 'NOSET' || $content === 'NOPART') { - return null; - } - - return $content; - } - //TODO - throw new LogicException($response->getStatusCode()); - } catch (ConnectException $e) { - //TODO - throw new LogicException($e->getMessage()); - } catch (ClientException $e) { - //TODO - throw new LogicException($e->getMessage()); - } - } -} diff --git a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php new file mode 100644 index 0000000..d3e5eaf --- /dev/null +++ b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php @@ -0,0 +1,67 @@ +client = new Client(['base_uri' => self::BASE_URI]); + $this->apiKey = $apiKey; + } + + /** + * @param $method + * @param $uri + * @param array $options + * + * @return string + */ + public function call($method, $uri, $options = []) + { + $options['query']['key'] = $this->apiKey; + $options['headers'] = [ + 'Accept' => 'application/json', + ]; + + try { + $response = $this->client->request($method, $uri, $options); + + $content = $response->getBody()->getContents(); + + return $content; + } catch (ConnectException $e) { + //TODO + throw new LogicException($e); + } catch (ClientException $e) { + //TODO + if ($e->getCode() == 404) { + throw new LogicException('Not Found'); + } + if ($e->getCode() == 500) { + throw new LogicException('Invalid token'); + } + throw new LogicException($e); + } + } +} diff --git a/src/AppBundle/Api/Manager/RebrickableManager.php b/src/AppBundle/Api/Manager/RebrickableManager.php index 40ef01e..d8997e8 100644 --- a/src/AppBundle/Api/Manager/RebrickableManager.php +++ b/src/AppBundle/Api/Manager/RebrickableManager.php @@ -2,11 +2,13 @@ namespace AppBundle\Api\Manager; -use AppBundle\Api\Client\Rebrickable\Converter\PartPropertyNameConverter; +use AppBundle\Api\Client\Rebrickable\Converter\PropertyNameConverter; use AppBundle\Api\Client\Rebrickable\Entity\Color; use AppBundle\Api\Client\Rebrickable\Entity\Part; +use AppBundle\Api\Client\Rebrickable\Entity\PartCategory; use AppBundle\Api\Client\Rebrickable\Entity\Set; -use AppBundle\Api\Client\Rebrickable\Rebrickable; +use AppBundle\Api\Client\Rebrickable\Entity\Theme; +use AppBundle\Api\Client\Rebrickable\Rebrickable_v3; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -17,151 +19,149 @@ class RebrickableManager const FORMAT = 'json'; /** - * @var Rebrickable + * @var Rebrickable_v3 */ private $rebrickableClient; + /** + * @var Serializer + */ + private $serializer; + /** * RebrickableManager constructor. * - * @param Rebrickable $rebrickableClient + * @param Rebrickable_v3 $rebrickableClient */ - public function __construct(Rebrickable $rebrickableClient) + public function __construct(Rebrickable_v3 $rebrickableClient) { $this->rebrickableClient = $rebrickableClient; + $this->serializer = $this->initSerializer(); } - private function getSerializer() + private function initSerializer() { $encoders = [new JsonEncoder()]; - $nameConverter = new PartPropertyNameConverter(); - $objectNormalizer = new ObjectNormalizer(null, $nameConverter); + $objectNormalizer = new ObjectNormalizer(null, new PropertyNameConverter()); $normalizers = [$objectNormalizer, new ArrayDenormalizer()]; $serializer = new Serializer($normalizers, $encoders); return $serializer; } - /** - * Get a list of all parts (normal + spare) used in a set. - * - * @param string $setName unique rebrickable set name - * - * @return Part[]|null - */ - public function getSetParts($setName) - { - $parameters = [ - 'query' => [ - 'set' => $setName, - ], - ]; - - $data = $this->rebrickableClient->call('get_set_parts', $parameters); - - $serializer = $this->getSerializer(); - $partsSTD = json_decode($data, true)[0]['parts']; - - 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; - } - /** * Get details about a specific part. * - * @param $partID + * @param $id * - * @return Part|null + * @return Part */ - public function getPart($partID) + public function getPart($id) { - $parameters = [ - 'query' => [ - 'part_id' => $partID, - 'inc_ext' => 1, - ], - ]; + $data = $this->rebrickableClient->call('GET', 'lego/parts/'.$id); - $data = $this->rebrickableClient->call('get_part', $parameters); - $serializer = $this->getSerializer(); - - return $data ? $serializer->deserialize($data, Part::class, self::FORMAT) : null; + return $this->serializer->deserialize($data, Part::class, self::FORMAT); } /** - * Get associative array of colors used by all parts where key == rb_color_id. + * Get details about a specific Color. * - * @return Color[]|null + * @param $id + * + * @return Color */ - public function getColors() + public function getColor($id) { - $data = json_decode($this->rebrickableClient->call('get_colors'), true); + $data = $this->rebrickableClient->call('GET', 'lego/colors/'.$id); - $serializer = $this->getSerializer(); - - $colors = []; - - foreach ($data as $item) { - $color = $serializer->denormalize($item, Color::class, self::FORMAT); - $colors[$color->getRbColorId()] = $color; - } - - return $data ? $colors : []; + return $this->serializer->deserialize($data, Color::class, self::FORMAT); } /** - * Get associative array of themes used by all parts where key == part_type_id. + * Get details for a specific Set. * - * @return string[] + * @param $id + * + * @return Set */ - public function getPartTypes() + public function getSet($id) { - $data = json_decode($this->rebrickableClient->call('get_part_types'), true)['part_types']; + $data = $this->rebrickableClient->call('GET', 'lego/sets/'.$id); - $types = []; - foreach ($data as $item) { - $types[$item['part_type_id']] = $item['desc']; - } + return $this->serializer->deserialize($data, Set::class, self::FORMAT); + } - return $data ? $types : null; + /** + * Return details for a specific Theme. + * + * @param $id + * + * @return Theme + */ + public function getTheme($id) + { + $data = $this->rebrickableClient->call('GET', 'lego/themes/'.$id); + + return $this->serializer->deserialize($data, Theme::class, self::FORMAT); + } + + /** + * Return details for a specific PartCategory. + * + * @param $id + * + * @return PartCategory + */ + public function getPartCategory($id) + { + $data = $this->rebrickableClient->call('GET', 'lego/part_categories/'.$id); + + return $this->serializer->deserialize($data, PartCategory::class, self::FORMAT); } /** * Get the list of sets that a specific part/color appears in. * - * @param $partID - * @param $colorID + * @param $partId + * @param $colorId + * @param $page * * @return Set[] */ - public function getPartSets($partID, $colorID) + public function getPartSets($partId, $colorId, $page = null) { - $parameters = [ + $options = [ 'query' => [ - 'part_id' => $partID, - 'color_id' => $colorID, + 'page' => $page, ], ]; - $serializer = $this->getSerializer(); + $response = $this->rebrickableClient->call('GET', 'lego/parts/'.$partId.'/colors/'.$colorId.'/sets', $options); + $data = json_decode($response, true)['results']; - $data = json_decode($this->rebrickableClient->call('get_part_sets', $parameters), true)[0]['sets']; + return $this->serializer->denormalize($data, Set::class.'[]', self::FORMAT); + } - return $data ? $serializer->denormalize($data, Set::class.'[]', self::FORMAT) : null; + /** + * Get a list of all parts (normal + spare) used in a set. + * + * @param $setId + * @param $page + * + * @return + */ + public function getSetParts($setId, $page = null) + { + $options = [ + 'query' => [ + 'page' => $page, + ], + ]; +// +// $response = $this->rebrickableClient->call('GET','lego/sets/'.$setId.'/parts', $options); +// +// $data = json_decode($response, true)['results']; +// +// return $this->serializer->denormalize($data, Part::class . '[]', self::FORMAT); } } From 1a9b856b3e6aca6351508a2c07446ba0dd2b2786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Tue, 7 Feb 2017 13:54:05 +0100 Subject: [PATCH 2/3] Update rebrickable entities Update rebrickable entities to match new structure of rebrickable v3 data --- .../Api/Client/Rebrickable/Entity/Part.php | 10 +- src/AppBundle/Entity/Keyword.php | 112 ---------------- .../Entity/{ => Rebrickable}/Category.php | 48 +------ .../Entity/{ => Rebrickable}/Color.php | 66 ++++++--- .../Entity/{ => Rebrickable}/Part.php | 86 ++++-------- .../Part_Set.php} | 46 +++---- .../{BuildingKit.php => Rebrickable/Set.php} | 111 ++++++---------- src/AppBundle/Entity/Rebrickable/Theme.php | 125 ++++++++++++++++++ .../Repository/BuildingKitRepository.php | 26 ---- .../Repository/CategoryRepository.php | 13 -- src/AppBundle/Repository/ColorRepository.php | 13 -- .../Repository/KeywordRepository.php | 13 -- src/AppBundle/Repository/ModelRepository.php | 13 -- src/AppBundle/Repository/PartRepository.php | 13 -- .../Repository/Part_BuildingKitRepository.php | 13 -- 15 files changed, 268 insertions(+), 440 deletions(-) delete mode 100644 src/AppBundle/Entity/Keyword.php rename src/AppBundle/Entity/{ => Rebrickable}/Category.php (64%) rename src/AppBundle/Entity/{ => Rebrickable}/Color.php (63%) rename src/AppBundle/Entity/{ => Rebrickable}/Part.php (54%) rename src/AppBundle/Entity/{Part_BuildingKit.php => Rebrickable/Part_Set.php} (66%) rename src/AppBundle/Entity/{BuildingKit.php => Rebrickable/Set.php} (57%) create mode 100644 src/AppBundle/Entity/Rebrickable/Theme.php delete mode 100644 src/AppBundle/Repository/BuildingKitRepository.php delete mode 100644 src/AppBundle/Repository/CategoryRepository.php delete mode 100644 src/AppBundle/Repository/ColorRepository.php delete mode 100644 src/AppBundle/Repository/KeywordRepository.php delete mode 100644 src/AppBundle/Repository/ModelRepository.php delete mode 100644 src/AppBundle/Repository/PartRepository.php delete mode 100644 src/AppBundle/Repository/Part_BuildingKitRepository.php diff --git a/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php b/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php index 103e624..b845c54 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php +++ b/src/AppBundle/Api/Client/Rebrickable/Entity/Part.php @@ -57,17 +57,17 @@ class Part /** * @return int */ - public function getPartNum() + public function getNumber() { - return $this->partNum; + return $this->number; } /** - * @param int $partNum + * @param int $number */ - public function setPartNum($partNum) + public function setNumber($number) { - $this->partNum = $partNum; + $this->number = $number; } /** diff --git a/src/AppBundle/Entity/Keyword.php b/src/AppBundle/Entity/Keyword.php deleted file mode 100644 index f35ebba..0000000 --- a/src/AppBundle/Entity/Keyword.php +++ /dev/null @@ -1,112 +0,0 @@ -building_kits = new ArrayCollection(); - } - - /** - * Get id. - * - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * Set name. - * - * @param string $name - * - * @return Keyword - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name. - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @return ArrayCollection - */ - public function getBuildingKits() - { - return $this->building_kits; - } - - /** - * @param BuildingKit $building_kit - * - * @return Keyword - */ - public function addBuildingKit(BuildingKit $building_kit) - { - $this->building_kits->add($building_kit); - - return $this; - } - - /** - * @param BuildingKit $building_kit - * - * @return Keyword - */ - public function removeBuildingKit(BuildingKit $building_kit) - { - $this->building_kits->remove($building_kit); - - return $this; - } -} diff --git a/src/AppBundle/Entity/Category.php b/src/AppBundle/Entity/Rebrickable/Category.php similarity index 64% rename from src/AppBundle/Entity/Category.php rename to src/AppBundle/Entity/Rebrickable/Category.php index 10be5c7..448f713 100644 --- a/src/AppBundle/Entity/Category.php +++ b/src/AppBundle/Entity/Rebrickable/Category.php @@ -1,6 +1,6 @@ models = new ArrayCollection(); $this->parts = new ArrayCollection(); } @@ -87,40 +79,6 @@ class Category return $this->name; } - /** - * Get models. - * - * @return ArrayCollection - */ - public function getModels() - { - return $this->models; - } - - /** - * @param Model $model - * - * @return Category - */ - public function addModel(Model $model) - { - $this->models->add($model); - - return $this; - } - - /** - * @param Model $model - * - * @return Category - */ - public function removeModel(Model $model) - { - $this->models->remove($model); - - return $this; - } - /** * Get parts. * diff --git a/src/AppBundle/Entity/Color.php b/src/AppBundle/Entity/Rebrickable/Color.php similarity index 63% rename from src/AppBundle/Entity/Color.php rename to src/AppBundle/Entity/Rebrickable/Color.php index abd6547..5055a1b 100644 --- a/src/AppBundle/Entity/Color.php +++ b/src/AppBundle/Entity/Rebrickable/Color.php @@ -1,7 +1,8 @@ part_sets = new ArrayCollection(); + } /** * Set id. @@ -114,43 +130,55 @@ class Color return $this->rgb; } + /** + * Is transparent. + * + * @return bool + */ + public function isTransparent() + { + return $this->transparent; + } + + /** + * Set transparent. + * + * @param bool $transparent + */ + public function setTransparent($transparent) + { + $this->transparent = $transparent; + } + /** * @return Collection */ public function getPartBuildingKits() { - return $this->part_building_kits; + return $this->part_sets; } /** - * @param Part_BuildingKit $part_building_kit + * @param Part_Set $part_building_kit * * @return Color */ - public function addPartBuildingKit(Part_BuildingKit $part_building_kit) + public function addPartBuildingKit(Part_Set $part_set) { - $this->part_building_kits->add($part_building_kit); + $this->part_sets->add($part_set); return $this; } /** - * @param Part_BuildingKit $part_building_kit + * @param Part_Set $part_building_kit * * @return Color */ - public function removePartBuildingKit(Part_BuildingKit $part_building_kit) + public function removePartBuildingKit(Part_Set $part_set) { - $this->part_building_kits->remove($part_building_kit); + $this->part_sets->remove($part_set); return $this; } - - /** - * Constructor. - */ - public function __construct() - { - $this->part_building_kits = new \Doctrine\Common\Collections\ArrayCollection(); - } } diff --git a/src/AppBundle/Entity/Part.php b/src/AppBundle/Entity/Rebrickable/Part.php similarity index 54% rename from src/AppBundle/Entity/Part.php rename to src/AppBundle/Entity/Rebrickable/Part.php index feb3288..61cae98 100644 --- a/src/AppBundle/Entity/Part.php +++ b/src/AppBundle/Entity/Rebrickable/Part.php @@ -1,6 +1,6 @@ building_kits = new ArrayCollection(); - } - - /** - * Get id. - * - * @return int - */ - public function getId() - { - return $this->id; + $this->sets = new ArrayCollection(); } /** @@ -124,54 +110,34 @@ class Part return $this->name; } - /** - * @return Model - */ - public function getModel() - { - return $this->model; - } - - /** - * @param Model $model - * - * @return Part - */ - public function setModel($model) - { - $this->model = $model; - - return $this; - } - /** * @return mixed */ - public function getBuildingKits() + public function getSets() { - return $this->building_kits; + return $this->sets; } /** - * @param Part_BuildingKit $building_kit + * @param Part_Set $set * * @return Part */ - public function addBuildingKit(Part_BuildingKit $building_kit) + public function addSet(Part_Set $set) { - $this->building_kits->add($building_kit); + $this->sets->add($set); return $this; } /** - * @param Part_BuildingKit $building_kit + * @param Part_Set $set * * @return Part */ - public function removeBuildingKit($building_kit) + public function removeSet($set) { - $this->building_kits->remove($building_kit); + $this->sets->removeElement($set); return $this; } diff --git a/src/AppBundle/Entity/Part_BuildingKit.php b/src/AppBundle/Entity/Rebrickable/Part_Set.php similarity index 66% rename from src/AppBundle/Entity/Part_BuildingKit.php rename to src/AppBundle/Entity/Rebrickable/Part_Set.php index 3703ef4..60c2233 100644 --- a/src/AppBundle/Entity/Part_BuildingKit.php +++ b/src/AppBundle/Entity/Rebrickable/Part_Set.php @@ -1,16 +1,16 @@ addBuildingKit($this); + $part->addSet($this); $this->part = $part; return $this; } /** - * @return BuildingKit + * @return Set */ - public function getBuildingKit() + public function getSet() { - return $this->building_kit; + return $this->set; } /** - * @param BuildingKit $building_kit + * @param Set $set * - * @return Part_BuildingKit + * @return Part_Set */ - public function setBuildingKit(BuildingKit $building_kit) + public function setSet(Set $set) { - $building_kit->addPart($this); - $this->building_kit = $building_kit; + $set->addPart($this); + $this->set = $set; return $this; } diff --git a/src/AppBundle/Entity/BuildingKit.php b/src/AppBundle/Entity/Rebrickable/Set.php similarity index 57% rename from src/AppBundle/Entity/BuildingKit.php rename to src/AppBundle/Entity/Rebrickable/Set.php index b6ee8ef..38b5939 100644 --- a/src/AppBundle/Entity/BuildingKit.php +++ b/src/AppBundle/Entity/Rebrickable/Set.php @@ -1,32 +1,33 @@ parts = new ArrayCollection(); - $this->keywords = new ArrayCollection(); + $this->themes = new ArrayCollection(); } - /** - * Get id. - * - * @return int - */ - public function getId() - { - return $this->id; - } +// /** +// * Get id. +// * +// * @return int +// */ +// public function getId() +// { +// return $this->id; +// } /** * @return string @@ -95,7 +96,7 @@ class BuildingKit /** * @param string $number * - * @return BuildingKit + * @return Set */ public function setNumber($number) { @@ -109,7 +110,7 @@ class BuildingKit * * @param string $name * - * @return BuildingKit + * @return Set */ public function setName($name) { @@ -133,7 +134,7 @@ class BuildingKit * * @param int $year * - * @return BuildingKit + * @return Set */ public function setYear($year) { @@ -163,7 +164,7 @@ class BuildingKit /** * @param int $partCount * - * @return BuildingKit + * @return Set */ public function setPartCount($partCount) { @@ -183,11 +184,11 @@ class BuildingKit } /** - * @param Part_BuildingKit $part + * @param Part_Set $part * - * @return BuildingKit + * @return Set */ - public function addPart(Part_BuildingKit $part) + public function addPart(Part_Set $part) { $this->parts->add($part); @@ -195,48 +196,14 @@ class BuildingKit } /** - * @param Part_BuildingKit $part + * @param Part_Set $part * - * @return BuildingKit + * @return Set */ - public function removePart(Part_BuildingKit $part) + public function removePart(Part_Set $part) { $this->parts->remove($part); return $this; } - - /** - * Get keywords. - * - * @return Collection - */ - public function getKeywords() - { - return $this->keywords; - } - - /** - * @param Keyword $keyword - * - * @return BuildingKit - */ - public function addKeyword(Keyword $keyword) - { - $this->keywords->add($keyword); - - return $this; - } - - /** - * @param Keyword $keyword - * - * @return BuildingKit - */ - public function removeKeyword(Keyword $keyword) - { - $this->keywords->remove($keyword); - - return $this; - } } diff --git a/src/AppBundle/Entity/Rebrickable/Theme.php b/src/AppBundle/Entity/Rebrickable/Theme.php new file mode 100644 index 0000000..7a6c600 --- /dev/null +++ b/src/AppBundle/Entity/Rebrickable/Theme.php @@ -0,0 +1,125 @@ +id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return Collection + */ + public function getParent() + { + return $this->parent; + } + + /** + * @param Collection $parent + */ + public function setParent($parent) + { + $this->parent = $parent; + } + + /** + * @return mixed + */ + public function getSets() + { + return $this->sets; + } + + /** + * @param Part_Set $set + * + * @return Theme + */ + public function addSet(Part_Set $set) + { + $this->sets->add($set); + + return $this; + } + + /** + * @param Part_Set $set + * + * @return Theme + */ + public function removeSet($set) + { + $this->sets->removeElement($set); + + return $this; + } +} diff --git a/src/AppBundle/Repository/BuildingKitRepository.php b/src/AppBundle/Repository/BuildingKitRepository.php deleted file mode 100644 index 5cf0efe..0000000 --- a/src/AppBundle/Repository/BuildingKitRepository.php +++ /dev/null @@ -1,26 +0,0 @@ -getEntityManager()->createQueryBuilder(); - - $qb->select('building_kit') - ->from('AppBundle:BuildingKit', 'building_kit') - ->innerJoin('building_kit.parts', 'parts') - ->where('parts.part = :id')->setParameter('id', $part->getId()); - - return $qb->getQuery()->getResult(); - } -} diff --git a/src/AppBundle/Repository/CategoryRepository.php b/src/AppBundle/Repository/CategoryRepository.php deleted file mode 100644 index 6b9fe2b..0000000 --- a/src/AppBundle/Repository/CategoryRepository.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Fri, 10 Mar 2017 23:37:23 +0100 Subject: [PATCH 3/3] Add RebrickableLoader Loader to obtain Rebrickable database dump and load it to local database --- app/config/services.yml | 7 +++++-- ...mmand.php => LoadRebrickableDataCommand.php} | 17 ++++++----------- .../{Command => }/Loader/RebrickableLoader.php | 5 ++--- 3 files changed, 13 insertions(+), 16 deletions(-) rename src/AppBundle/Command/{LoadLibraryCommand.php => LoadRebrickableDataCommand.php} (59%) rename src/AppBundle/{Command => }/Loader/RebrickableLoader.php (98%) diff --git a/app/config/services.yml b/app/config/services.yml index 21eb13b..1f94483 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -18,8 +18,11 @@ services: arguments: ['@doctrine.orm.entity_manager', '@manager.brickset','@manager.rebrickable'] loader.rebrickable: - class: AppBundle\Command\Loader\RebrickableLoader - arguments: ['@doctrine.orm.entity_manager', '@manager.rebrickable', '%rebrickable_url%' ] + class: AppBundle\Loader\RebrickableLoader + calls: + - [setArguments, ['@manager.rebrickable', '%rebrickable_url%']] + parent: service.loader + loader.ldraw: class: AppBundle\Command\Loader\LDrawLoader arguments: ['@doctrine.orm.entity_manager', '%kernel.root_dir%/../bin/ldview', '@oneup_flysystem.ldraw_filesystem', '%ldraw_url%'] diff --git a/src/AppBundle/Command/LoadLibraryCommand.php b/src/AppBundle/Command/LoadRebrickableDataCommand.php similarity index 59% rename from src/AppBundle/Command/LoadLibraryCommand.php rename to src/AppBundle/Command/LoadRebrickableDataCommand.php index d96d211..089e4e5 100644 --- a/src/AppBundle/Command/LoadLibraryCommand.php +++ b/src/AppBundle/Command/LoadRebrickableDataCommand.php @@ -3,32 +3,27 @@ namespace AppBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class LoadLibraryCommand extends ContainerAwareCommand +class LoadRebrickableDataCommand extends ContainerAwareCommand { protected function configure() { $this - ->setName('app:load:library') - ->setDescription('Loads LDraw library parts') - ->setHelp('This command allows you to..') - ->addArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library folder'); + ->setName('app:load:rebrickable') + ->setDescription('Loads Rebrickable database') + ->setHelp('This command allows you to..'); } protected function execute(InputInterface $input, OutputInterface $output) { - $ldrawLoader = $this->getContainer()->get('loader.ldraw'); - $ldrawLoader->setOutput($output); - $rebrickableLoader = $this->getContainer()->get('loader.rebrickable'); $rebrickableLoader->setOutput($output); - try { - $ldrawLoader->loadModels($input->getArgument('ldraw')); + //TODO log errors + try { $rebrickableLoader->loadColors(); $rebrickableLoader->loadParts(); diff --git a/src/AppBundle/Command/Loader/RebrickableLoader.php b/src/AppBundle/Loader/RebrickableLoader.php similarity index 98% rename from src/AppBundle/Command/Loader/RebrickableLoader.php rename to src/AppBundle/Loader/RebrickableLoader.php index 2009394..a313bba 100644 --- a/src/AppBundle/Command/Loader/RebrickableLoader.php +++ b/src/AppBundle/Loader/RebrickableLoader.php @@ -1,6 +1,6 @@ em = $em; $this->rebrickableManager = $rebrickableManager; $this->rebrickable_url = $rebrickable_url; }