src/Entity/Specialite.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use App\Repository\SpecialiteRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassSpecialiteRepository::class)]
  12. #[ApiResource(
  13.     operations: [
  14.         new GetCollection()
  15.     ]
  16. )]
  17. class Specialite
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     #[Groups(['read:user:item'])]
  23.     private ?int $id null;
  24.     #[ORM\ManyToOne(inversedBy'specialites')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     #[Groups(['read:user:item'])]
  27.     private ?Filiere $filiere null;
  28.     #[ORM\Column(length255)]
  29.     #[Assert\NotBlank(message"Ne peut ĂȘtre vide !")]
  30.     #[Assert\NotNull(message"Ne peut ĂȘtre nul !")]
  31.     #[Groups(['read:user:item'])]
  32.     private ?string $name null;
  33.     #[ORM\Column(length255)]
  34.     #[Groups(['read:user:item'])]
  35.     private ?string $slug null;
  36.     #[ORM\OneToMany(mappedBy'specialite'targetEntityClasse::class)]
  37.     private Collection $classes;
  38.     public function __construct()
  39.     {
  40.         $this->classes = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getFiliere(): ?Filiere
  47.     {
  48.         return $this->filiere;
  49.     }
  50.     public function setFiliere(?Filiere $filiere): self
  51.     {
  52.         $this->filiere $filiere;
  53.         return $this;
  54.     }
  55.     public function getName(): ?string
  56.     {
  57.         return $this->name;
  58.     }
  59.     public function setName(string $name): self
  60.     {
  61.         $this->name $name;
  62.         return $this;
  63.     }
  64.     public function getSlug(): ?string
  65.     {
  66.         return $this->slug;
  67.     }
  68.     public function setSlug(string $slug): self
  69.     {
  70.         $this->slug $slug;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @return Collection<int, Classe>
  75.      */
  76.     public function getClasses(): Collection
  77.     {
  78.         return $this->classes;
  79.     }
  80.     public function addClass(Classe $class): self
  81.     {
  82.         if (!$this->classes->contains($class)) {
  83.             $this->classes->add($class);
  84.             $class->setSpecialite($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeClass(Classe $class): self
  89.     {
  90.         if ($this->classes->removeElement($class)) {
  91.             // set the owning side to null (unless already changed)
  92.             if ($class->getSpecialite() === $this) {
  93.                 $class->setSpecialite(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98. }