M config/packages/doctrine/Tag.orm.xml +0 -3
@@ 19,8 19,5 @@
<field name="createdAt" column="created_at" type="datetime" />
<field name="updatedAt" column="updated_at" type="datetime" />
-
- <many-to-many field="articles" target-entity="Article">
- </many-to-many>
</entity>
</doctrine-mapping>
M src/Entity/Article.php +20 -55
@@ 2,28 2,34 @@
namespace App\Entity;
+use Doctrine\Common\Collections\ArrayCollection;
use Ramsey\Uuid\Uuid;
class Article
{
private $id;
- private $title;
- private $teasing;
- private $content;
- private $tags;
+ public $title;
+ public $teasing;
+ public $content;
+ public $tags;
private $createdAt;
private $updatedAt;
- public function __construct(
- string $title,
- string $teasing,
- string $content,
- ?array $tags = []
- ) {
- $this->title = $title;
- $this->teasing = $teasing;
- $this->content = $content;
- $this->tags = $tags;
+ public function __construct()
+ {
+ $this->tags = new ArrayCollection();
+ }
+
+ public function addTag(Tag $tag): void
+ {
+ $tag->product = $this;
+ $this->tags->add($tag);
+ }
+
+ public function removeTag(Tag $tag): void
+ {
+ $tag->product = null;
+ $this->tags->removeElement($tag);
}
public function onPrePersist()
@@ 38,47 44,6 @@ class Article
return $this->id;
}
- public function getTitle(): ?string
- {
- return $this->title;
- }
-
- public function setTitle(string $title): self
- {
- $this->title = $title;
-
- return $this;
- }
-
- public function getTeasing(): ?string
- {
- return $this->teasing;
- }
-
- public function setTeasing(string $teasing): self
- {
- $this->teasing = $teasing;
-
- return $this;
- }
-
- public function getContent(): ?string
- {
- return $this->content;
- }
-
- public function setContent(string $teasing): self
- {
- $this->content = $teasing;
-
- return $this;
- }
-
- public function getTags(): ?\Traversable
- {
- return $this->tags;
- }
-
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
M src/Entity/Tag.php +1 -27
@@ 7,8 7,7 @@ use Ramsey\Uuid\Uuid;
class Tag
{
private $id;
- private $label;
- private $articles;
+ public $label;
private $createdAt;
private $updatedAt;
@@ 19,36 18,11 @@ class Tag
$this->updatedAt = $date;
}
- public function __construct(
- string $label,
- ?array $articles = []
- ) {
- $this->label = $label;
- $this->articles = $articles;
- }
-
public function getId(): ?Uuid
{
return $this->id;
}
- public function getLabel(): ?string
- {
- return $this->label;
- }
-
- public function setLabel(string $label): self
- {
- $this->label = $label;
-
- return $this;
- }
-
- public function getArticles(): ?\Traversable
- {
- return $this->articles;
- }
-
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;