<?php
namespace App\Entity;
use App\Traits\Activeable;
use App\Traits\Creatable;
use App\Traits\Deleteable;
use App\Traits\Updateable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="`article_category`")
* @ORM\Entity()
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class ArticleCategory
{
use Creatable, Updateable, Activeable, Deleteable;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @var string
* @ORM\Column(type="string")
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="articleCategory")
* @ORM\OrderBy({"date" = "DESC"})
*/
private Collection $articles;
public function __construct()
{
$this->articles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection|array
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setArticleCategory($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getArticleCategory() === $this) {
$article->setArticleCategory(null);
}
}
return $this;
}
}