src/Entity/Badge.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BadgeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass=BadgeRepository::class)
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Badge
  13. {
  14.     use RemoveImageTrait;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      * @Assert\NotBlank()
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $image;
  30.     /**
  31.      * @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="badges")
  32.      */
  33.     private $speakers;
  34.     /**
  35.      * @ORM\Column(type="string")
  36.      */
  37.     private $place;
  38.     public function __construct()
  39.     {
  40.         $this->speakers = new ArrayCollection();
  41.     }
  42.     /**
  43.      * @ORM\PostRemove()
  44.      */
  45.     public function removeImageOnDelete()
  46.     {
  47.         $this->removeImage($this->getImage());
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getImage(): ?string
  63.     {
  64.         return $this->image;
  65.     }
  66.     public function setImage(string $image): self
  67.     {
  68.         $this->image $image;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection|Speaker[]
  73.      */
  74.     public function getSpeakers(): Collection
  75.     {
  76.         return $this->speakers;
  77.     }
  78.     public function addSpeaker(Speaker $speaker): self
  79.     {
  80.         if (!$this->speakers->contains($speaker)) {
  81.             $this->speakers[] = $speaker;
  82.             $speaker->addBadge($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeSpeaker(Speaker $speaker): self
  87.     {
  88.         if ($this->speakers->removeElement($speaker)) {
  89.             $speaker->removeBadge($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function __toString(): string
  94.     {
  95.         return $this->getName();
  96.     }
  97.     public function getPlace(): ?string
  98.     {
  99.         return $this->place;
  100.     }
  101.     public function setPlace(string $place): self
  102.     {
  103.         $this->place $place;
  104.         return $this;
  105.     }
  106. }