src/Entity/Category.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  10. #[Vich\Uploadable]
  11. class Category
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private ?int $id null;
  17.     #[ORM\Column(type'string'length255)]
  18.     private ?string $name null;
  19.     #[ORM\ManyToMany(targetEntityProduct::class, inversedBy'categories')]
  20.     private Collection $products;
  21.     #[Vich\UploadableField(mapping'category_image'fileNameProperty'imageName')]
  22.     private ?File $imageFile null;
  23.     #[ORM\Column(type'string'length255nullabletrue)]
  24.     private ?string $imageName null;
  25.     #[ORM\Column(type'datetime'nullabletrue)]
  26.     private ?\DateTimeInterface $updatedAt null;
  27.     public function __construct()
  28.     {
  29.         $this->products = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getName(): ?string
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function setName(string $name): self
  40.     {
  41.         $this->name $name;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return Collection<int, Product>
  46.      */
  47.     public function getProducts(): Collection
  48.     {
  49.         return $this->products;
  50.     }
  51.     public function addProduct(Product $product): self
  52.     {
  53.         if (!$this->products->contains($product)) {
  54.             $this->products[] = $product;
  55.         }
  56.         return $this;
  57.     }
  58.     public function removeProduct(Product $product): self
  59.     {
  60.         $this->products->removeElement($product);
  61.         return $this;
  62.     }
  63.     public function getImageFile(): ?File
  64.     {
  65.         return $this->imageFile;
  66.     }
  67.     public function setImageFile(?File $imageFile): self
  68.     {
  69.         $this->imageFile $imageFile;
  70.         if ($imageFile) {
  71.             $this->updatedAt = new \DateTimeImmutable();
  72.         }
  73.         return $this;
  74.     }
  75.     public function getImageName(): ?string
  76.     {
  77.         return $this->imageName;
  78.     }
  79.     public function setImageName(?string $imageName): self
  80.     {
  81.         $this->imageName $imageName;
  82.         return $this;
  83.     }
  84.     public function getUpdatedAt(): ?\DateTimeInterface
  85.     {
  86.         return $this->updatedAt;
  87.     }
  88.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  89.     {
  90.         $this->updatedAt $updatedAt;
  91.         return $this;
  92.     }
  93. }