diff --git a/app/Resources/views/model/detail.html.twig b/app/Resources/views/model/detail.html.twig index 67fe580..a4ea0ac 100644 --- a/app/Resources/views/model/detail.html.twig +++ b/app/Resources/views/model/detail.html.twig @@ -24,7 +24,7 @@ model{{ model.path }} - author{{ model.author }} + author{{ model.author.name }} @@ -59,11 +59,15 @@ -

- Subparts of this model + Related Models

+ +
+ Subparts of this model +
+
{% for subpart in model.subparts %}
@@ -72,9 +76,9 @@ {% endfor %}
-

+

Model is subpart of -
+
{% for subpart in model.parents %} @@ -84,10 +88,9 @@ {% endfor %}
- -

- Related -

+
+ Model pairs with +
{% for subpart in related %} diff --git a/app/config/service/repository.yml b/app/config/service/repository.yml index 080bbdf..afb69d5 100644 --- a/app/config/service/repository.yml +++ b/app/config/service/repository.yml @@ -41,6 +41,13 @@ services: arguments: - AppBundle\Entity\LDraw\Alias + repository.ldraw.author: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine", getRepository] + arguments: + - AppBundle\Entity\LDraw\Author + + repository.rebrickable.category: class: Doctrine\ORM\EntityRepository factory: ["@doctrine", getRepository] diff --git a/src/AppBundle/Entity/LDraw/Author.php b/src/AppBundle/Entity/LDraw/Author.php new file mode 100644 index 0000000..9d87c02 --- /dev/null +++ b/src/AppBundle/Entity/LDraw/Author.php @@ -0,0 +1,34 @@ +models; + } +} diff --git a/src/AppBundle/Entity/LDraw/Model.php b/src/AppBundle/Entity/LDraw/Model.php index f126637..e770b2b 100644 --- a/src/AppBundle/Entity/LDraw/Model.php +++ b/src/AppBundle/Entity/LDraw/Model.php @@ -5,7 +5,6 @@ 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; /** @@ -68,9 +67,9 @@ class Model private $path; /** - * @var string + * @var Author * - * @ORM\Column(type="string", length=255, nullable=true) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\LDraw\Author", cascade={"persist"}, inversedBy="models") */ private $author; @@ -116,7 +115,7 @@ class Model /** * Set author. * - * @param string $author + * @param Author $author * * @return Model */ @@ -130,7 +129,7 @@ class Model /** * Get author. * - * @return string + * @return Author */ public function getAuthor() { @@ -270,7 +269,6 @@ class Model return $this; } - /** * @param Subpart $subpart * diff --git a/src/AppBundle/Repository/LDraw/AuthorRepository.php b/src/AppBundle/Repository/LDraw/AuthorRepository.php new file mode 100644 index 0000000..eca33fb --- /dev/null +++ b/src/AppBundle/Repository/LDraw/AuthorRepository.php @@ -0,0 +1,31 @@ +findOneBy(['name' => $name]); + } + + /** + * Get existing entity or create new. + * + * @param $name + * + * @return Author + */ + public function getOrCreate($name) + { + if (($author = $this->findOneByName($name)) == null) { + $author = new Author(); + $author->setName($name); + } + + return $author; + } +}