src/Entity/Category.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\CategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  11.  * @ApiResource(
  12.  *     collectionOperations={"get","post"},
  13.  *     itemOperations={"get","put","patch","delete"},
  14.  *     normalizationContext={"groups"={"category"}},
  15.  *     denormalizationContext={"groups"={"category"}},
  16.  *     attributes={"pagination_enabled"=false}
  17.  * )
  18.  */
  19. class Category
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      * @Groups("category", "article")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      * @Groups("category")
  31.      */
  32.     private $nameFr;
  33.     /**
  34.      * @ORM\Column(type="string", length=255, nullable=true)
  35.      * @Groups("category")
  36.      */
  37.     private $nameEn;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      * @Groups("category")
  41.      */
  42.     private $nameDe;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      * @Groups("category")
  46.      */
  47.     private $nameNl;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=Article::class, mappedBy="category")
  50.      */
  51.     private $articles;
  52.     /**
  53.      * @ORM\Column(type="text", nullable=true)
  54.      * @Groups("category")
  55.      */
  56.     private $image;
  57.     public function __construct()
  58.     {
  59.         $this->articles = new ArrayCollection();
  60.     }
  61.     public function getId(): ?int
  62.     {
  63.         return $this->id;
  64.     }
  65.     public function getNameFr(): ?string
  66.     {
  67.         return $this->nameFr;
  68.     }
  69.     public function setNameFr(?string $nameFr): self
  70.     {
  71.         $this->nameFr $nameFr;
  72.         return $this;
  73.     }
  74.     public function getNameEn(): ?string
  75.     {
  76.         return $this->nameEn;
  77.     }
  78.     public function setNameEn(?string $nameEn): self
  79.     {
  80.         $this->nameEn $nameEn;
  81.         return $this;
  82.     }
  83.     public function getNameDe(): ?string
  84.     {
  85.         return $this->nameDe;
  86.     }
  87.     public function setNameDe(?string $nameDe): self
  88.     {
  89.         $this->nameDe $nameDe;
  90.         return $this;
  91.     }
  92.     public function getNameNl(): ?string
  93.     {
  94.         return $this->nameNl;
  95.     }
  96.     public function setNameNl(?string $nameNl): self
  97.     {
  98.         $this->nameNl $nameNl;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection|Article[]
  103.      */
  104.     public function getArticles(): Collection
  105.     {
  106.         return $this->articles;
  107.     }
  108.     public function addArticle(Article $article): self
  109.     {
  110.         if (!$this->articles->contains($article)) {
  111.             $this->articles[] = $article;
  112.             $article->setFamily($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeArticle(Article $article): self
  117.     {
  118.         if ($this->articles->removeElement($article)) {
  119.             // set the owning side to null (unless already changed)
  120.             if ($article->getFamily() === $this) {
  121.                 $article->setFamily(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126.     public function getImage(): ?string
  127.     {
  128.         return $this->image;
  129.     }
  130.     public function setImage(?string $image): self
  131.     {
  132.         $this->image $image;
  133.         return $this;
  134.     }
  135. }