src/Entity/Document.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. #[Vich\Uploadable]
  10. #[ORM\Entity(repositoryClass"App\Repository\DocumentRepository")]
  11. #[ORM\Table(name"document")]
  12. class Document
  13. {
  14.     #[ORM\Column(type"boolean")]
  15.     private bool $isDeleted false;
  16.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy"documents")]
  17.     #[ORM\JoinColumn(nullablefalse)]
  18.     private User $user;
  19.     #[ORM\ManyToMany(targetEntityDisasterDeclaration::class, mappedBy"destroyedDocuments"cascade: ["persist"])]
  20.     private Collection|array $disasterDeclarations;
  21.     #[ORM\Column(type"datetime")]
  22.     private DateTime $createdAt;
  23.     #[ORM\Column(name"id"type"integer")]
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue(strategy"AUTO")]
  26.     private ?int $id;
  27.     /**
  28.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  29.      */
  30.     #[Assert\NotBlank(message'Ce champ est obligatoire')]
  31.     #[Vich\UploadableField(mapping"document"fileNameProperty"documentFileName"size"documentFileSize")]
  32.     private File $documentFile;
  33.     #[ORM\Column(type"string"length255nullabletrue)]
  34.     private ?string $documentFileName;
  35.     #[ORM\Column(type"integer"nullabletrue)]
  36.     private ?int $documentFileSize;
  37.     #[ORM\Column(type"datetime"nullabletrue)]
  38.     private ?DateTime $documentFileUpdatedAt;
  39.     public function __construct()
  40.     {
  41.         $this->createdAt = new DateTime();
  42.     }
  43.     public function __toString()
  44.     {
  45.         return "#" $this->id " - " $this->documentFileName;
  46.     }
  47.     /**
  48.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  49.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  50.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  51.      * must be able to accept an instance of 'File' as the bundle will inject one here
  52.      * during Doctrine hydration.
  53.      *
  54.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  55.      */
  56.     public function setDocumentFile(File $image null)
  57.     {
  58.         $this->documentFile $image;
  59.         if (null !== $image) {
  60.             // It is required that at least one field changes if you are using doctrine
  61.             // otherwise the event listeners won't be called and the file is lost
  62.             $this->documentFileUpdatedAt = new \DateTime();
  63.         }
  64.     }
  65.     public function getDocumentFile()
  66.     {
  67.         return $this->documentFile;
  68.     }
  69.     /**
  70.      * Get id
  71.      *
  72.      * @return int
  73.      */
  74.     public function getId()
  75.     {
  76.         return $this->id;
  77.     }
  78.     /**
  79.      * Set createdAt
  80.      *
  81.      * @param DateTime $createdAt
  82.      *
  83.      * @return Document
  84.      */
  85.     public function setCreatedAt($createdAt)
  86.     {
  87.         $this->createdAt $createdAt;
  88.         return $this;
  89.     }
  90.     /**
  91.      * Get createdAt
  92.      *
  93.      * @return DateTime
  94.      */
  95.     public function getCreatedAt()
  96.     {
  97.         return $this->createdAt;
  98.     }
  99.     /**
  100.      * Set documentFileName
  101.      *
  102.      * @param string $documentFileName
  103.      *
  104.      * @return Document
  105.      */
  106.     public function setDocumentFileName($documentFileName)
  107.     {
  108.         $this->documentFileName $documentFileName;
  109.         return $this;
  110.     }
  111.     /**
  112.      * Get documentFileName
  113.      *
  114.      * @return string
  115.      */
  116.     public function getDocumentFileName()
  117.     {
  118.         return $this->documentFileName;
  119.     }
  120.     /**
  121.      * Set documentFileSize
  122.      *
  123.      * @param integer $documentFileSize
  124.      *
  125.      * @return Document
  126.      */
  127.     public function setDocumentFileSize($documentFileSize)
  128.     {
  129.         $this->documentFileSize $documentFileSize;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Get documentFileSize
  134.      *
  135.      * @return integer
  136.      */
  137.     public function getDocumentFileSize()
  138.     {
  139.         return $this->documentFileSize;
  140.     }
  141.     /**
  142.      * Set documentFileUpdatedAt
  143.      *
  144.      * @param DateTime $documentFileUpdatedAt
  145.      *
  146.      * @return Document
  147.      */
  148.     public function setDocumentFileUpdatedAt($documentFileUpdatedAt)
  149.     {
  150.         $this->documentFileUpdatedAt $documentFileUpdatedAt;
  151.         return $this;
  152.     }
  153.     /**
  154.      * Get documentFileUpdatedAt
  155.      *
  156.      * @return DateTime
  157.      */
  158.     public function getDocumentFileUpdatedAt()
  159.     {
  160.         return $this->documentFileUpdatedAt;
  161.     }
  162.     /**
  163.      * Set user
  164.      *
  165.      * @param \App\Entity\User $user
  166.      *
  167.      * @return Document
  168.      */
  169.     public function setUser(\App\Entity\User $user)
  170.     {
  171.         $this->user $user;
  172.         return $this;
  173.     }
  174.     /**
  175.      * Get user
  176.      *
  177.      * @return \App\Entity\User
  178.      */
  179.     public function getUser()
  180.     {
  181.         return $this->user;
  182.     }
  183.     /**
  184.      * Add disasterDeclaration
  185.      *
  186.      * @param \App\Entity\DisasterDeclaration $disasterDeclaration
  187.      *
  188.      * @return Document
  189.      */
  190.     public function addDisasterDeclaration(\App\Entity\DisasterDeclaration $disasterDeclaration)
  191.     {
  192.         $this->disasterDeclarations[] = $disasterDeclaration;
  193.         return $this;
  194.     }
  195.     /**
  196.      * Remove disasterDeclaration
  197.      *
  198.      * @param \App\Entity\DisasterDeclaration $disasterDeclaration
  199.      */
  200.     public function removeDisasterDeclaration(\App\Entity\DisasterDeclaration $disasterDeclaration)
  201.     {
  202.         $this->disasterDeclarations->removeElement($disasterDeclaration);
  203.     }
  204.     /**
  205.      * Get disasterDeclarations
  206.      *
  207.      * @return \Doctrine\Common\Collections\Collection
  208.      */
  209.     public function getDisasterDeclarations()
  210.     {
  211.         return $this->disasterDeclarations;
  212.     }
  213.     /**
  214.      * Set isDeleted
  215.      *
  216.      * @param boolean $isDeleted
  217.      *
  218.      * @return Document
  219.      */
  220.     public function setIsDeleted($isDeleted)
  221.     {
  222.         $this->isDeleted $isDeleted;
  223.         return $this;
  224.     }
  225.     /**
  226.      * Get isDeleted
  227.      *
  228.      * @return boolean
  229.      */
  230.     public function getIsDeleted()
  231.     {
  232.         return $this->isDeleted;
  233.     }
  234. }