<?php
namespace App\Entity;
use App\Repository\SiteRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=SiteRepository::class)
* @ORM\HasLifecycleCallbacks
* @Vich\Uploadable()
*/
class Site
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\Column(type="string", length=255)
*/
private string $title;
/**
* @ORM\Column(type="string", length=1024)
*/
private string $shortDescription;
/**
* @ORM\Column(type="text")
*/
private string $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $location;
/**
* @ORM\Column(type="string", length=255, unique=true)
*
* @Gedmo\Slug(fields={"title"})
*/
private string $slug;
/**
* @ORM\Column(type="date", nullable=true)
*/
private ?\DateTimeInterface $date;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $updatedAt;
/**
* @ORM\OneToMany(targetEntity="Image", mappedBy="site", cascade={"all"})
*/
private $images;
/**
* @ORM\ManyToMany(targetEntity=Category::class)
*/
private $categories;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->categories = new ArrayCollection();
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps(): void
{
$this->setUpdatedAt(new \DateTime('now'));
if ($this->getCreatedAt() === null) {
$this->setCreatedAt(new \DateTime('now'));
}
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(string $shortDescription): self
{
$this->shortDescription = $shortDescription;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function getSlug(): string
{
return $this->slug;
}
public function setSlug(string $slug): void
{
$this->slug = $slug;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getImages()
{
return $this->images;
}
public function addImage(Image $image): self
{
$image->setSite($this);
$this->images[] = $image;
return $this;
}
public function removeImage(Image $image)
{
$image->setSite(null);
$this->images->removeElement($image);
}
public function __toString(): string
{
return $this->title . ' '. $this->location;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
}
return $this;
}
public function removeCategory(Category $category): self
{
$this->categories->removeElement($category);
return $this;
}
}