|
@@ -3,6 +3,8 @@
|
|
|
namespace App\Entity;
|
|
|
|
|
|
use App\Repository\ArticleRepository;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
+use Doctrine\Common\Collections\Collection;
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
@@ -40,10 +42,17 @@ class Article
|
|
|
#[Assert\Regex('/ /', match: false, message: 'Pas d`espace dans le permalien')]
|
|
|
private ?string $slug = null;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var Collection<int, Tag>
|
|
|
+ */
|
|
|
+ #[ORM\ManyToMany(targetEntity: Tag::class)]
|
|
|
+ private Collection $tags;
|
|
|
+
|
|
|
public function __construct(User $author)
|
|
|
{
|
|
|
$this->setAuthor($author);
|
|
|
$this->setPublicationDate(new \DateTimeImmutable());
|
|
|
+ $this->tags = new ArrayCollection();
|
|
|
}
|
|
|
|
|
|
public function getId(): ?int
|
|
@@ -122,4 +131,28 @@ class Article
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Collection<int, Tag>
|
|
|
+ */
|
|
|
+ public function getTags(): Collection
|
|
|
+ {
|
|
|
+ return $this->tags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addTag(Tag $tag): static
|
|
|
+ {
|
|
|
+ if (!$this->tags->contains($tag)) {
|
|
|
+ $this->tags->add($tag);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeTag(Tag $tag): static
|
|
|
+ {
|
|
|
+ $this->tags->removeElement($tag);
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
}
|