<?php
namespace App\Entity;
use App\Repository\DevisAttachmentRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use DateTime;
use DateTimeZone;
/**
* @ORM\Entity(repositoryClass=DevisAttachmentRepository::class)
* @Vich\Uploadable
*/
class DevisAttachment
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $fileName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $originalName;
/**
* @Vich\UploadableField(mapping="devis_attachments", fileNameProperty="fileName")
*
* @var File|null
*/
private $attachFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $size;
/**
* @ORM\ManyToOne(targetEntity=Devis::class, inversedBy="attachments")
*/
private $devis;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
public function __construct()
{
$this->createdAt = new DateTime('now', new DateTimeZone('Europe/Paris'));
}
public function getId(): ?int
{
return $this->id;
}
public function getFileName(): ?string
{
return $this->fileName;
}
public function setFileName(?string $fileName): self
{
$this->fileName = $fileName;
return $this;
}
public function getOriginalName(): ?string
{
return $this->originalName;
}
public function setOriginalName(?string $originalName): self
{
$this->originalName = $originalName;
return $this;
}
public function getAttachFile(): ?File
{
return $this->attachFile;
}
/**
* @param File|UploadedFile|null $attachFile
*/
public function setAttachFile(?File $attachFile = null): void
{
$this->attachFile = $attachFile;
if ($attachFile) {
$parisTimezone = new DateTimeZone('Europe/Paris');
$this->updatedAt = new DateTime('now', $parisTimezone);
if ($attachFile instanceof UploadedFile) {
$this->originalName = $attachFile->getClientOriginalName();
$this->size = $attachFile->getSize();
}
if ($this->createdAt === null) {
$this->createdAt = new DateTime('now', $parisTimezone);
}
}
}
public function getSize(): ?string
{
return $this->size;
}
public function setSize(?string $size): self
{
$this->size = $size;
return $this;
}
public function getDevis(): ?Devis
{
return $this->devis;
}
public function setDevis(?Devis $devis): self
{
$this->devis = $devis;
return $this;
}
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;
}
/**
* __serialize() : cela signifie simplement que nous convertissons les données ou l'état d'un objet en
* une forme de stockage (comme un tableau) pour qu'il puisse être sauvegardé ou transmis.
*/
public function __serialize(): array
{
return [
'id' => $this->id,
'fileName' => $this->fileName,
'originalName' => $this->originalName,
'size' => $this->size,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}
/**
* __unserialize() : cela signifie que l'on reconstruit un objet à partir des données qui ont été
* précédemment sérialisées, pour qu'il puisse être utilisé à nouveau dans le programme
*/
public function __unserialize(array $data): void
{
$this->id = $data['id'];
$this->fileName = $data['fileName'];
$this->originalName = $data['originalName'];
$this->size = $data['size'];
$this->createdAt = $data['createdAt'];
$this->updatedAt = $data['updatedAt'];
}
}