src/Entity/Playlist.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PlaylistRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PlaylistRepository::class)
  9.  */
  10. class Playlist
  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, nullable=true)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="text", nullable=true)
  24.      */
  25.     private $description;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity=Formation::class, mappedBy="playlist")
  28.      */
  29.     private $formations;
  30.     public function __construct()
  31.     {
  32.         $this->formations = new ArrayCollection();
  33.     }
  34.     public function __toString()
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     public function setName(?string $name): self
  47.     {
  48.         $this->name $name;
  49.         return $this;
  50.     }
  51.     public function getDescription(): ?string
  52.     {
  53.         return $this->description;
  54.     }
  55.     public function setDescription(?string $description): self
  56.     {
  57.         $this->description $description;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @return Collection<int, Formation>
  62.      */
  63.     public function getFormations(): Collection
  64.     {
  65.         return $this->formations;
  66.     }
  67.     public function addFormation(Formation $formation): self
  68.     {
  69.         if (!$this->formations->contains($formation)) {
  70.             $this->formations[] = $formation;
  71.             $formation->setPlaylist($this);
  72.         }
  73.         return $this;
  74.     }
  75.     public function removeFormation(Formation $formation): self
  76.     {
  77.         if ($this->formations->removeElement($formation) && $formation->getPlaylist() === $this) {
  78.             // set the owning side to null (unless already changed)
  79.             $formation->setPlaylist(null);
  80.         }
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return ArrayCollection<int, string>
  85.      */
  86.     public function getCategoriesPlaylist() : ArrayCollection
  87.     {
  88.         $categories = new ArrayCollection();
  89.         foreach ($this->formations as $formation) {
  90.             $categoriesFormation $formation->getCategories();
  91.             foreach ($categoriesFormation as $categorieFormation) {
  92.                 if (!$categories->contains($categorieFormation->getName())) {
  93.                     $categories[] = $categorieFormation->getName();
  94.                 }
  95.             }
  96.         }
  97.         return $categories;
  98.     }
  99. }