<?php
namespace App\Entity;
use App\Entity\Traits\UpdatableInterface;
use App\Entity\Traits\UpdatableTrait;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Vich\Uploadable
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category implements TranslatableInterface, UpdatableInterface
{
use TranslatableTrait;
use UpdatableTrait;
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function __get($name)
{
$method = 'get' . ucfirst($name);
$arguments = [];
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function __toString()
{
return "#" . $this->id . " " . $this->getTitle();
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Gedmo\SortablePosition()
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="category", fileNameProperty="categoryFileName", size="categoryFileSize")
* @Assert\Expression("this.getCategoryFile() or this.getCategoryFileName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
*
* @var File
*/
private $categoryFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $categoryFileName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $categoryFileSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $categoryFileUpdatedAt;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="category")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity=SubCategory::class, mappedBy="category")
*/
private $subCategories;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="category1", fileNameProperty="category1FileName", size="category1FileSize")
* @Assert\Expression("this.getCategory1File() or this.getCategory1FileName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
*
* @var File
*/
private $category1File;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $category1FileName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $category1FileSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $category1FileUpdatedAt;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="categoryIcon", fileNameProperty="categoryIconFileName", size="categoryIconFileSize")
* @Assert\Expression("this.getCategoryIconFile() or this.getCategoryIconFileName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
*
* @var File
*/
private $categoryIconFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $categoryIconFileName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $categoryIconFileSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $categoryIconFileUpdatedAt;
/**
* @ORM\OneToMany(targetEntity=Publication::class, mappedBy="category")
*/
private $publications;
/**
* @ORM\OneToMany(targetEntity=CategoryPhaseEvolution::class, mappedBy="category")
*/
private $categoryPhaseEvolutions;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="categoryIcon1", fileNameProperty="categoryIcon1FileName", size="categoryIcon1FileSize")
* @Assert\Expression("this.getCategoryIcon1File() or this.getCategoryIcon1FileName()", message = "Veuillez sélectionner un fichier")
* @Assert\File(
* maxSize = "1200k"
* )
*
* @var File
*/
private $categoryIcon1File;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $categoryIcon1FileName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var integer
*/
private $categoryIcon1FileSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $categoryIcon1FileUpdatedAt;
/**
* 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 $image
*/
public function setCategoryIcon1File(File $image = null)
{
$this->categoryIcon1File = $image;
if (null !== $image) {
// 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->categoryIcon1FileUpdatedAt = new \DateTimeImmutable();
}
}
public function getCategoryIcon1File()
{
return $this->categoryIcon1File;
}
public function getCategoryIcon1FileName(): ?string
{
return $this->categoryIcon1FileName;
}
public function setCategoryIcon1FileName(?string $categoryIcon1FileName): self
{
$this->categoryIcon1FileName = $categoryIcon1FileName;
return $this;
}
public function getCategoryIcon1FileSize(): ?int
{
return $this->categoryIcon1FileSize;
}
public function setCategoryIcon1FileSize(?int $categoryIcon1FileSize): self
{
$this->categoryIcon1FileSize = $categoryIcon1FileSize;
return $this;
}
public function getCategoryIcon1FileUpdatedAt(): ?\DateTimeInterface
{
return $this->categoryIcon1FileUpdatedAt;
}
public function setCategoryIcon1FileUpdatedAt(?\DateTimeInterface $categoryIcon1FileUpdatedAt): self
{
$this->categoryIcon1FileUpdatedAt = $categoryIcon1FileUpdatedAt;
return $this;
}
/**
* 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 $image
*/
public function setCategoryIconFile(File $image = null)
{
$this->categoryIconFile = $image;
if (null !== $image) {
// 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->categoryIconFileUpdatedAt = new \DateTimeImmutable();
}
}
public function getCategoryIconFile()
{
return $this->categoryIconFile;
}
public function getCategoryIconFileName(): ?string
{
return $this->categoryIconFileName;
}
public function setCategoryIconFileName(?string $categoryIconFileName): self
{
$this->categoryIconFileName = $categoryIconFileName;
return $this;
}
public function getCategoryIconFileSize(): ?int
{
return $this->categoryIconFileSize;
}
public function setCategoryIconFileSize(?int $categoryIconFileSize): self
{
$this->categoryIconFileSize = $categoryIconFileSize;
return $this;
}
public function getCategoryIconFileUpdatedAt(): ?\DateTimeInterface
{
return $this->categoryIconFileUpdatedAt;
}
public function setCategoryIconFileUpdatedAt(?\DateTimeInterface $categoryIconFileUpdatedAt): self
{
$this->categoryIconFileUpdatedAt = $categoryIconFileUpdatedAt;
return $this;
}
/**
* 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 $image
*/
public function setCategory1File(File $image = null)
{
$this->category1File = $image;
if (null !== $image) {
// 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->category1FileUpdatedAt = new \DateTimeImmutable();
}
}
public function getCategory1File()
{
return $this->category1File;
}
public function getCategory1FileName(): ?string
{
return $this->category1FileName;
}
public function setCategory1FileName(?string $category1FileName): self
{
$this->category1FileName = $category1FileName;
return $this;
}
public function getCategory1FileSize(): ?int
{
return $this->category1FileSize;
}
public function setCategory1FileSize(?int $category1FileSize): self
{
$this->category1FileSize = $category1FileSize;
return $this;
}
public function getCategory1FileUpdatedAt(): ?\DateTimeInterface
{
return $this->category1FileUpdatedAt;
}
public function setCategory1FileUpdatedAt(?\DateTimeInterface $category1FileUpdatedAt): self
{
$this->category1FileUpdatedAt = $category1FileUpdatedAt;
return $this;
}
public function __construct()
{
$this->products = new ArrayCollection();
$this->subCategories = new ArrayCollection();
$this->publications = new ArrayCollection();
$this->categoryPhaseEvolutions = new ArrayCollection();
}
/**
* 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 $image
*/
public function setCategoryFile(File $image = null)
{
$this->categoryFile = $image;
if (null !== $image) {
// 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->categoryFileUpdatedAt = new \DateTimeImmutable();
}
}
public function getCategoryFile()
{
return $this->categoryFile;
}
public function getCategoryFileName(): ?string
{
return $this->categoryFileName;
}
public function setCategoryFileName(?string $categoryFileName): self
{
$this->categoryFileName = $categoryFileName;
return $this;
}
public function getCategoryFileSize(): ?int
{
return $this->categoryFileSize;
}
public function setCategoryFileSize(?int $categoryFileSize): self
{
$this->categoryFileSize = $categoryFileSize;
return $this;
}
public function getCategoryFileUpdatedAt(): ?\DateTimeInterface
{
return $this->categoryFileUpdatedAt;
}
public function setCategoryFileUpdatedAt(?\DateTimeInterface $categoryFileUpdatedAt): self
{
$this->categoryFileUpdatedAt = $categoryFileUpdatedAt;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCategory($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
/**
* @return Collection<int, SubCategory>
*/
public function getSubCategories(): Collection
{
return $this->subCategories;
}
public function addSubCategory(SubCategory $subCategory): self
{
if (!$this->subCategories->contains($subCategory)) {
$this->subCategories[] = $subCategory;
$subCategory->setCategory($this);
}
return $this;
}
public function removeSubCategory(SubCategory $subCategory): self
{
if ($this->subCategories->removeElement($subCategory)) {
// set the owning side to null (unless already changed)
if ($subCategory->getCategory() === $this) {
$subCategory->setCategory(null);
}
}
return $this;
}
/**
* @return Collection<int, Publication>
*/
public function getPublications(): Collection
{
return $this->publications;
}
public function addPublication(Publication $publication): self
{
if (!$this->publications->contains($publication)) {
$this->publications[] = $publication;
$publication->setCategory($this);
}
return $this;
}
public function removePublication(Publication $publication): self
{
if ($this->publications->removeElement($publication)) {
// set the owning side to null (unless already changed)
if ($publication->getCategory() === $this) {
$publication->setCategory(null);
}
}
return $this;
}
/**
* @return Collection<int, CategoryPhaseEvolution>
*/
public function getCategoryPhaseEvolutions(): Collection
{
return $this->categoryPhaseEvolutions;
}
public function addCategoryPhaseEvolution(CategoryPhaseEvolution $categoryPhaseEvolution): self
{
if (!$this->categoryPhaseEvolutions->contains($categoryPhaseEvolution)) {
$this->categoryPhaseEvolutions[] = $categoryPhaseEvolution;
$categoryPhaseEvolution->setCategory($this);
}
return $this;
}
public function removeCategoryPhaseEvolution(CategoryPhaseEvolution $categoryPhaseEvolution): self
{
if ($this->categoryPhaseEvolutions->removeElement($categoryPhaseEvolution)) {
// set the owning side to null (unless already changed)
if ($categoryPhaseEvolution->getCategory() === $this) {
$categoryPhaseEvolution->setCategory(null);
}
}
return $this;
}
}