<?php
namespace App\Entity;
use App\Repository\NuptialsRepository;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: NuptialsRepository::class)]
#[Vich\Uploadable]
class Nuptials
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $titolo;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*/
#[Vich\UploadableField(mapping: 'nuptials', fileNameProperty: 'copertina')]
private ?File $imageFile = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $copertina;
#[ORM\Column(type: 'text', nullable: true)]
private $descrizione;
#[ORM\OneToMany(mappedBy: 'nuptial', targetEntity: NuptialsGallery::class, orphanRemoval: true)]
private $nuptialsGalleries;
#[ORM\Column(type: 'datetime')]
private $updatedAt;
public function __construct()
{
$this->updatedAt = new DateTime('now');
$this->nuptialsGalleries = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitolo(): ?string
{
return $this->titolo;
}
public function setTitolo(?string $titolo): self
{
$this->titolo = $titolo;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function getCopertina(): ?string
{
return $this->copertina;
}
public function setCopertina(?string $copertina): self
{
$this->copertina = $copertina;
return $this;
}
public function getDescrizione(): ?string
{
return $this->descrizione;
}
public function setDescrizione(?string $descrizione): self
{
$this->descrizione = $descrizione;
return $this;
}
/**
* @return Collection<int, NuptialsGallery>
*/
public function getNuptialsGalleries(): Collection
{
return $this->nuptialsGalleries;
}
public function addNuptialsGallery(NuptialsGallery $nuptialsGallery): self
{
if (!$this->nuptialsGalleries->contains($nuptialsGallery)) {
$this->nuptialsGalleries[] = $nuptialsGallery;
$nuptialsGallery->setNuptial($this);
}
return $this;
}
public function removeNuptialsGallery(NuptialsGallery $nuptialsGallery): self
{
if ($this->nuptialsGalleries->removeElement($nuptialsGallery)) {
// set the owning side to null (unless already changed)
if ($nuptialsGallery->getNuptial() === $this) {
$nuptialsGallery->setNuptial(null);
}
}
return $this;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function __toString(): string
{
return $this->titolo;
}
}