<?php
namespace App\Entity;
use App\Repository\RealisationRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\UX\Turbo\Attribute\Broadcast;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: RealisationRepository::class)]
#[Broadcast]
#[Vich\Uploadable]
class Realisation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $position;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $description;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $pictureFilename;
/**
* @var File|null
*/
#[Vich\UploadableField(mapping: "realisation", fileNameProperty: "pictureFilename")]
#[Assert\Image(
mimeTypes: ["image/jpeg", "image/png", "image/jpg", "image/gif"],
mimeTypesMessage: "Les formats d'images acceptés sont : .jpeg .jpg .png .gif"
)]
private $pictureFile;
#[ORM\Column(type: 'datetime')]
private $created_at;
#[ORM\Column(type: 'datetime')]
private $updated_at;
public function __construct()
{
$this->created_at = new DateTime('now');
$this->updated_at = new DateTime('now');
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPictureFilename(): ?string
{
return $this->pictureFilename;
}
public function setPictureFilename(?string $pictureFilename): self
{
$this->pictureFilename = $pictureFilename;
return $this;
}
/**
* @return null|File
*/
public function getPictureFile(): ?File
{
return $this->pictureFile;
}
/**
* @param null|File $pictureFile
* @return Realisation
*/
public function setPictureFile(?File $pictureFile): self
{
$this->pictureFile = $pictureFile;
if ($this->pictureFile instanceof UploadedFile) {
$this->updated_at = new DateTime('now');
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
}