src/Entity/Badge.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\BadgeRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassBadgeRepository::class)]
  9. #[ApiResource]
  10. class Badge
  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\ManyToOne(inversedBy'badges')]
  19.     private ?MediaObject $icon null;
  20.     #[ORM\ManyToMany(targetEntityAttendee::class, mappedBy'badges')]
  21.     private Collection $attendees;
  22.     #[ORM\OneToMany(mappedBy'badge'targetEntityLesson::class)]
  23.     private Collection $lessons;
  24.     public function __construct()
  25.     {
  26.         $this->attendees = new ArrayCollection();
  27.         $this->lessons = new ArrayCollection();
  28.     }
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function __toString(): string
  34.     {
  35.         return $this->name;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     public function getIcon(): ?MediaObject
  47.     {
  48.         return $this->icon;
  49.     }
  50.     public function setIcon(?MediaObject $icon): self
  51.     {
  52.         $this->icon $icon;
  53.         return $this;
  54.     }
  55.     /**
  56.      * @return Collection<int, Attendee>
  57.      */
  58.     public function getAttendees(): Collection
  59.     {
  60.         return $this->attendees;
  61.     }
  62.     public function addAttendee(Attendee $attendee): self
  63.     {
  64.         if (!$this->attendees->contains($attendee)) {
  65.             $this->attendees->add($attendee);
  66.             $attendee->addBadge($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeAttendee(Attendee $attendee): self
  71.     {
  72.         if ($this->attendees->removeElement($attendee)) {
  73.             $attendee->removeBadge($this);
  74.         }
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return Collection<int, Lesson>
  79.      */
  80.     public function getLessons(): Collection
  81.     {
  82.         return $this->lessons;
  83.     }
  84.     public function addLesson(Lesson $lesson): self
  85.     {
  86.         if (!$this->lessons->contains($lesson)) {
  87.             $this->lessons->add($lesson);
  88.             $lesson->setBadge($this);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeLesson(Lesson $lesson): self
  93.     {
  94.         if ($this->lessons->removeElement($lesson)) {
  95.             // set the owning side to null (unless already changed)
  96.             if ($lesson->getBadge() === $this) {
  97.                 $lesson->setBadge(null);
  98.             }
  99.         }
  100.         return $this;
  101.     }
  102. }