src/Entity/Category.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use DateTime;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  11. #[ORM\Table(name'category')]
  12. #[Vich\Uploadable]
  13. class Category {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue(strategy"AUTO")]
  16.     #[ORM\Column(typeTypes::INTEGER)]
  17.     private ?int $id;
  18.     #[ORM\Column(typeTypes::BOOLEAN)]
  19.     private bool $isDeleted false;
  20.     #[ORM\Column(typeTypes::STRINGlength255)]
  21.     private ?string $name;
  22.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  23.     private ?string $categoryFileName;
  24.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  25.     private ?int $categoryFileSize;
  26.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  27.     private ?DateTime $categoryFileUpdatedAt;
  28.     /**
  29.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  30.      */
  31.     #[Vich\UploadableField(mapping:'category'fileNameProperty:'categoryFileName'size:'categoryFileSize')]
  32.     private? File $categoryFile;
  33.     public function __toString() {
  34.         return "#" $this->id " - " $this->name;
  35.     }
  36.     public function getId(): ?int {
  37.         return $this->id;
  38.     }
  39.     public function setIsDeleted(bool $isDeleted): static
  40.     {
  41.         $this->isDeleted $isDeleted;
  42.         return $this;
  43.     }
  44.     public function getIsDeleted(): bool
  45.     {
  46.         return $this->isDeleted;
  47.     }
  48.     public function setName(?string $name): static {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setCategoryFileName(?string $categoryFileName): static
  57.     {
  58.         $this->categoryFileName $categoryFileName;
  59.         return $this;
  60.     }
  61.     public function getCategoryFileName(): ?string {
  62.         return $this->categoryFileName;
  63.     }
  64.     public function setCategoryFileSize(?int $categoryFileSize): static {
  65.         $this->categoryFileSize $categoryFileSize;
  66.         return $this;
  67.     }
  68.     public function getCategoryFileSize(): ?int {
  69.         return $this->categoryFileSize;
  70.     }
  71.     public function setCategoryFileUpdatedAt(DateTime $categoryFileUpdatedAt): static {
  72.         $this->categoryFileUpdatedAt $categoryFileUpdatedAt;
  73.         return $this;
  74.     }
  75.     public function getCategoryFileUpdatedAt(): DateTime {
  76.         return $this->categoryFileUpdatedAt;
  77.     }
  78.     /**
  79.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  80.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  81.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  82.      * must be able to accept an instance of 'File' as the bundle will inject one here
  83.      * during Doctrine hydration.
  84.      */
  85.     public function setCategoryFile(File|UploadedFile $image null): static {
  86.         $this->categoryFile $image;
  87.         if (null !== $image) {
  88. // It is required that at least one field changes if you are using doctrine
  89. // otherwise the event listeners won't be called and the file is lost
  90.             $this->categoryFileUpdatedAt = new \DateTime();
  91.         }
  92.         return $this;
  93.     }
  94.     public function getCategoryFile(): ?File {
  95.         return $this->categoryFile;
  96.     }
  97. }