src/Entity/Categories.php line 16
<?php
namespace App\Entity;
use App\Repository\CategoriesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: CategoriesRepository::class)]
#[Vich\Uploadable]
class Categories
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Vich\UploadableField(mapping: 'products', fileNameProperty: 'imageName')]
private ?File $imageFile = null;
#[ORM\Column(nullable: true)]
private ?string $imageName = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'categories')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $categories;
#[ORM\OneToMany(mappedBy: 'categories', targetEntity: ImagesCategories::class, orphanRemoval: true)]
private Collection $imagesCategories;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->imagesCategories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(self $category): self
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setParent($this);
}
return $this;
}
public function removeCategory(self $category): self
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getParent() === $this) {
$category->setParent(null);
}
}
return $this;
}
/**
* @return Collection<int, ImagesCategories>
*/
public function getImagesCategories(): Collection
{
return $this->imagesCategories;
}
public function addImagesCategory(ImagesCategories $imagesCategory): self
{
if (!$this->imagesCategories->contains($imagesCategory)) {
$this->imagesCategories->add($imagesCategory);
$imagesCategory->setCategories($this);
}
return $this;
}
public function removeImagesCategory(ImagesCategories $imagesCategory): self
{
if ($this->imagesCategories->removeElement($imagesCategory)) {
// set the owning side to null (unless already changed)
if ($imagesCategory->getCategories() === $this) {
$imagesCategory->setCategories(null);
}
}
return $this;
}
}