<?php
namespace App\Entity;
use App\Repository\LocalidadRepository;
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: LocalidadRepository::class)]
class Localidad {
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Serializer\Groups(groups: ['api'])]
private $id;
#[Assert\NotBlank]
#[ORM\Column(type: 'string')]
private ?string $nombre = null;
#[ORM\Column(type: 'boolean')]
private bool $visible = true;
#[ORM\Column(type: 'boolean')]
private bool $borrado = false;
#[Assert\NotBlank]
#[ORM\ManyToOne(targetEntity: Comarca::class, inversedBy: 'localidades')]
#[ORM\JoinColumn(nullable: false)]
#[Serializer\Groups(groups: ['api'])]
private ?Comarca $comarca = null;
#[ORM\Column(type: 'boolean')]
private bool $tieneMenos5000Habitantes = false;
#[ORM\OneToMany(targetEntity: Curso::class, mappedBy: 'localidad')]
private Collection $cursos;
#[Assert\NotBlank]
#[Assert\Regex(pattern: '/^[a-z0-9]+(?:-[a-z0-9]+)*$/')]
#[ORM\Column(type: 'string', length: 190, nullable: true, 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: Usuario::class, mappedBy: 'localidad')]
private Collection $usuarios;
#[ORM\OneToMany(targetEntity: Solicitud::class, mappedBy: 'localidad')]
private Collection $solicitudes;
#[ORM\OneToMany(mappedBy: 'localidad', targetEntity: JornadaCurso::class)]
private Collection $jornadasCursos;
public function __construct()
{
$this->cursos = new ArrayCollection();
$this->usuarios = new ArrayCollection();
$this->solicitudes = new ArrayCollection();
$this->jornadasCursos = 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 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 getComarca(): ?Comarca
{
return $this->comarca;
}
public function setComarca(?Comarca $comarca): self
{
$this->comarca = $comarca;
return $this;
}
public function isTieneMenos5000Habitantes(): ?bool
{
return $this->tieneMenos5000Habitantes;
}
public function setTieneMenos5000Habitantes(bool $tieneMenos5000Habitantes): self
{
$this->tieneMenos5000Habitantes = $tieneMenos5000Habitantes;
return $this;
}
/**
* @return Collection<int, Curso>
*/
public function getCursos(): Collection
{
return $this->cursos;
}
public function addCurso(Curso $curso): self
{
if (!$this->cursos->contains($curso)) {
$this->cursos[] = $curso;
$curso->setLocalidad($this);
}
return $this;
}
public function removeCurso(Curso $curso): self
{
// set the owning side to null (unless already changed)
if ($this->cursos->removeElement($curso) && $curso->getLocalidad() === $this) {
$curso->setLocalidad(null);
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
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, Usuario>
*/
public function getUsuarios(): Collection
{
return $this->usuarios;
}
public function addUsuario(Usuario $usuario): self
{
if (!$this->usuarios->contains($usuario)) {
$this->usuarios[] = $usuario;
$usuario->setLocalidad($this);
}
return $this;
}
public function removeUsuario(Usuario $usuario): self
{
// set the owning side to null (unless already changed)
if ($this->usuarios->removeElement($usuario) && $usuario->getLocalidad() === $this) {
$usuario->setLocalidad(null);
}
return $this;
}
/**
* @return Collection<int, Solicitud>
*/
public function getSolicitudes(): Collection
{
return $this->solicitudes;
}
public function addSolicitude(Solicitud $solicitude): self
{
if (!$this->solicitudes->contains($solicitude)) {
$this->solicitudes[] = $solicitude;
$solicitude->setLocalidad($this);
}
return $this;
}
public function removeSolicitude(Solicitud $solicitude): self
{
// set the owning side to null (unless already changed)
if ($this->solicitudes->removeElement($solicitude) && $solicitude->getLocalidad() === $this) {
$solicitude->setLocalidad(null);
}
return $this;
}
/**
* @return Collection<int, JornadaCurso>
*/
public function getJornadasCursos(): Collection
{
return $this->jornadasCursos;
}
public function addJornadasCurso(JornadaCurso $jornadasCurso): static
{
if (!$this->jornadasCursos->contains($jornadasCurso)) {
$this->jornadasCursos->add($jornadasCurso);
$jornadasCurso->setLocalidad($this);
}
return $this;
}
public function removeJornadasCurso(JornadaCurso $jornadasCurso): static
{
if ($this->jornadasCursos->removeElement($jornadasCurso)) {
// set the owning side to null (unless already changed)
if ($jornadasCurso->getLocalidad() === $this) {
$jornadasCurso->setLocalidad(null);
}
}
return $this;
}
}