<?php
namespace App\Entity;
use App\Repository\HotelTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: HotelTypeRepository::class)]
#[UniqueEntity(['name'])]
class HotelType
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 128)]
#[Assert\NotBlank]
#[Assert\Length(max: 128)]
#[Assert\Regex(
pattern: '/^[\p{L}\p{M}0-9\s\'-]+$/u',
)]
private ?string $name;
#[ORM\OneToMany(mappedBy: 'type', targetEntity: Hotel::class)]
private $hotels;
public function __construct()
{
$this->hotels = new ArrayCollection();
}
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;
}
/**
* @return Collection<int, Hotel>
*/
public function getHotels(): Collection
{
return $this->hotels;
}
public function addHotel(Hotel $hotel): self
{
if (!$this->hotels->contains($hotel)) {
$this->hotels[] = $hotel;
$hotel->setType($this);
}
return $this;
}
public function removeHotel(Hotel $hotel): self
{
if ($this->hotels->removeElement($hotel)) {
// set the owning side to null (unless already changed)
if ($hotel->getType() === $this) {
$hotel->setType(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name;
}
}