src/Entity/CourseTag.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\CourseTagRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassCourseTagRepository::class)]
  9. #[ApiResource]
  10. class CourseTag
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $color null;
  20.     #[ORM\OneToMany(mappedBy'courseTag'targetEntityCourse::class)]
  21.     private Collection $courses;
  22.     public function __construct()
  23.     {
  24.         $this->courses = new ArrayCollection();
  25.     }
  26.     public function getId(): ?int
  27.     {
  28.         return $this->id;
  29.     }
  30.     public function __toString(): string
  31.     {
  32.         return $this->name;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getColor(): ?string
  44.     {
  45.         return $this->color;
  46.     }
  47.     public function setColor(string $color): self
  48.     {
  49.         $this->color $color;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return Collection<int, Course>
  54.      */
  55.     public function getCourses(): Collection
  56.     {
  57.         return $this->courses;
  58.     }
  59.     public function addCourse(Course $course): self
  60.     {
  61.         if (!$this->courses->contains($course)) {
  62.             $this->courses->add($course);
  63.             $course->setCourseTag($this);
  64.         }
  65.         return $this;
  66.     }
  67.     public function removeCourse(Course $course): self
  68.     {
  69.         if ($this->courses->removeElement($course)) {
  70.             // set the owning side to null (unless already changed)
  71.             if ($course->getCourseTag() === $this) {
  72.                 $course->setCourseTag(null);
  73.             }
  74.         }
  75.         return $this;
  76.     }
  77. }