src/Entity/Category.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\UpdatableInterface;
  4. use App\Entity\Traits\UpdatableTrait;
  5. use App\Repository\CategoryRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @Vich\Uploadable
  17.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  18.  */
  19. class Category implements TranslatableInterfaceUpdatableInterface
  20. {
  21.     use TranslatableTrait;
  22.     use UpdatableTrait;
  23.     public function __call($method$arguments)
  24.     {
  25.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  26.     }
  27.     public function __get($name)
  28.     {
  29.         $method 'get' ucfirst($name);
  30.         $arguments = [];
  31.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  32.     }
  33.     public function __toString()
  34.     {
  35.         return "#" $this->id " " $this->getTitle();
  36.     }
  37.     /**
  38.      * @ORM\Id
  39.      * @ORM\GeneratedValue
  40.      * @ORM\Column(type="integer")
  41.      */
  42.     private $id;
  43.     /**
  44.      * @Gedmo\SortablePosition()
  45.      * @ORM\Column(type="integer", nullable=true)
  46.      */
  47.     private $position;
  48.     /**
  49.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  50.      * @Vich\UploadableField(mapping="category", fileNameProperty="categoryFileName", size="categoryFileSize")
  51.      * @Assert\Expression("this.getCategoryFile() or this.getCategoryFileName()", message = "Veuillez sélectionner un fichier")
  52.      * @Assert\File(
  53.      *     maxSize = "1200k"
  54.      * )
  55.      *
  56.      * @var File
  57.      */
  58.     private $categoryFile;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      *
  62.      * @var string
  63.      */
  64.     private $categoryFileName;
  65.     /**
  66.      * @ORM\Column(type="integer", nullable=true)
  67.      *
  68.      * @var integer
  69.      */
  70.     private $categoryFileSize;
  71.     /**
  72.      * @ORM\Column(type="datetime", nullable=true)
  73.      *
  74.      * @var \DateTime
  75.      */
  76.     private $categoryFileUpdatedAt;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="category")
  79.      */
  80.     private $products;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=SubCategory::class, mappedBy="category")
  83.      */
  84.     private $subCategories;
  85.     /**
  86.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  87.      * @Vich\UploadableField(mapping="category1", fileNameProperty="category1FileName", size="category1FileSize")
  88.      * @Assert\Expression("this.getCategory1File() or this.getCategory1FileName()", message = "Veuillez sélectionner un fichier")
  89.      * @Assert\File(
  90.      *     maxSize = "1200k"
  91.      * )
  92.      *
  93.      * @var File
  94.      */
  95.     private $category1File;
  96.     /**
  97.      * @ORM\Column(type="string", length=255, nullable=true)
  98.      *
  99.      * @var string
  100.      */
  101.     private $category1FileName;
  102.     /**
  103.      * @ORM\Column(type="integer", nullable=true)
  104.      *
  105.      * @var integer
  106.      */
  107.     private $category1FileSize;
  108.     /**
  109.      * @ORM\Column(type="datetime", nullable=true)
  110.      *
  111.      * @var \DateTime
  112.      */
  113.     private $category1FileUpdatedAt;
  114.     /**
  115.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  116.      * @Vich\UploadableField(mapping="categoryIcon", fileNameProperty="categoryIconFileName", size="categoryIconFileSize")
  117.      * @Assert\Expression("this.getCategoryIconFile() or this.getCategoryIconFileName()", message = "Veuillez sélectionner un fichier")
  118.      * @Assert\File(
  119.      *     maxSize = "1200k"
  120.      * )
  121.      *
  122.      * @var File
  123.      */
  124.     private $categoryIconFile;
  125.     /**
  126.      * @ORM\Column(type="string", length=255, nullable=true)
  127.      *
  128.      * @var string
  129.      */
  130.     private $categoryIconFileName;
  131.     /**
  132.      * @ORM\Column(type="integer", nullable=true)
  133.      *
  134.      * @var integer
  135.      */
  136.     private $categoryIconFileSize;
  137.     /**
  138.      * @ORM\Column(type="datetime", nullable=true)
  139.      *
  140.      * @var \DateTime
  141.      */
  142.     private $categoryIconFileUpdatedAt;
  143.     /**
  144.      * @ORM\OneToMany(targetEntity=Publication::class, mappedBy="category")
  145.      */
  146.     private $publications;
  147.     /**
  148.      * @ORM\OneToMany(targetEntity=CategoryPhaseEvolution::class, mappedBy="category")
  149.      */
  150.     private $categoryPhaseEvolutions;
  151.     /**
  152.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  153.      * @Vich\UploadableField(mapping="categoryIcon1", fileNameProperty="categoryIcon1FileName", size="categoryIcon1FileSize")
  154.      * @Assert\Expression("this.getCategoryIcon1File() or this.getCategoryIcon1FileName()", message = "Veuillez sélectionner un fichier")
  155.      * @Assert\File(
  156.      *     maxSize = "1200k"
  157.      * )
  158.      *
  159.      * @var File
  160.      */
  161.     private $categoryIcon1File;
  162.     /**
  163.      * @ORM\Column(type="string", length=255, nullable=true)
  164.      *
  165.      * @var string
  166.      */
  167.     private $categoryIcon1FileName;
  168.     /**
  169.      * @ORM\Column(type="integer", nullable=true)
  170.      *
  171.      * @var integer
  172.      */
  173.     private $categoryIcon1FileSize;
  174.     /**
  175.      * @ORM\Column(type="datetime", nullable=true)
  176.      *
  177.      * @var \DateTime
  178.      */
  179.     private $categoryIcon1FileUpdatedAt;
  180.     /**
  181.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  182.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  183.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  184.      * must be able to accept an instance of 'File' as the bundle will inject one here
  185.      * during Doctrine hydration.
  186.      *
  187.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  188.      */
  189.     public function setCategoryIcon1File(File $image null)
  190.     {
  191.         $this->categoryIcon1File $image;
  192.         if (null !== $image) {
  193.             // It is required that at least one field changes if you are using doctrine
  194.             // otherwise the event listeners won't be called and the file is lost
  195.             $this->categoryIcon1FileUpdatedAt = new \DateTimeImmutable();
  196.         }
  197.     }
  198.     public function getCategoryIcon1File()
  199.     {
  200.         return $this->categoryIcon1File;
  201.     }
  202.     public function getCategoryIcon1FileName(): ?string
  203.     {
  204.         return $this->categoryIcon1FileName;
  205.     }
  206.     public function setCategoryIcon1FileName(?string $categoryIcon1FileName): self
  207.     {
  208.         $this->categoryIcon1FileName $categoryIcon1FileName;
  209.         return $this;
  210.     }
  211.     public function getCategoryIcon1FileSize(): ?int
  212.     {
  213.         return $this->categoryIcon1FileSize;
  214.     }
  215.     public function setCategoryIcon1FileSize(?int $categoryIcon1FileSize): self
  216.     {
  217.         $this->categoryIcon1FileSize $categoryIcon1FileSize;
  218.         return $this;
  219.     }
  220.     public function getCategoryIcon1FileUpdatedAt(): ?\DateTimeInterface
  221.     {
  222.         return $this->categoryIcon1FileUpdatedAt;
  223.     }
  224.     public function setCategoryIcon1FileUpdatedAt(?\DateTimeInterface $categoryIcon1FileUpdatedAt): self
  225.     {
  226.         $this->categoryIcon1FileUpdatedAt $categoryIcon1FileUpdatedAt;
  227.         return $this;
  228.     }
  229.     /**
  230.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  231.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  232.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  233.      * must be able to accept an instance of 'File' as the bundle will inject one here
  234.      * during Doctrine hydration.
  235.      *
  236.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  237.      */
  238.     public function setCategoryIconFile(File $image null)
  239.     {
  240.         $this->categoryIconFile $image;
  241.         if (null !== $image) {
  242.             // It is required that at least one field changes if you are using doctrine
  243.             // otherwise the event listeners won't be called and the file is lost
  244.             $this->categoryIconFileUpdatedAt = new \DateTimeImmutable();
  245.         }
  246.     }
  247.     public function getCategoryIconFile()
  248.     {
  249.         return $this->categoryIconFile;
  250.     }
  251.     public function getCategoryIconFileName(): ?string
  252.     {
  253.         return $this->categoryIconFileName;
  254.     }
  255.     public function setCategoryIconFileName(?string $categoryIconFileName): self
  256.     {
  257.         $this->categoryIconFileName $categoryIconFileName;
  258.         return $this;
  259.     }
  260.     public function getCategoryIconFileSize(): ?int
  261.     {
  262.         return $this->categoryIconFileSize;
  263.     }
  264.     public function setCategoryIconFileSize(?int $categoryIconFileSize): self
  265.     {
  266.         $this->categoryIconFileSize $categoryIconFileSize;
  267.         return $this;
  268.     }
  269.     public function getCategoryIconFileUpdatedAt(): ?\DateTimeInterface
  270.     {
  271.         return $this->categoryIconFileUpdatedAt;
  272.     }
  273.     public function setCategoryIconFileUpdatedAt(?\DateTimeInterface $categoryIconFileUpdatedAt): self
  274.     {
  275.         $this->categoryIconFileUpdatedAt $categoryIconFileUpdatedAt;
  276.         return $this;
  277.     }
  278.     /**
  279.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  280.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  281.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  282.      * must be able to accept an instance of 'File' as the bundle will inject one here
  283.      * during Doctrine hydration.
  284.      *
  285.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  286.      */
  287.     public function setCategory1File(File $image null)
  288.     {
  289.         $this->category1File $image;
  290.         if (null !== $image) {
  291.             // It is required that at least one field changes if you are using doctrine
  292.             // otherwise the event listeners won't be called and the file is lost
  293.             $this->category1FileUpdatedAt = new \DateTimeImmutable();
  294.         }
  295.     }
  296.     public function getCategory1File()
  297.     {
  298.         return $this->category1File;
  299.     }
  300.     public function getCategory1FileName(): ?string
  301.     {
  302.         return $this->category1FileName;
  303.     }
  304.     public function setCategory1FileName(?string $category1FileName): self
  305.     {
  306.         $this->category1FileName $category1FileName;
  307.         return $this;
  308.     }
  309.     public function getCategory1FileSize(): ?int
  310.     {
  311.         return $this->category1FileSize;
  312.     }
  313.     public function setCategory1FileSize(?int $category1FileSize): self
  314.     {
  315.         $this->category1FileSize $category1FileSize;
  316.         return $this;
  317.     }
  318.     public function getCategory1FileUpdatedAt(): ?\DateTimeInterface
  319.     {
  320.         return $this->category1FileUpdatedAt;
  321.     }
  322.     public function setCategory1FileUpdatedAt(?\DateTimeInterface $category1FileUpdatedAt): self
  323.     {
  324.         $this->category1FileUpdatedAt $category1FileUpdatedAt;
  325.         return $this;
  326.     }
  327.     public function __construct()
  328.     {
  329.         $this->products = new ArrayCollection();
  330.         $this->subCategories = new ArrayCollection();
  331.         $this->publications = new ArrayCollection();
  332.         $this->categoryPhaseEvolutions = new ArrayCollection();
  333.     }
  334.     /**
  335.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  336.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  337.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  338.      * must be able to accept an instance of 'File' as the bundle will inject one here
  339.      * during Doctrine hydration.
  340.      *
  341.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  342.      */
  343.     public function setCategoryFile(File $image null)
  344.     {
  345.         $this->categoryFile $image;
  346.         if (null !== $image) {
  347.             // It is required that at least one field changes if you are using doctrine
  348.             // otherwise the event listeners won't be called and the file is lost
  349.             $this->categoryFileUpdatedAt = new \DateTimeImmutable();
  350.         }
  351.     }
  352.     public function getCategoryFile()
  353.     {
  354.         return $this->categoryFile;
  355.     }
  356.     public function getCategoryFileName(): ?string
  357.     {
  358.         return $this->categoryFileName;
  359.     }
  360.     public function setCategoryFileName(?string $categoryFileName): self
  361.     {
  362.         $this->categoryFileName $categoryFileName;
  363.         return $this;
  364.     }
  365.     public function getCategoryFileSize(): ?int
  366.     {
  367.         return $this->categoryFileSize;
  368.     }
  369.     public function setCategoryFileSize(?int $categoryFileSize): self
  370.     {
  371.         $this->categoryFileSize $categoryFileSize;
  372.         return $this;
  373.     }
  374.     public function getCategoryFileUpdatedAt(): ?\DateTimeInterface
  375.     {
  376.         return $this->categoryFileUpdatedAt;
  377.     }
  378.     public function setCategoryFileUpdatedAt(?\DateTimeInterface $categoryFileUpdatedAt): self
  379.     {
  380.         $this->categoryFileUpdatedAt $categoryFileUpdatedAt;
  381.         return $this;
  382.     }
  383.     public function getId(): ?int
  384.     {
  385.         return $this->id;
  386.     }
  387.     public function getPosition(): ?int
  388.     {
  389.         return $this->position;
  390.     }
  391.     public function setPosition(?int $position): self
  392.     {
  393.         $this->position $position;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, Product>
  398.      */
  399.     public function getProducts(): Collection
  400.     {
  401.         return $this->products;
  402.     }
  403.     public function addProduct(Product $product): self
  404.     {
  405.         if (!$this->products->contains($product)) {
  406.             $this->products[] = $product;
  407.             $product->setCategory($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeProduct(Product $product): self
  412.     {
  413.         if ($this->products->removeElement($product)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($product->getCategory() === $this) {
  416.                 $product->setCategory(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, SubCategory>
  423.      */
  424.     public function getSubCategories(): Collection
  425.     {
  426.         return $this->subCategories;
  427.     }
  428.     public function addSubCategory(SubCategory $subCategory): self
  429.     {
  430.         if (!$this->subCategories->contains($subCategory)) {
  431.             $this->subCategories[] = $subCategory;
  432.             $subCategory->setCategory($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeSubCategory(SubCategory $subCategory): self
  437.     {
  438.         if ($this->subCategories->removeElement($subCategory)) {
  439.             // set the owning side to null (unless already changed)
  440.             if ($subCategory->getCategory() === $this) {
  441.                 $subCategory->setCategory(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Collection<int, Publication>
  448.      */
  449.     public function getPublications(): Collection
  450.     {
  451.         return $this->publications;
  452.     }
  453.     public function addPublication(Publication $publication): self
  454.     {
  455.         if (!$this->publications->contains($publication)) {
  456.             $this->publications[] = $publication;
  457.             $publication->setCategory($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removePublication(Publication $publication): self
  462.     {
  463.         if ($this->publications->removeElement($publication)) {
  464.             // set the owning side to null (unless already changed)
  465.             if ($publication->getCategory() === $this) {
  466.                 $publication->setCategory(null);
  467.             }
  468.         }
  469.         return $this;
  470.     }
  471.     /**
  472.      * @return Collection<int, CategoryPhaseEvolution>
  473.      */
  474.     public function getCategoryPhaseEvolutions(): Collection
  475.     {
  476.         return $this->categoryPhaseEvolutions;
  477.     }
  478.     public function addCategoryPhaseEvolution(CategoryPhaseEvolution $categoryPhaseEvolution): self
  479.     {
  480.         if (!$this->categoryPhaseEvolutions->contains($categoryPhaseEvolution)) {
  481.             $this->categoryPhaseEvolutions[] = $categoryPhaseEvolution;
  482.             $categoryPhaseEvolution->setCategory($this);
  483.         }
  484.         return $this;
  485.     }
  486.     public function removeCategoryPhaseEvolution(CategoryPhaseEvolution $categoryPhaseEvolution): self
  487.     {
  488.         if ($this->categoryPhaseEvolutions->removeElement($categoryPhaseEvolution)) {
  489.             // set the owning side to null (unless already changed)
  490.             if ($categoryPhaseEvolution->getCategory() === $this) {
  491.                 $categoryPhaseEvolution->setCategory(null);
  492.             }
  493.         }
  494.         return $this;
  495.     }
  496. }