<?php
namespace App\Entity;
use App\Repository\BadgeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=BadgeRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Badge
{
use RemoveImageTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="badges")
*/
private $speakers;
/**
* @ORM\Column(type="string")
*/
private $place;
public function __construct()
{
$this->speakers = new ArrayCollection();
}
/**
* @ORM\PostRemove()
*/
public function removeImageOnDelete()
{
$this->removeImage($this->getImage());
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return Collection|Speaker[]
*/
public function getSpeakers(): Collection
{
return $this->speakers;
}
public function addSpeaker(Speaker $speaker): self
{
if (!$this->speakers->contains($speaker)) {
$this->speakers[] = $speaker;
$speaker->addBadge($this);
}
return $this;
}
public function removeSpeaker(Speaker $speaker): self
{
if ($this->speakers->removeElement($speaker)) {
$speaker->removeBadge($this);
}
return $this;
}
public function __toString(): string
{
return $this->getName();
}
public function getPlace(): ?string
{
return $this->place;
}
public function setPlace(string $place): self
{
$this->place = $place;
return $this;
}
}