<?php
namespace App\Entity;
use App\Repository\ProvinciaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[UniqueEntity('slug')]
#[ORM\Entity(repositoryClass: ProvinciaRepository::class)]
class Provincia {
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Serializer\Groups(groups: ['api'])]
private $id;
#[Assert\NotBlank]
#[ORM\Column(type: 'string')]
private ?string $nombre = null;
#[Assert\NotBlank]
#[ORM\ManyToOne(targetEntity: Comunidad::class, inversedBy: 'provincias')]
#[ORM\JoinColumn(nullable: false)]
#[Serializer\Groups(groups: ['api'])]
private ?Comunidad $comunidad = null;
#[ORM\Column(type: 'boolean')]
private bool $visible = true;
#[ORM\Column(type: 'boolean')]
private bool $borrado = false;
#[Assert\NotBlank]
#[Assert\Regex(pattern: '/^[a-z0-9]+(?:-[a-z0-9]+)*$/')]
#[ORM\Column(type: 'string', length: 190, unique: true)]
private ?string $slug = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $seoTitle = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $seoDescription = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $seoKeywords = null;
#[ORM\OneToMany(targetEntity: Comarca::class, mappedBy: 'provincia')]
private Collection $comarcas;
public function __construct()
{
$this->comarcas = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNombre(): ?string
{
return $this->nombre;
}
/**
* @param mixed $nombre
*/
public function setNombre(?string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function getComunidad(): ?Comunidad
{
return $this->comunidad;
}
public function setComunidad(?Comunidad $comunidad): self
{
$this->comunidad = $comunidad;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
public function isBorrado(): ?bool
{
return $this->borrado;
}
public function setBorrado(bool $borrado): self
{
$this->borrado = $borrado;
return $this;
}
public function getSeoTitle(): ?string
{
return $this->seoTitle;
}
public function setSeoTitle(?string $seoTitle): self
{
$this->seoTitle = $seoTitle;
return $this;
}
public function getSeoDescription(): ?string
{
return $this->seoDescription;
}
public function setSeoDescription(?string $seoDescription): self
{
$this->seoDescription = $seoDescription;
return $this;
}
public function getSeoKeywords(): ?string
{
return $this->seoKeywords;
}
public function setSeoKeywords(?string $seoKeywords): self
{
$this->seoKeywords = $seoKeywords;
return $this;
}
/**
* @return Collection<int, Comarca>
*/
public function getComarcas(): Collection
{
return $this->comarcas;
}
public function addComarca(Comarca $comarca): self
{
if (!$this->comarcas->contains($comarca)) {
$this->comarcas[] = $comarca;
$comarca->setProvincia($this);
}
return $this;
}
public function removeComarca(Comarca $comarca): self
{
// set the owning side to null (unless already changed)
if ($this->comarcas->removeElement($comarca) && $comarca->getProvincia() === $this) {
$comarca->setProvincia(null);
}
return $this;
}
}