1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-20 06:00:08 -07:00

Add Author entity

This commit is contained in:
David Hübner 2017-04-16 21:59:59 +02:00
parent 8e4792a6c4
commit 4742e6eac8
5 changed files with 88 additions and 15 deletions

View File

@ -24,7 +24,7 @@
<th>model</th><td>{{ model.path }}</td>
</tr>
<tr>
<th>author</th><td>{{ model.author }}</td>
<th>author</th><td>{{ model.author.name }}</td>
</tr>
</table>
@ -59,11 +59,15 @@
</div>
<h4 class="ui horizontal divider header">
Subparts of this model
Related Models
</h4>
<h5 class="ui horizontal divider header">
Subparts of this model
</h5>
<div class="ui eight column grid">
{% for subpart in model.subparts %}
<div class="column">
@ -72,9 +76,9 @@
{% endfor %}
</div>
<h4 class="ui horizontal divider header">
<h5 class="ui horizontal divider header">
Model is subpart of
</h4>
</h5>
<div class="ui eight column grid">
{% for subpart in model.parents %}
@ -84,10 +88,9 @@
{% endfor %}
</div>
<h4 class="ui horizontal divider header">
Related
</h4>
<h5 class="ui horizontal divider header">
Model pairs with
</h5>
<div class="ui eight column grid">
{% for subpart in related %}

View File

@ -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]

View File

@ -0,0 +1,34 @@
<?php
namespace AppBundle\Entity\LDraw;
use AppBundle\Entity\Traits\IdentityTrait;
use AppBundle\Entity\Traits\UniqueNameTrait;
use Doctrine\ORM\Mapping as ORM;
/**
* Author.
*
* @ORM\Table(name="ldraw_author")
* @ORM\Entity(repositoryClass="AppBundle\Repository\LDraw\AuthorRepository")
*/
class Author
{
use IdentityTrait;
use UniqueNameTrait;
/**
* @var Author
*
* @ORM\OneToMany(targetEntity="AppBundle\Entity\LDraw\Model", mappedBy="author")
*/
private $models;
/**
* @return Author
*/
public function getModels()
{
return $this->models;
}
}

View File

@ -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
*

View File

@ -0,0 +1,31 @@
<?php
namespace AppBundle\Repository\LDraw;
use AppBundle\Entity\LDraw\Author;
use AppBundle\Repository\BaseRepository;
class AuthorRepository extends BaseRepository
{
public function findOneByName($name)
{
return $this->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;
}
}