src/Entity/ArticleCategory.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\Activeable;
  4. use App\Traits\Creatable;
  5. use App\Traits\Deleteable;
  6. use App\Traits\Updateable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. /**
  12.  * @ORM\Table(name="`article_category`")
  13.  * @ORM\Entity()
  14.  * @Gedmo\SoftDeleteable(fieldName="deletedAt")
  15.  */
  16. class ArticleCategory
  17. {
  18.     use CreatableUpdateableActiveableDeleteable;
  19.     /**
  20.      * @ORM\Id()
  21.      * @ORM\GeneratedValue()
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private ?int $id null;
  25.     /**
  26.      * @var string
  27.      * @ORM\Column(type="string")
  28.      */
  29.     private string $name;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="articleCategory")
  32.      * @ORM\OrderBy({"date" = "DESC"})
  33.      */
  34.     private Collection $articles;
  35.     public function __construct()
  36.     {
  37.         $this->articles = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return Collection|Article[]
  54.      */
  55.     public function getArticles(): Collection|array
  56.     {
  57.         return $this->articles;
  58.     }
  59.     public function addArticle(Article $article): self
  60.     {
  61.         if (!$this->articles->contains($article)) {
  62.             $this->articles[] = $article;
  63.             $article->setArticleCategory($this);
  64.         }
  65.         return $this;
  66.     }
  67.     public function removeArticle(Article $article): self
  68.     {
  69.         if ($this->articles->removeElement($article)) {
  70.             // set the owning side to null (unless already changed)
  71.             if ($article->getArticleCategory() === $this) {
  72.                 $article->setArticleCategory(null);
  73.             }
  74.         }
  75.         return $this;
  76.     }
  77. }