<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[Vich\Uploadable]
#[ORM\Entity(repositoryClass: "App\Repository\DocumentRepository")]
#[ORM\Table(name: "document")]
class Document
{
#[ORM\Column(type: "boolean")]
private bool $isDeleted = false;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: "documents")]
#[ORM\JoinColumn(nullable: false)]
private User $user;
#[ORM\ManyToMany(targetEntity: DisasterDeclaration::class, mappedBy: "destroyedDocuments", cascade: ["persist"])]
private Collection|array $disasterDeclarations;
#[ORM\Column(type: "datetime")]
private DateTime $createdAt;
#[ORM\Column(name: "id", type: "integer")]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "AUTO")]
private ?int $id;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*/
#[Assert\NotBlank(message: 'Ce champ est obligatoire')]
#[Vich\UploadableField(mapping: "document", fileNameProperty: "documentFileName", size: "documentFileSize")]
private File $documentFile;
#[ORM\Column(type: "string", length: 255, nullable: true)]
private ?string $documentFileName;
#[ORM\Column(type: "integer", nullable: true)]
private ?int $documentFileSize;
#[ORM\Column(type: "datetime", nullable: true)]
private ?DateTime $documentFileUpdatedAt;
public function __construct()
{
$this->createdAt = new DateTime();
}
public function __toString()
{
return "#" . $this->id . " - " . $this->documentFileName;
}
/**
* 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|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setDocumentFile(File $image = null)
{
$this->documentFile = $image;
if (null !== $image) {
// 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->documentFileUpdatedAt = new \DateTime();
}
}
public function getDocumentFile()
{
return $this->documentFile;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set createdAt
*
* @param DateTime $createdAt
*
* @return Document
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set documentFileName
*
* @param string $documentFileName
*
* @return Document
*/
public function setDocumentFileName($documentFileName)
{
$this->documentFileName = $documentFileName;
return $this;
}
/**
* Get documentFileName
*
* @return string
*/
public function getDocumentFileName()
{
return $this->documentFileName;
}
/**
* Set documentFileSize
*
* @param integer $documentFileSize
*
* @return Document
*/
public function setDocumentFileSize($documentFileSize)
{
$this->documentFileSize = $documentFileSize;
return $this;
}
/**
* Get documentFileSize
*
* @return integer
*/
public function getDocumentFileSize()
{
return $this->documentFileSize;
}
/**
* Set documentFileUpdatedAt
*
* @param DateTime $documentFileUpdatedAt
*
* @return Document
*/
public function setDocumentFileUpdatedAt($documentFileUpdatedAt)
{
$this->documentFileUpdatedAt = $documentFileUpdatedAt;
return $this;
}
/**
* Get documentFileUpdatedAt
*
* @return DateTime
*/
public function getDocumentFileUpdatedAt()
{
return $this->documentFileUpdatedAt;
}
/**
* Set user
*
* @param \App\Entity\User $user
*
* @return Document
*/
public function setUser(\App\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \App\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Add disasterDeclaration
*
* @param \App\Entity\DisasterDeclaration $disasterDeclaration
*
* @return Document
*/
public function addDisasterDeclaration(\App\Entity\DisasterDeclaration $disasterDeclaration)
{
$this->disasterDeclarations[] = $disasterDeclaration;
return $this;
}
/**
* Remove disasterDeclaration
*
* @param \App\Entity\DisasterDeclaration $disasterDeclaration
*/
public function removeDisasterDeclaration(\App\Entity\DisasterDeclaration $disasterDeclaration)
{
$this->disasterDeclarations->removeElement($disasterDeclaration);
}
/**
* Get disasterDeclarations
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getDisasterDeclarations()
{
return $this->disasterDeclarations;
}
/**
* Set isDeleted
*
* @param boolean $isDeleted
*
* @return Document
*/
public function setIsDeleted($isDeleted)
{
$this->isDeleted = $isDeleted;
return $this;
}
/**
* Get isDeleted
*
* @return boolean
*/
public function getIsDeleted()
{
return $this->isDeleted;
}
}