src/Entity/Forum.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use App\Controller\Api\Controller\Course\Forum\CourseForum;
  6. use App\Repository\ForumRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassForumRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['read:forum:item']],
  14.     operations: [
  15.         new Get(), 
  16.         new Get(
  17.             uriTemplate'/cours/{id}/forum',
  18.             controllerCourseForum::class,
  19.             readfalse,
  20.         )
  21.     ]
  22. )]
  23. class Forum
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     #[Groups(['read:forum:item''read:course:collection'])]
  29.     private ?int $id null;
  30.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     #[Groups(['read:forum:item'])]
  33.     private ?Cours $cours null;
  34.     #[ORM\ManyToMany(targetEntityMembre::class, mappedBy'forums'cascade: ['persist''remove'])]
  35.     private Collection $membres;
  36.     #[ORM\OneToMany(mappedBy'forum'targetEntitySujet::class, orphanRemovaltrue)]
  37.     private Collection $sujets;
  38.     public function __construct()
  39.     {
  40.         $this->membres = new ArrayCollection();
  41.         $this->sujets = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getCours(): ?Cours
  48.     {
  49.         return $this->cours;
  50.     }
  51.     public function setCours(Cours $cours): self
  52.     {
  53.         $this->cours $cours;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection<int, Membre>
  58.      */
  59.     public function getMembres(): Collection
  60.     {
  61.         return $this->membres;
  62.     }
  63.     public function addMembre(Membre $membre): self
  64.     {
  65.         if (!$this->membres->contains($membre)) {
  66.             $this->membres->add($membre);
  67.             $membre->addForum($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeMembre(Membre $membre): self
  72.     {
  73.         if ($this->membres->removeElement($membre)) {
  74.             $membre->removeForum($this);
  75.         }
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return Collection<int, Sujet>
  80.      */
  81.     public function getSujets(): Collection
  82.     {
  83.         return $this->sujets;
  84.     }
  85.     public function addSujet(Sujet $sujet): self
  86.     {
  87.         if (!$this->sujets->contains($sujet)) {
  88.             $this->sujets->add($sujet);
  89.             $sujet->setForum($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function removeSujet(Sujet $sujet): self
  94.     {
  95.         if ($this->sujets->removeElement($sujet)) {
  96.             // set the owning side to null (unless already changed)
  97.             if ($sujet->getForum() === $this) {
  98.                 $sujet->setForum(null);
  99.             }
  100.         }
  101.         return $this;
  102.     }
  103. }