src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  9.  */
  10. class Category
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=100)
  20.      */
  21.     private $label;
  22.     /**
  23.      * @ORM\Column(type="boolean")
  24.      */
  25.     private $is_active;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Section::class, inversedBy="categories")
  28.      * @ORM\JoinColumn(nullable=false)
  29.      */
  30.     private $section;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Article::class, mappedBy="category", orphanRemoval=true)
  33.      */
  34.     private $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 getLabel(): ?string
  44.     {
  45.         return $this->label;
  46.     }
  47.     public function setLabel(string $label): self
  48.     {
  49.         $this->label $label;
  50.         return $this;
  51.     }
  52.     public function isIsActive(): ?bool
  53.     {
  54.         return $this->is_active;
  55.     }
  56.     public function setIsActive(bool $is_active): self
  57.     {
  58.         $this->is_active $is_active;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return mixed
  63.      */
  64.     public function getSection()
  65.     {
  66.         return $this->section;
  67.     }
  68.     /**
  69.      * @param mixed $section
  70.      */
  71.     public function setSection($section): void
  72.     {
  73.         $this->section $section;
  74.     }
  75.     /**
  76.      * @return Collection<int, Article>
  77.      */
  78.     public function getArticles(): Collection
  79.     {
  80.         return $this->articles;
  81.     }
  82.     public function addArticle(Article $article): self
  83.     {
  84.         if (!$this->articles->contains($article)) {
  85.             $this->articles[] = $article;
  86.             $article->setCategory($this);
  87.         }
  88.         return $this;
  89.     }
  90.     public function removeArticle(Article $article): self
  91.     {
  92.         if ($this->articles->removeElement($article)) {
  93.             // set the owning side to null (unless already changed)
  94.             if ($article->getCategory() === $this) {
  95.                 $article->setCategory(null);
  96.             }
  97.         }
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection<int, Article>
  102.      */
  103.     public function getMoreArticles(Article $article): Collection
  104.     {
  105.         $elements = new ArrayCollection();
  106.         foreach ($this->articles as $art){
  107.             if ($art != $article){
  108.                 $elements[] = $art;
  109.             }
  110.         }
  111.         return $elements;
  112.     }
  113. }