src/Entity/Categories.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoriesRepository;
  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 Symfony\Component\Security\Core\User\UserInterface;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassCategoriesRepository::class)]
  12. #[Vich\Uploadable]
  13. class Categories
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[Vich\UploadableField(mapping'products'fileNameProperty'imageName')]
  20.     private ?File $imageFile null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?string $imageName null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $name null;
  25.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'categories')]
  26.     private ?self $parent null;
  27.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  28.     private Collection $categories;
  29.     #[ORM\OneToMany(mappedBy'categories'targetEntityImagesCategories::class, orphanRemovaltrue)]
  30.     private Collection $imagesCategories;
  31.     public function __construct()
  32.     {
  33.         $this->categories = new ArrayCollection();
  34.         $this->imagesCategories = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     /**
  41.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  42.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  43.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  44.      * must be able to accept an instance of 'File' as the bundle will inject one here
  45.      * during Doctrine hydration.
  46.      *
  47.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  48.      */
  49.     public function setImageFile(?File $imageFile null): void
  50.     {
  51.         $this->imageFile $imageFile;
  52.         if (null !== $imageFile) {
  53.             // It is required that at least one field changes if you are using doctrine
  54.             // otherwise the event listeners won't be called and the file is lost
  55.             $this->updatedAt = new \DateTimeImmutable();
  56.         }
  57.     }
  58.     public function getImageFile(): ?File
  59.     {
  60.         return $this->imageFile;
  61.     }
  62.     public function setImageName(?string $imageName): void
  63.     {
  64.         $this->imageName $imageName;
  65.     }
  66.     public function getImageName(): ?string
  67.     {
  68.         return $this->imageName;
  69.     }
  70.     public function getName(): ?string
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function setName(string $name): self
  75.     {
  76.         $this->name $name;
  77.         return $this;
  78.     }
  79.     public function getParent(): ?self
  80.     {
  81.         return $this->parent;
  82.     }
  83.     public function setParent(?self $parent): self
  84.     {
  85.         $this->parent $parent;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, self>
  90.      */
  91.     public function getCategories(): Collection
  92.     {
  93.         return $this->categories;
  94.     }
  95.     public function addCategory(self $category): self
  96.     {
  97.         if (!$this->categories->contains($category)) {
  98.             $this->categories->add($category);
  99.             $category->setParent($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeCategory(self $category): self
  104.     {
  105.         if ($this->categories->removeElement($category)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($category->getParent() === $this) {
  108.                 $category->setParent(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Collection<int, ImagesCategories>
  115.      */
  116.     public function getImagesCategories(): Collection
  117.     {
  118.         return $this->imagesCategories;
  119.     }
  120.     public function addImagesCategory(ImagesCategories $imagesCategory): self
  121.     {
  122.         if (!$this->imagesCategories->contains($imagesCategory)) {
  123.             $this->imagesCategories->add($imagesCategory);
  124.             $imagesCategory->setCategories($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeImagesCategory(ImagesCategories $imagesCategory): self
  129.     {
  130.         if ($this->imagesCategories->removeElement($imagesCategory)) {
  131.             // set the owning side to null (unless already changed)
  132.             if ($imagesCategory->getCategories() === $this) {
  133.                 $imagesCategory->setCategories(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138. }