mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 20:30:09 -07:00
Update LDraw entites structure
Uprate LDraw Entity structure to store information about model alias ids and known subparts of model
This commit is contained in:
parent
6421ed66f2
commit
775af7c23b
@ -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"
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
40
src/AppBundle/Entity/LDraw/Alias.php
Normal file
40
src/AppBundle/Entity/LDraw/Alias.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Entity\LDraw;
|
||||
|
||||
use AppBundle\Entity\Traits\NumberTrait;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @ORM\Table(name="ldraw_alias")
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\LDraw\AliasRepository")
|
||||
*/
|
||||
class Alias
|
||||
{
|
||||
use NumberTrait;
|
||||
|
||||
/**
|
||||
* @var Model
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Model", inversedBy="aliases", cascade={"persist"})
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @return Model
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
*/
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,297 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Entity\LDraw;
|
||||
|
||||
use AppBundle\Entity\Traits\NumberTrait;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Part.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\LDraw\PartRepository")
|
||||
* @ORM\Table(name="ldraw_part")
|
||||
*/
|
||||
class Part
|
||||
{
|
||||
use NumberTrait;
|
||||
|
||||
/**
|
||||
* @var Type
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Type", inversedBy="parts", cascade={"persist"})
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Category
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Category", inversedBy="parts", cascade={"persist"})
|
||||
*/
|
||||
private $category;
|
||||
|
||||
/**
|
||||
* @var Part_Relation
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Part_Relation", mappedBy="parent")
|
||||
*/
|
||||
private $relationsTo;
|
||||
|
||||
/**
|
||||
* @var Part_Relation
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Part_Relation", mappedBy="child")
|
||||
*/
|
||||
private $relationsFrom;
|
||||
|
||||
/**
|
||||
* @var Model
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Model", cascade={"persist"})
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\LDraw\Keyword", inversedBy="parts", cascade={"persist"})
|
||||
*/
|
||||
private $keywords;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Entity\LDraw;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Part.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\LDraw\Part_RelationRepository")
|
||||
* @ORM\Table(name="ldraw_part_relation")
|
||||
*/
|
||||
class Part_Relation
|
||||
{
|
||||
/**
|
||||
* @var Part
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Part", inversedBy="relationsTo", cascade={"persist"})
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var Part
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Part", inversedBy="relationsFrom", cascade={"persist"} )
|
||||
*/
|
||||
private $child;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* @return Part
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
97
src/AppBundle/Entity/LDraw/Subpart.php
Normal file
97
src/AppBundle/Entity/LDraw/Subpart.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Entity\LDraw;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Subpart.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\LDraw\SubpartRepository")
|
||||
* @ORM\Table(name="ldraw_subpart")
|
||||
*/
|
||||
class Subpart
|
||||
{
|
||||
/**
|
||||
* @var Model
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Model", inversedBy="subparts", cascade={"persist"})
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var Model
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Model", inversedBy="parents", cascade={"persist"} )
|
||||
*/
|
||||
private $subpart;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* @return Model
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
40
src/AppBundle/Manager/LDraw/AliasManager.php
Normal file
40
src/AppBundle/Manager/LDraw/AliasManager.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\AliasRepository;
|
||||
|
||||
class AliasManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* AliasManager constructor.
|
||||
*
|
||||
* @param AliasRepository $repository
|
||||
*/
|
||||
public function __construct(AliasRepository $repository)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Part;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\CategoryRepository;
|
||||
use AppBundle\Repository\LDraw\PartRepository;
|
||||
|
||||
class PartManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* PartManager constructor.
|
||||
*
|
||||
* @param CategoryRepository $repository
|
||||
*/
|
||||
public function __construct(PartRepository $repository)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Part_Relation;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\Part_RelationRepository;
|
||||
|
||||
class Part_RelationManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* Part_RelationManager constructor.
|
||||
*
|
||||
* @param Part_RelationRepository $repository
|
||||
*/
|
||||
public function __construct(Part_RelationRepository $repository)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
42
src/AppBundle/Manager/LDraw/SubpartManager.php
Normal file
42
src/AppBundle/Manager/LDraw/SubpartManager.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Subpart;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\SubpartRepository;
|
||||
|
||||
class SubpartManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* SubpartManager constructor.
|
||||
*
|
||||
* @param SubpartRepository $repository
|
||||
*/
|
||||
public function __construct(SubpartRepository $repository)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
99
src/AppBundle/Manager/LDrawManager.php
Normal file
99
src/AppBundle/Manager/LDrawManager.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager;
|
||||
|
||||
use AppBundle\Manager\LDraw\AliasManager;
|
||||
use AppBundle\Manager\LDraw\CategoryManager;
|
||||
use AppBundle\Manager\LDraw\KeywordManager;
|
||||
use AppBundle\Manager\LDraw\ModelManager;
|
||||
use AppBundle\Manager\LDraw\SubpartManager;
|
||||
use AppBundle\Manager\LDraw\TypeManager;
|
||||
|
||||
class LDrawManager
|
||||
{
|
||||
/** @var CategoryManager */
|
||||
private $categoryManager;
|
||||
|
||||
/** @var KeywordManager */
|
||||
private $keywordManager;
|
||||
|
||||
/** @var TypeManager */
|
||||
private $typeManager;
|
||||
|
||||
/** @var SubpartManager */
|
||||
private $subpartManager;
|
||||
|
||||
/** @var ModelManager */
|
||||
private $modelManager;
|
||||
|
||||
/** @var AliasManager */
|
||||
private $aliasManager;
|
||||
|
||||
/**
|
||||
* LDrawService constructor.
|
||||
*
|
||||
* @param CategoryManager $categoryManager
|
||||
* @param KeywordManager $keywordManager
|
||||
* @param TypeManager $typeManager
|
||||
* @param SubpartManager $subpartManager
|
||||
* @param ModelManager $modelManager
|
||||
* @param AliasManager $aliasManager
|
||||
*/
|
||||
public function __construct(CategoryManager $categoryManager, KeywordManager $keywordManager, TypeManager $typeManager, SubpartManager $subpartManager, ModelManager $modelManager, AliasManager $aliasManager)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
9
src/AppBundle/Repository/LDraw/AliasRepository.php
Normal file
9
src/AppBundle/Repository/LDraw/AliasRepository.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class AliasRepository extends BaseRepository
|
||||
{
|
||||
}
|
@ -2,8 +2,66 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Type;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class ModelRepository extends BaseRepository
|
||||
{
|
||||
public function findAllByType($type)
|
||||
{
|
||||
$queryBuilder = $this->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();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class Part_RelationRepository extends BaseRepository
|
||||
{
|
||||
public function findByForeignKeys($parent, $child, $relationType)
|
||||
{
|
||||
return $this->find(['parent' => $parent, 'child' => $child, 'type' => $relationType]);
|
||||
}
|
||||
}
|
13
src/AppBundle/Repository/LDraw/SubpartRepository.php
Normal file
13
src/AppBundle/Repository/LDraw/SubpartRepository.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class SubpartRepository extends BaseRepository
|
||||
{
|
||||
public function findOneByKeys($parent, $child)
|
||||
{
|
||||
return $this->find(['parent' => $parent, 'subpart' => $child]);
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Service;
|
||||
|
||||
use AppBundle\Manager\LDraw\CategoryManager;
|
||||
use AppBundle\Manager\LDraw\KeywordManager;
|
||||
use AppBundle\Manager\LDraw\Part_RelationManager;
|
||||
use AppBundle\Manager\LDraw\PartManager;
|
||||
use AppBundle\Manager\LDraw\TypeManager;
|
||||
|
||||
class LDrawService
|
||||
{
|
||||
/** @var CategoryManager */
|
||||
private $categoryManager;
|
||||
|
||||
/** @var KeywordManager */
|
||||
private $keywordManager;
|
||||
|
||||
/** @var TypeManager */
|
||||
private $typeManager;
|
||||
|
||||
/** @var PartManager */
|
||||
private $partManager;
|
||||
|
||||
/** @var Part_RelationManager */
|
||||
private $partRelationManager;
|
||||
|
||||
/**
|
||||
* LDrawService constructor.
|
||||
*
|
||||
* @param CategoryManager $categoryManager
|
||||
* @param KeywordManager $keywordManager
|
||||
* @param TypeManager $typeManager
|
||||
* @param PartManager $partManager
|
||||
* @param Part_RelationManager $partRelationManager
|
||||
*/
|
||||
public function __construct(CategoryManager $categoryManager, KeywordManager $keywordManager, TypeManager $typeManager, PartManager $partManager, Part_RelationManager $partRelationManager)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user