src/Entity/ItemPhoto.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. /**
  9.  * @Vich\Uploadable
  10.  */
  11. #[ORM\Entity(repositoryClass'App\Repository\ItemPhotoRepository')]
  12. #[ORM\Table(name'item_photo')]
  13. class ItemPhoto
  14. {
  15.     #[ORM\Column(type'boolean')]
  16.     private bool $isDeleted false;
  17.     #[ORM\Column(name'createdAt'type'datetime')]
  18.     private DateTime $createdAt;
  19.     #[ORM\ManyToOne(targetEntityItem::class, inversedBy'itemPhotos')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private Item $item;
  22.     #[ORM\Id]
  23.     #[ORM\Column(name'id'type'integer')]
  24.     #[ORM\GeneratedValue(strategy'AUTO')]
  25.     private ?int $id null;
  26.     /**
  27.      * @Vich\UploadableField(mapping="itemPhoto", fileNameProperty="itemPhotoFileName", size="itemPhotoFileSize")
  28.      */
  29.     #[Assert\File(maxSize'1024k')]
  30.     private ?File $itemPhotoFile null;
  31.     #[ORM\Column(type'string'length255nullabletrue)]
  32.     private ?string $itemPhotoFileName null;
  33.     #[ORM\Column(type'integer'nullabletrue)]
  34.     private ?int $itemPhotoFileSize null;
  35.     #[ORM\Column(type'datetime'nullabletrue)]
  36.     private ?DateTime $itemPhotoFileUpdatedAt;
  37.     public function __construct()
  38.     {
  39.         $this->createdAt = new DateTime();
  40.     }
  41.     public function __toString()
  42.     {
  43.         return "#" $this->id " - " $this->itemPhotoFileName;
  44.     }
  45.     /**
  46.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  47.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  48.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  49.      * must be able to accept an instance of 'File' as the bundle will inject one here
  50.      * during Doctrine hydration.
  51.      *
  52.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  53.      */
  54.     public function setItemPhotoFile(File $image null)
  55.     {
  56.         $this->itemPhotoFile $image;
  57.         if (null !== $image) {
  58.             // It is required that at least one field changes if you are using doctrine
  59.             // otherwise the event listeners won't be called and the file is lost
  60.             $this->itemPhotoFileUpdatedAt = new \DateTime();
  61.         }
  62.     }
  63.     public function getItemPhotoFile()
  64.     {
  65.         return $this->itemPhotoFile;
  66.     }
  67.     /**
  68.      * Get id
  69.      *
  70.      * @return int
  71.      */
  72.     public function getId()
  73.     {
  74.         return $this->id;
  75.     }
  76.     /**
  77.      * Set createdAt
  78.      *
  79.      * @param DateTime $createdAt
  80.      *
  81.      * @return ItemPhoto
  82.      */
  83.     public function setCreatedAt($createdAt)
  84.     {
  85.         $this->createdAt $createdAt;
  86.         return $this;
  87.     }
  88.     /**
  89.      * Get createdAt
  90.      *
  91.      * @return DateTime
  92.      */
  93.     public function getCreatedAt()
  94.     {
  95.         return $this->createdAt;
  96.     }
  97.     /**
  98.      * Set itemPhotoFileName
  99.      *
  100.      * @param string $itemPhotoFileName
  101.      *
  102.      * @return ItemPhoto
  103.      */
  104.     public function setItemPhotoFileName($itemPhotoFileName)
  105.     {
  106.         $this->itemPhotoFileName $itemPhotoFileName;
  107.         return $this;
  108.     }
  109.     /**
  110.      * Get itemPhotoFileName
  111.      *
  112.      * @return string
  113.      */
  114.     public function getItemPhotoFileName()
  115.     {
  116.         return $this->itemPhotoFileName;
  117.     }
  118.     /**
  119.      * Set itemPhotoFileSize
  120.      *
  121.      * @param integer $itemPhotoFileSize
  122.      *
  123.      * @return ItemPhoto
  124.      */
  125.     public function setItemPhotoFileSize($itemPhotoFileSize)
  126.     {
  127.         $this->itemPhotoFileSize $itemPhotoFileSize;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get itemPhotoFileSize
  132.      *
  133.      * @return integer
  134.      */
  135.     public function getItemPhotoFileSize()
  136.     {
  137.         return $this->itemPhotoFileSize;
  138.     }
  139.     /**
  140.      * Set itemPhotoFileUpdatedAt
  141.      *
  142.      * @param DateTime $itemPhotoFileUpdatedAt
  143.      *
  144.      * @return ItemPhoto
  145.      */
  146.     public function setItemPhotoFileUpdatedAt($itemPhotoFileUpdatedAt)
  147.     {
  148.         $this->itemPhotoFileUpdatedAt $itemPhotoFileUpdatedAt;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get itemPhotoFileUpdatedAt
  153.      *
  154.      * @return DateTime
  155.      */
  156.     public function getItemPhotoFileUpdatedAt()
  157.     {
  158.         return $this->itemPhotoFileUpdatedAt;
  159.     }
  160.     /**
  161.      * Set item
  162.      *
  163.      * @param \App\Entity\Item $item
  164.      *
  165.      * @return ItemPhoto
  166.      */
  167.     public function setItem(\App\Entity\Item $item)
  168.     {
  169.         $this->item $item;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Get item
  174.      *
  175.      * @return \App\Entity\Item
  176.      */
  177.     public function getItem()
  178.     {
  179.         return $this->item;
  180.     }
  181.     /**
  182.      * Set isDeleted
  183.      *
  184.      * @param boolean $isDeleted
  185.      *
  186.      * @return ItemPhoto
  187.      */
  188.     public function setIsDeleted($isDeleted)
  189.     {
  190.         $this->isDeleted $isDeleted;
  191.         return $this;
  192.     }
  193.     /**
  194.      * Get isDeleted
  195.      *
  196.      * @return boolean
  197.      */
  198.     public function getIsDeleted()
  199.     {
  200.         return $this->isDeleted;
  201.     }
  202. }