From 775af7c23bf24d838e8fc7158da3d9259540a27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Wed, 5 Apr 2017 17:04:54 +0200 Subject: [PATCH] Update LDraw entites structure Uprate LDraw Entity structure to store information about model alias ids and known subparts of model --- app/config/service/manager.yml | 17 +- app/config/service/repository.yml | 10 +- app/config/service/service.yml | 9 +- src/AppBundle/Entity/LDraw/Alias.php | 40 +++ src/AppBundle/Entity/LDraw/Category.php | 24 +- src/AppBundle/Entity/LDraw/Keyword.php | 22 +- src/AppBundle/Entity/LDraw/Model.php | 226 ++++++++++++- src/AppBundle/Entity/LDraw/Part.php | 297 ------------------ src/AppBundle/Entity/LDraw/Part_Relation.php | 125 -------- src/AppBundle/Entity/LDraw/Subpart.php | 97 ++++++ src/AppBundle/Entity/LDraw/Type.php | 24 +- src/AppBundle/Manager/LDraw/AliasManager.php | 40 +++ src/AppBundle/Manager/LDraw/ModelManager.php | 12 +- src/AppBundle/Manager/LDraw/PartManager.php | 38 --- .../Manager/LDraw/Part_RelationManager.php | 41 --- .../Manager/LDraw/SubpartManager.php | 42 +++ src/AppBundle/Manager/LDrawManager.php | 99 ++++++ .../Repository/LDraw/AliasRepository.php | 9 + .../Repository/LDraw/ModelRepository.php | 58 ++++ .../LDraw/Part_RelationRepository.php | 13 - .../Repository/LDraw/SubpartRepository.php | 13 + src/AppBundle/Service/LDrawService.php | 85 ----- 22 files changed, 677 insertions(+), 664 deletions(-) create mode 100644 src/AppBundle/Entity/LDraw/Alias.php delete mode 100644 src/AppBundle/Entity/LDraw/Part.php delete mode 100644 src/AppBundle/Entity/LDraw/Part_Relation.php create mode 100644 src/AppBundle/Entity/LDraw/Subpart.php create mode 100644 src/AppBundle/Manager/LDraw/AliasManager.php delete mode 100644 src/AppBundle/Manager/LDraw/PartManager.php delete mode 100644 src/AppBundle/Manager/LDraw/Part_RelationManager.php create mode 100644 src/AppBundle/Manager/LDraw/SubpartManager.php create mode 100644 src/AppBundle/Manager/LDrawManager.php create mode 100644 src/AppBundle/Repository/LDraw/AliasRepository.php delete mode 100644 src/AppBundle/Repository/LDraw/Part_RelationRepository.php create mode 100644 src/AppBundle/Repository/LDraw/SubpartRepository.php delete mode 100644 src/AppBundle/Service/LDrawService.php diff --git a/app/config/service/manager.yml b/app/config/service/manager.yml index 2a99018..1490a07 100644 --- a/app/config/service/manager.yml +++ b/app/config/service/manager.yml @@ -11,13 +11,18 @@ services: class: AppBundle\Manager\LDraw\TypeManager arguments: - "@repository.ldraw.type" - manager.ldraw.part: - class: AppBundle\Manager\LDraw\PartManager + manager.ldraw.subpart: + class: AppBundle\Manager\LDraw\SubpartManager arguments: - - "@repository.ldraw.part" - manager.ldraw.partRelation: - class: AppBundle\Manager\LDraw\Part_RelationManager + - "@repository.ldraw.subpart" + manager.ldraw.model: + class: AppBundle\Manager\LDraw\ModelManager arguments: - - "@repository.ldraw.partRelation" + - "@repository.ldraw.model" + manager.ldraw.alias: + class: AppBundle\Manager\LDraw\AliasManager + arguments: + - "@repository.ldraw.alias" + diff --git a/app/config/service/repository.yml b/app/config/service/repository.yml index d3fa1a6..080bbdf 100644 --- a/app/config/service/repository.yml +++ b/app/config/service/repository.yml @@ -29,11 +29,17 @@ services: arguments: - AppBundle\Entity\LDraw\Type - repository.ldraw.partRelation: + repository.ldraw.subpart: class: Doctrine\ORM\EntityRepository factory: ["@doctrine", getRepository] arguments: - - AppBundle\Entity\LDraw\Part_Relation + - AppBundle\Entity\LDraw\Subpart + + repository.ldraw.alias: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine", getRepository] + arguments: + - AppBundle\Entity\LDraw\Alias repository.rebrickable.category: class: Doctrine\ORM\EntityRepository diff --git a/app/config/service/service.yml b/app/config/service/service.yml index 2d96f56..1db4e3f 100644 --- a/app/config/service/service.yml +++ b/app/config/service/service.yml @@ -3,14 +3,15 @@ services: class: AppBundle\Service\CollectionService arguments: ['@doctrine', '@manager.brickset','@manager.rebrickable'] - service.ldraw: - class: AppBundle\Service\LDrawService + manager.ldraw: + class: AppBundle\Manager\LDrawManager arguments: - '@manager.ldraw.category' - '@manager.ldraw.keyword' - '@manager.ldraw.type' - - '@manager.ldraw.part' - - '@manager.ldraw.partRelation' + - '@manager.ldraw.subpart' + - '@manager.ldraw.model' + - '@manager.ldraw.alias' app.form.filter_set: class: AppBundle\Form\FilterSetType diff --git a/src/AppBundle/Entity/LDraw/Alias.php b/src/AppBundle/Entity/LDraw/Alias.php new file mode 100644 index 0000000..3be0904 --- /dev/null +++ b/src/AppBundle/Entity/LDraw/Alias.php @@ -0,0 +1,40 @@ +model; + } + + /** + * @param Model $model + */ + public function setModel($model) + { + $this->model = $model; + } +} diff --git a/src/AppBundle/Entity/LDraw/Category.php b/src/AppBundle/Entity/LDraw/Category.php index 607547c..549c804 100644 --- a/src/AppBundle/Entity/LDraw/Category.php +++ b/src/AppBundle/Entity/LDraw/Category.php @@ -22,48 +22,48 @@ class Category /** * @var Collection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Part", mappedBy="category") + * @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Model", mappedBy="category") */ - private $parts; + private $models; /** * BuildingKit constructor. */ public function __construct() { - $this->parts = new ArrayCollection(); + $this->models = new ArrayCollection(); } /** - * Get parts. + * Get models. * * @return ArrayCollection */ - public function getParts() + public function getModels() { - return $this->parts; + return $this->models; } /** - * @param Part $part + * @param Model $model * * @return Category */ - public function addPart(Part $part) + public function addModel(Model $model) { - $this->parts->add($part); + $this->models->add($model); return $this; } /** - * @param Part $part + * @param Model $model * * @return Category */ - public function removePart(Part $part) + public function removeModel(Model $model) { - $this->parts->remove($part); + $this->models->remove($model); return $this; } diff --git a/src/AppBundle/Entity/LDraw/Keyword.php b/src/AppBundle/Entity/LDraw/Keyword.php index 7db27ba..1a57071 100644 --- a/src/AppBundle/Entity/LDraw/Keyword.php +++ b/src/AppBundle/Entity/LDraw/Keyword.php @@ -21,16 +21,16 @@ class Keyword /** * @var ArrayCollection * - * @ORM\ManyToMany(targetEntity="AppBundle\Entity\LDraw\Part", mappedBy="keywords") + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\LDraw\Model", mappedBy="keywords") */ - private $parts; + private $models; /** * Keyword constructor. */ public function __construct() { - $this->parts = new ArrayCollection(); + $this->models = new ArrayCollection(); } /** @@ -38,31 +38,31 @@ class Keyword * * @return ArrayCollection */ - public function getParts() + public function getModels() { - return $this->parts; + return $this->models; } /** - * @param Part $part + * @param Model $part * * @return Keyword */ - public function addPart(Part $part) + public function addModel(Model $part) { - $this->parts->add($part); + $this->models->add($part); return $this; } /** - * @param Part $part + * @param Model $part * * @return Keyword */ - public function removeModel(Part $part) + public function removeModel(Model $part) { - $this->parts->removeElement($part); + $this->models->removeElement($part); return $this; } diff --git a/src/AppBundle/Entity/LDraw/Model.php b/src/AppBundle/Entity/LDraw/Model.php index e52482c..fb7e90a 100644 --- a/src/AppBundle/Entity/LDraw/Model.php +++ b/src/AppBundle/Entity/LDraw/Model.php @@ -3,6 +3,7 @@ namespace AppBundle\Entity\LDraw; use AppBundle\Entity\Traits\NumberTrait; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -16,12 +17,61 @@ class Model { use NumberTrait; + /** + * @var Type + * + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Type", inversedBy="models", cascade={"persist"}) + */ + private $type; + /** * @var string * - * @ORM\Column(type="string", length=255, nullable=false) + * @ORM\Column(type="string", length=255, nullable=true) */ - private $file; + private $name; + + /** + * @var Category + * + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Category", inversedBy="models", cascade={"persist"}) + */ + private $category; + + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Alias", mappedBy="model", cascade={"persist"}) + */ + private $aliases; + + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Subpart", mappedBy="parent") + */ + private $subparts; + + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Subpart", mappedBy="subpart") + */ + private $parents; + + /** + * @var Collection + * + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\LDraw\Keyword", inversedBy="models", cascade={"persist"}) + */ + private $keywords; + + /** + * @var string + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $path; /** * @var string @@ -37,31 +87,36 @@ class Model */ private $modified; -// /** -// * @var Collection -// * -// * @ORM\OneToMany(targetEntity="AppBundle\Entity\Part", mappedBy="model") -// */ -// private $parts; + /** + * @var ArrayCollection + * + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Rebrickable\Part", mappedBy="model") + */ + private $parts; + + public function __construct() + { + $this->keywords = new ArrayCollection(); + $this->subparts = new ArrayCollection(); + $this->parents = new ArrayCollection(); + $this->aliases = new ArrayCollection(); + $this->parts = new ArrayCollection(); + } /** * @return string */ - public function getFile() + public function getPath() { - return $this->file; + return $this->path; } /** - * @param string $file - * - * @return Model + * @param string $path */ - public function setFile($file) + public function setPath($path) { - $this->file = $file; - - return $this; + $this->path = $path; } /** @@ -107,4 +162,141 @@ class Model return $this; } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return Category + */ + public function getCategory() + { + return $this->category; + } + + /** + * @param Category $category + * + * @return Model + */ + public function setCategory(Category $category) + { + $this->category = $category; + + return $this; + } + + /** + * @return Collection + */ + public function getSubparts() + { + return $this->subparts; + } + + /** + * @return ArrayCollection + */ + public function getParents() + { + return $this->parents; + } + + /** + * Get keywords. + * + * @return Collection + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param Keyword $keyword + * + * @return Model + */ + public function addKeyword(Keyword $keyword) + { + if (!$this->keywords->contains($keyword)) { + $this->keywords->add($keyword); + $keyword->addModel($this); + } + + return $this; + } + + /** + * @param Keyword $keyword + * + * @return Model + */ + public function removeKeyword(Keyword $keyword) + { + $this->keywords->removeElement($keyword); + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getAliases() + { + return $this->aliases; + } + + /** + * @param Alias $alias + * + * @return $this + */ + public function addAlias($alias) + { + if (!$this->aliases->contains($alias)) { + $this->aliases->add($alias); + } + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getParts() + { + return $this->parts; + } } diff --git a/src/AppBundle/Entity/LDraw/Part.php b/src/AppBundle/Entity/LDraw/Part.php deleted file mode 100644 index 39abf69..0000000 --- a/src/AppBundle/Entity/LDraw/Part.php +++ /dev/null @@ -1,297 +0,0 @@ -keywords = new ArrayCollection(); - $this->relationsTo = new ArrayCollection(); - $this->relationsFrom = new ArrayCollection(); - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * @param string $type - */ - public function setType($type) - { - $this->type = $type; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * @return Category - */ - public function getCategory() - { - return $this->category; - } - - /** - * @param Collection $category - * - * @return Part - */ - public function setCategory(Category $category) - { - $this->category = $category; - - return $this; - } - - /** - * @return Part_Relation - */ - public function getRelationsTo() - { - return $this->relationsTo; - } - - /** - * @param Part_Relation $relationsTo - */ - public function setRelationsTo($relationsTo) - { - $this->relationsTo = $relationsTo; - } - - /** - * @return Part_Relation - */ - public function getRelationsFrom() - { - return $this->relationsFrom; - } - - /** - * @param Part_Relation $relationsFrom - */ - public function setRelationsFrom($relationsFrom) - { - $this->relationsFrom = $relationsFrom; - } - - /** - * @return Model - */ - public function getModel() - { - if (!$this->model) { - if ($this->getPrintOf()) { - return $this->getPrintOf()->getModel(); - } elseif ($this->getAliasOf()) { - return $this->getAliasOf()->getModel(); - } - - return null; - } - - return $this->model; - } - - /** - * @param Model $model - * - * @return Part - */ - public function setModel($model) - { - $this->model = $model; - - return $this; - } - - /** - * Get keywords. - * - * @return Collection - */ - public function getKeywords() - { - return $this->keywords; - } - - /** - * @param Keyword $keyword - * - * @return Part - */ - public function addKeyword(Keyword $keyword) - { - if (!$this->keywords->contains($keyword)) { - $this->keywords->add($keyword); - $keyword->addPart($this); - } - - return $this; - } - - /** - * @param Keyword $keyword - * - * @return Part - */ - public function removeKeyword(Keyword $keyword) - { - $this->keywords->removeElement($keyword); - - return $this; - } - - private function getRelationOf($type) - { - $criteria = new Criteria(); - $criteria->where(Criteria::expr()->eq('type', $type)); - - $relations = $this->relationsFrom->matching($criteria); - - $array = new ArrayCollection(); - foreach ($relations as $relation) { - $array->add($relation->getParent()); - } - - return $array; - } - - private function getRelations($type) - { - $criteria = new Criteria(); - $criteria->where(Criteria::expr()->eq('type', $type)); - - $relations = $this->relationsTo->matching($criteria); - - $array = new ArrayCollection(); - foreach ($relations as $relation) { - $array->add($relation->getChild()); - } - - return $array; - } - - public function getPrintOf() - { - $parents = $this->getRelationOf('Print'); - if (count($parents) > 0) { - return $parents->first(); - } - - return null; - } - - public function getPrints() - { - return $this->getRelations('Print'); - } - - public function getSubpartOf() - { - return $this->getRelationOf('Subpart'); - } - - public function getSubparts() - { - return $this->getRelations('Subpart'); - } - - public function getAliasOf() - { - $parents = $this->getRelationOf('Alias'); - if (count($parents) > 0) { - return $parents->first(); - } - - return null; - } - - public function getAliases() - { - return $this->getRelations('Alias'); - } -} diff --git a/src/AppBundle/Entity/LDraw/Part_Relation.php b/src/AppBundle/Entity/LDraw/Part_Relation.php deleted file mode 100644 index 3943ff5..0000000 --- a/src/AppBundle/Entity/LDraw/Part_Relation.php +++ /dev/null @@ -1,125 +0,0 @@ -parent; - } - - /** - * @param Part $parent - * - * @return Part_Relation - */ - public function setParent($parent) - { - $this->parent = $parent; - - return $this; - } - - /** - * @return Part - */ - public function getChild() - { - return $this->child; - } - - /** - * @param Part $child - * - * @return Part_Relation - */ - public function setChild($child) - { - $this->child = $child; - - return $this; - } - - /** - * @return int - */ - public function getCount() - { - return $this->count; - } - - /** - * @param int $count - * - * @return Part_Relation - */ - public function setCount($count) - { - $this->count = $count; - - return $this; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * @param string $type - * - * @return Part_Relation - */ - public function setType($type) - { - $this->type = $type; - - return $this; - } -} diff --git a/src/AppBundle/Entity/LDraw/Subpart.php b/src/AppBundle/Entity/LDraw/Subpart.php new file mode 100644 index 0000000..71b42b0 --- /dev/null +++ b/src/AppBundle/Entity/LDraw/Subpart.php @@ -0,0 +1,97 @@ +parent; + } + + /** + * @param Model $parent + * + * @return Subpart + */ + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } + + /** + * @return Model + */ + public function getSubpart() + { + return $this->subpart; + } + + /** + * @param Model $subpart + * + * @return Subpart + */ + public function setSubpart($subpart) + { + $this->subpart = $subpart; + + return $this; + } + + /** + * @return int + */ + public function getCount() + { + return $this->count; + } + + /** + * @param int $count + * + * @return Subpart + */ + public function setCount($count) + { + $this->count = $count; + + return $this; + } +} diff --git a/src/AppBundle/Entity/LDraw/Type.php b/src/AppBundle/Entity/LDraw/Type.php index fe49c7a..c33ea34 100644 --- a/src/AppBundle/Entity/LDraw/Type.php +++ b/src/AppBundle/Entity/LDraw/Type.php @@ -27,16 +27,16 @@ class Type /** * @var Collection * - * @ORM\OneToMany(targetEntity="Part", mappedBy="type") + * @ORM\OneToMany(targetEntity="Model", mappedBy="type") */ - private $parts; + private $models; /** * BuildingKit constructor. */ public function __construct() { - $this->parts = new ArrayCollection(); + $this->models = new ArrayCollection(); } /** @@ -56,35 +56,35 @@ class Type } /** - * Get parts. + * Get models. * * @return ArrayCollection */ - public function getParts() + public function getModels() { - return $this->parts; + return $this->models; } /** - * @param Part $part + * @param Model $model * * @return Type */ - public function addPart(Part $part) + public function addModel(Model $model) { - $this->parts->add($part); + $this->models->add($model); return $this; } /** - * @param Part $part + * @param Model $model * * @return Type */ - public function removePart(Part $part) + public function removeModel(Model $model) { - $this->parts->remove($part); + $this->models->remove($model); return $this; } diff --git a/src/AppBundle/Manager/LDraw/AliasManager.php b/src/AppBundle/Manager/LDraw/AliasManager.php new file mode 100644 index 0000000..fa50d6d --- /dev/null +++ b/src/AppBundle/Manager/LDraw/AliasManager.php @@ -0,0 +1,40 @@ +repository = $repository; + } + + /** + * Create new Alias entity. + * + * @param $number + * @param Model $model + * + * @return Alias + */ + public function create($number, $model) + { + if (($alias = $this->repository->findOneBy(['number' => $number, 'model' => $model])) == null) { + $alias = new Alias(); + $alias->setModel($model); + $alias->setNumber($number); + } + + return $alias; + } +} diff --git a/src/AppBundle/Manager/LDraw/ModelManager.php b/src/AppBundle/Manager/LDraw/ModelManager.php index 1d1e6cc..3c3f8fd 100644 --- a/src/AppBundle/Manager/LDraw/ModelManager.php +++ b/src/AppBundle/Manager/LDraw/ModelManager.php @@ -27,11 +27,21 @@ class ModelManager extends BaseManager */ public function create($number) { - if (($model = $this->repository->find($number)) == null) { + if (($model = $this->repository->findOneBy(['number' => $number])) == null) { $model = new Model(); $model->setNumber($number); } return $model; } + + public function findByNumber($number) + { + return $this->repository->findOneByNumber($number); + } + + public function findByName($name) + { + return $this->repository->findOneBy(['name' => $name]); + } } diff --git a/src/AppBundle/Manager/LDraw/PartManager.php b/src/AppBundle/Manager/LDraw/PartManager.php deleted file mode 100644 index a25e8ac..0000000 --- a/src/AppBundle/Manager/LDraw/PartManager.php +++ /dev/null @@ -1,38 +0,0 @@ -repository = $repository; - } - - /** - * Create new Part entity with $number or retrieve one. - * - * @param $number - * - * @return Part - */ - public function create($number) - { - if (($part = $this->repository->find($number)) == null) { - $part = new Part(); - $part->setNumber($number); - } - - return $part; - } -} diff --git a/src/AppBundle/Manager/LDraw/Part_RelationManager.php b/src/AppBundle/Manager/LDraw/Part_RelationManager.php deleted file mode 100644 index d6e9fbd..0000000 --- a/src/AppBundle/Manager/LDraw/Part_RelationManager.php +++ /dev/null @@ -1,41 +0,0 @@ -repository = $repository; - } - - /** - * Create new Keyword entity with $name or retrieve one. - * - * @param $name - * - * @return Part_Relation - */ - public function create($parent, $child, $relationType) - { - if (($partRelation = $this->repository->findByForeignKeys($parent, $child, $relationType)) == null) { - $partRelation = new Part_Relation(); - $partRelation - ->setParent($parent) - ->setChild($child) - ->setCount(0) - ->setType($relationType); - } - - return $partRelation; - } -} diff --git a/src/AppBundle/Manager/LDraw/SubpartManager.php b/src/AppBundle/Manager/LDraw/SubpartManager.php new file mode 100644 index 0000000..3b74da3 --- /dev/null +++ b/src/AppBundle/Manager/LDraw/SubpartManager.php @@ -0,0 +1,42 @@ +repository = $repository; + } + + /** + * Create new Subpart relation entity or retrieve one by foreign keys. + * + * @param $name + * + * @return Subpart + */ + public function create($parent, $child) + { + if (($subpart = $this->repository->findOneByKeys($parent, $child))) { + $subpart->setCount($subpart->getCount() + 1); + } else { + $subpart = new Subpart(); + $subpart + ->setParent($parent) + ->setSubpart($child) + ->setCount(1); + } + + return $subpart; + } +} diff --git a/src/AppBundle/Manager/LDrawManager.php b/src/AppBundle/Manager/LDrawManager.php new file mode 100644 index 0000000..e452f93 --- /dev/null +++ b/src/AppBundle/Manager/LDrawManager.php @@ -0,0 +1,99 @@ +categoryManager = $categoryManager; + $this->keywordManager = $keywordManager; + $this->typeManager = $typeManager; + $this->subpartManager = $subpartManager; + $this->modelManager = $modelManager; + $this->aliasManager = $aliasManager; + } + + /** + * @return mixed + */ + public function getCategoryManager() + { + return $this->categoryManager; + } + + /** + * @return mixed + */ + public function getKeywordManager() + { + return $this->keywordManager; + } + + /** + * @return TypeManager + */ + public function getTypeManager() + { + return $this->typeManager; + } + + /** + * @return SubpartManager + */ + public function getSubpartManager() + { + return $this->subpartManager; + } + + /** + * @return ModelManager + */ + public function getModelManager() + { + return $this->modelManager; + } + + /** + * @return AliasManager + */ + public function getAliasManager() + { + return $this->aliasManager; + } +} diff --git a/src/AppBundle/Repository/LDraw/AliasRepository.php b/src/AppBundle/Repository/LDraw/AliasRepository.php new file mode 100644 index 0000000..18497f4 --- /dev/null +++ b/src/AppBundle/Repository/LDraw/AliasRepository.php @@ -0,0 +1,9 @@ +createQueryBuilder('model') + ->join(Type::class, 'type', Join::LEFT_JOIN, 'model.type = :type') + ->setParameter('type', $type); + + return $queryBuilder->getQuery(); + } + + public function findAllByCategory($category) + { + $queryBuilder = $this->createQueryBuilder('model') + ->join(Type::class, 'type', Join::LEFT_JOIN, 'model.category = :category') + ->setParameter('category', $category); + + return $queryBuilder->getQuery(); + } + + public function findOneByNumber($number) + { + $model = $this->createQueryBuilder('model') + ->where('model.number LIKE :number') + ->setParameter('number', $number) + ->getQuery()->getOneOrNullResult(); + + if (!$model) { + $model = $this->createQueryBuilder('model') + ->leftJoin(Alias::class, 'alias', JOIN::WITH, 'alias.model = model') + ->where('alias.number LIKE :number') + ->setParameter('number', $number) + ->getQuery()->getOneOrNullResult(); + } + + return $model; + } + + public function findAllBySetNumber($number) + { + $queryBuilder = $this->createQueryBuilder('model'); + + $queryBuilder + ->join(Part::class, 'part', JOIN::WITH, 'part.model = model') + ->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'part.number = inventory_part.part') + ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory.id') + ->join(Set::class, 's', Join::WITH, 'inventory.set = s.number') + ->where('s.number LIKE :number') + ->setParameter('number', $number) + ->distinct(true); + + return $queryBuilder->getQuery()->getResult(); + } } diff --git a/src/AppBundle/Repository/LDraw/Part_RelationRepository.php b/src/AppBundle/Repository/LDraw/Part_RelationRepository.php deleted file mode 100644 index bb3f6b3..0000000 --- a/src/AppBundle/Repository/LDraw/Part_RelationRepository.php +++ /dev/null @@ -1,13 +0,0 @@ -find(['parent' => $parent, 'child' => $child, 'type' => $relationType]); - } -} diff --git a/src/AppBundle/Repository/LDraw/SubpartRepository.php b/src/AppBundle/Repository/LDraw/SubpartRepository.php new file mode 100644 index 0000000..3674f50 --- /dev/null +++ b/src/AppBundle/Repository/LDraw/SubpartRepository.php @@ -0,0 +1,13 @@ +find(['parent' => $parent, 'subpart' => $child]); + } +} diff --git a/src/AppBundle/Service/LDrawService.php b/src/AppBundle/Service/LDrawService.php deleted file mode 100644 index ca7d848..0000000 --- a/src/AppBundle/Service/LDrawService.php +++ /dev/null @@ -1,85 +0,0 @@ -categoryManager = $categoryManager; - $this->keywordManager = $keywordManager; - $this->typeManager = $typeManager; - $this->partManager = $partManager; - $this->partRelationManager = $partRelationManager; - } - - /** - * @return mixed - */ - public function getCategoryManager() - { - return $this->categoryManager; - } - - /** - * @return mixed - */ - public function getKeywordManager() - { - return $this->keywordManager; - } - - /** - * @return TypeManager - */ - public function getTypeManager() - { - return $this->typeManager; - } - - /** - * @return PartManager - */ - public function getPartManager() - { - return $this->partManager; - } - - /** - * @return Part_RelationManager - */ - public function getPartRelationManager() - { - return $this->partRelationManager; - } -}