src/Entity/SubSubCategory.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubSubCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @Vich\Uploadable
  15.  * @ORM\Entity(repositoryClass=SubSubCategoryRepository::class)
  16.  */
  17. class SubSubCategory implements TranslatableInterface
  18. {
  19.     use TranslatableTrait;
  20.     public function __call($method$arguments)
  21.     {
  22.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  23.     }
  24.     public function __get($name)
  25.     {
  26.         $method 'get' ucfirst($name);
  27.         $arguments = [];
  28.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  29.     }
  30.     public function __toString()
  31.     {
  32.         return "#" $this->id " " $this->getTitle();
  33.     }
  34.     /**
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue
  37.      * @ORM\Column(type="integer")
  38.      */
  39.     private $id;
  40.     /**
  41.      * @Gedmo\SortableGroup()
  42.      * @Assert\NotBlank()
  43.      * @ORM\ManyToOne(targetEntity=SubCategory::class, inversedBy="subSubCategories")
  44.      */
  45.     private $subCategory;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="subSubCategory")
  48.      */
  49.     private $products;
  50.     /**
  51.        * NOTE: This is not a mapped field of entity metadata, just a simple property.
  52.        * @Vich\UploadableField(mapping="subSubCategoryIcon", fileNameProperty="subSubCategoryIconFileName", size="subSubCategoryIconFileSize")
  53.        * @Assert\File(
  54.        *     maxSize = "1200k"
  55.        * )
  56.        *
  57.        * @var File
  58.        */
  59.       private $subSubCategoryIconFile;
  60.       /**
  61.        * @ORM\Column(type="string", length=255, nullable=true)
  62.        *
  63.        * @var string
  64.        */
  65.       private $subSubCategoryIconFileName;
  66.     /**
  67.        * NOTE: This is not a mapped field of entity metadata, just a simple property.
  68.        * @Vich\UploadableField(mapping="subSubCategoryBg", fileNameProperty="subSubCategoryBgFileName", size="subSubCategoryBgFileSize")
  69.        * @Assert\Expression("this.getSubSubCategoryBgFile() or this.getSubSubCategoryBgFileName()", message = "Veuillez sélectionner un fichier")
  70.        * @Assert\File(
  71.        *     maxSize = "1200k"
  72.        * )
  73.        *
  74.        * @var File
  75.        */
  76.       private $subSubCategoryBgFile;
  77.       /**
  78.        * @ORM\Column(type="string", length=255, nullable=true)
  79.        *
  80.        * @var string
  81.        */
  82.       private $subSubCategoryBgFileName;
  83.       /**
  84.        * @ORM\Column(type="integer", nullable=true)
  85.        *
  86.        * @var integer
  87.        */
  88.       private $subSubCategoryBgFileSize;
  89.       /**
  90.        * @ORM\Column(type="datetime", nullable=true)
  91.        *
  92.        * @var \DateTime
  93.        */
  94.       private $subSubCategoryBgFileUpdatedAt;
  95.       /**
  96.        * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  97.        * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  98.        * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  99.        * must be able to accept an instance of 'File' as the bundle will inject one here
  100.        * during Doctrine hydration.
  101.        *
  102.        * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  103.        */
  104.       public function setSubSubCategoryBgFile(File $image null) {
  105.           $this->subSubCategoryBgFile $image;
  106.           if (null !== $image) {
  107.   // It is required that at least one field changes if you are using doctrine
  108.   // otherwise the event listeners won't be called and the file is lost
  109.               $this->subSubCategoryBgFileUpdatedAt = new \DateTimeImmutable();
  110.           }
  111.       }  public function getSubSubCategoryBgFile() {
  112.           return $this->subSubCategoryBgFile;
  113.       }
  114.        public function getSubSubCategoryBgFileName(): ?string
  115.       {
  116.           return $this->subSubCategoryBgFileName;
  117.       }
  118.       public function setSubSubCategoryBgFileName(?string $subSubCategoryBgFileName): self
  119.       {
  120.           $this->subSubCategoryBgFileName $subSubCategoryBgFileName;
  121.           return $this;
  122.       }
  123.       public function getSubSubCategoryBgFileSize(): ?int
  124.       {
  125.           return $this->subSubCategoryBgFileSize;
  126.       }
  127.       public function setSubSubCategoryBgFileSize(?int $subSubCategoryBgFileSize): self
  128.       {
  129.           $this->subSubCategoryBgFileSize $subSubCategoryBgFileSize;
  130.           return $this;
  131.       }
  132.       public function getSubSubCategoryBgFileUpdatedAt(): ?\DateTimeInterface
  133.       {
  134.           return $this->subSubCategoryBgFileUpdatedAt;
  135.       }
  136.       public function setSubSubCategoryBgFileUpdatedAt(?\DateTimeInterface $subSubCategoryBgFileUpdatedAt): self
  137.       {
  138.           $this->subSubCategoryBgFileUpdatedAt $subSubCategoryBgFileUpdatedAt;
  139.           return $this;
  140.       }
  141.       /**
  142.        * @ORM\Column(type="integer", nullable=true)
  143.        *
  144.        * @var integer
  145.        */
  146.       private $subSubCategoryIconFileSize;
  147.       /**
  148.        * @ORM\Column(type="datetime", nullable=true)
  149.        *
  150.        * @var \DateTime
  151.        */
  152.       private $subSubCategoryIconFileUpdatedAt;
  153.       /**
  154.        * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  155.        * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  156.        * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  157.        * must be able to accept an instance of 'File' as the bundle will inject one here
  158.        * during Doctrine hydration.
  159.        *
  160.        * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  161.        */
  162.       public function setSubSubCategoryIconFile(File $image null) {
  163.           $this->subSubCategoryIconFile $image;
  164.           if (null !== $image) {
  165.   // It is required that at least one field changes if you are using doctrine
  166.   // otherwise the event listeners won't be called and the file is lost
  167.               $this->subSubCategoryIconFileUpdatedAt = new \DateTimeImmutable();
  168.           }
  169.       }  public function getSubSubCategoryIconFile() {
  170.           return $this->subSubCategoryIconFile;
  171.       }
  172.        public function getSubSubCategoryIconFileName(): ?string
  173.       {
  174.           return $this->subSubCategoryIconFileName;
  175.       }
  176.       public function setSubSubCategoryIconFileName(?string $subSubCategoryIconFileName): self
  177.       {
  178.           $this->subSubCategoryIconFileName $subSubCategoryIconFileName;
  179.           return $this;
  180.       }
  181.       public function getSubSubCategoryIconFileSize(): ?int
  182.       {
  183.           return $this->subSubCategoryIconFileSize;
  184.       }
  185.       public function setSubSubCategoryIconFileSize(?int $subSubCategoryIconFileSize): self
  186.       {
  187.           $this->subSubCategoryIconFileSize $subSubCategoryIconFileSize;
  188.           return $this;
  189.       }
  190.       public function getSubSubCategoryIconFileUpdatedAt(): ?\DateTimeInterface
  191.       {
  192.           return $this->subSubCategoryIconFileUpdatedAt;
  193.       }
  194.       public function setSubSubCategoryIconFileUpdatedAt(?\DateTimeInterface $subSubCategoryIconFileUpdatedAt): self
  195.       {
  196.           $this->subSubCategoryIconFileUpdatedAt $subSubCategoryIconFileUpdatedAt;
  197.           return $this;
  198.       }
  199.     /**
  200.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  201.      * @Vich\UploadableField(mapping="subSubCategory", fileNameProperty="subSubCategoryFileName", size="subSubCategoryFileSize")
  202.      * @Assert\File(
  203.      *     maxSize = "1200k"
  204.      * )
  205.      *
  206.      * @var File
  207.      */
  208.     private $subSubCategoryFile;
  209.     /**
  210.      * @ORM\Column(type="string", length=255, nullable=true)
  211.      *
  212.      * @var string
  213.      */
  214.     private $subSubCategoryFileName;
  215.     /**
  216.      * @ORM\Column(type="integer", nullable=true)
  217.      *
  218.      * @var integer
  219.      */
  220.     private $subSubCategoryFileSize;
  221.     /**
  222.      * @ORM\Column(type="datetime", nullable=true)
  223.      *
  224.      * @var \DateTime
  225.      */
  226.     private $subSubCategoryFileUpdatedAt;
  227.     /**
  228.      * @Gedmo\SortablePosition()
  229.      * @ORM\Column(type="integer", nullable=true)
  230.      */
  231.     private $position;
  232.     /**
  233.      * @ORM\OneToMany(targetEntity=SubSubSubCategory::class, mappedBy="subSubCategory")
  234.      */
  235.     private $subSubSubCategories;
  236.     /**
  237.      * @ORM\OneToMany(targetEntity=ApplicationProduct::class, mappedBy="subSubCategory")
  238.      */
  239.     private $applicationProducts;
  240.     /**
  241.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  242.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  243.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  244.      * must be able to accept an instance of 'File' as the bundle will inject one here
  245.      * during Doctrine hydration.
  246.      *
  247.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  248.      */
  249.     public function setSubSubCategoryFile(File $image null)
  250.     {
  251.         $this->subSubCategoryFile $image;
  252.         if (null !== $image) {
  253.             // It is required that at least one field changes if you are using doctrine
  254.             // otherwise the event listeners won't be called and the file is lost
  255.             $this->subSubCategoryFileUpdatedAt = new \DateTimeImmutable();
  256.         }
  257.     }
  258.     public function getSubSubCategoryFile()
  259.     {
  260.         return $this->subSubCategoryFile;
  261.     }
  262.     public function getSubSubCategoryFileName(): ?string
  263.     {
  264.         return $this->subSubCategoryFileName;
  265.     }
  266.     public function setSubSubCategoryFileName(?string $subSubCategoryFileName): self
  267.     {
  268.         $this->subSubCategoryFileName $subSubCategoryFileName;
  269.         return $this;
  270.     }
  271.     public function getSubSubCategoryFileSize(): ?int
  272.     {
  273.         return $this->subSubCategoryFileSize;
  274.     }
  275.     public function setSubSubCategoryFileSize(?int $subSubCategoryFileSize): self
  276.     {
  277.         $this->subSubCategoryFileSize $subSubCategoryFileSize;
  278.         return $this;
  279.     }
  280.     public function getSubSubCategoryFileUpdatedAt(): ?\DateTimeInterface
  281.     {
  282.         return $this->subSubCategoryFileUpdatedAt;
  283.     }
  284.     public function setSubSubCategoryFileUpdatedAt(?\DateTimeInterface $subSubCategoryFileUpdatedAt): self
  285.     {
  286.         $this->subSubCategoryFileUpdatedAt $subSubCategoryFileUpdatedAt;
  287.         return $this;
  288.     }
  289.     public function __construct()
  290.     {
  291.         $this->products = new ArrayCollection();
  292.         $this->subSubSubCategories = new ArrayCollection();
  293.         $this->applicationProducts = new ArrayCollection();
  294.     }
  295.     public function getId(): ?int
  296.     {
  297.         return $this->id;
  298.     }
  299.     public function getSubCategory(): ?SubCategory
  300.     {
  301.         return $this->subCategory;
  302.     }
  303.     public function setSubCategory(?SubCategory $subCategory): self
  304.     {
  305.         $this->subCategory $subCategory;
  306.         return $this;
  307.     }
  308.     public function setParent(?SubCategory $category): self
  309.     {
  310.         return $this->setSubCategory($category);
  311.     }
  312.     public function getParent(): ?SubCategory
  313.     {
  314.         return $this->subCategory;
  315.     }
  316.     /**
  317.      * @return Collection<int, Product>
  318.      */
  319.     public function getProducts(): Collection
  320.     {
  321.         return $this->products;
  322.     }
  323.     public function addProduct(Product $product): self
  324.     {
  325.         if (!$this->products->contains($product)) {
  326.             $this->products[] = $product;
  327.             $product->setSubSubCategory($this);
  328.         }
  329.         return $this;
  330.     }
  331.     public function removeProduct(Product $product): self
  332.     {
  333.         if ($this->products->removeElement($product)) {
  334.             // set the owning side to null (unless already changed)
  335.             if ($product->getSubSubCategory() === $this) {
  336.                 $product->setSubSubCategory(null);
  337.             }
  338.         }
  339.         return $this;
  340.     }
  341.     public function getPosition(): ?int
  342.     {
  343.         return $this->position;
  344.     }
  345.     public function setPosition(?int $position): self
  346.     {
  347.         $this->position $position;
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return Collection<int, SubSubSubCategory>
  352.      */
  353.     public function getSubSubSubCategories(): Collection
  354.     {
  355.         return $this->subSubSubCategories;
  356.     }
  357.     public function addSubSubSubCategory(SubSubSubCategory $subSubSubCategory): self
  358.     {
  359.         if (!$this->subSubSubCategories->contains($subSubSubCategory)) {
  360.             $this->subSubSubCategories[] = $subSubSubCategory;
  361.             $subSubSubCategory->setSubSubCategory($this);
  362.         }
  363.         return $this;
  364.     }
  365.     public function removeSubSubSubCategory(SubSubSubCategory $subSubSubCategory): self
  366.     {
  367.         if ($this->subSubSubCategories->removeElement($subSubSubCategory)) {
  368.             // set the owning side to null (unless already changed)
  369.             if ($subSubSubCategory->getSubSubCategory() === $this) {
  370.                 $subSubSubCategory->setSubSubCategory(null);
  371.             }
  372.         }
  373.         return $this;
  374.     }
  375.     public function findChild($name$locale 'fr') : ?SubSubSubCategory
  376.     {
  377.         foreach ($this->subSubSubCategories as $child) {
  378.             if ($child->getTitle() === $name) {
  379.                 return $child;
  380.             }
  381.         }
  382.         return null;
  383.     }
  384.     public function addChild(SubSubSubCategory $child): self
  385.     {
  386.         return $this->addSubSubSubCategory($child);
  387.     }
  388.     /**
  389.      * @return Collection<int, ApplicationProduct>
  390.      */
  391.     public function getApplicationProducts(): Collection
  392.     {
  393.         return $this->applicationProducts;
  394.     }
  395.     public function addApplicationProduct(ApplicationProduct $applicationProduct): self
  396.     {
  397.         if (!$this->applicationProducts->contains($applicationProduct)) {
  398.             $this->applicationProducts[] = $applicationProduct;
  399.             $applicationProduct->setSubSubCategory($this);
  400.         }
  401.         return $this;
  402.     }
  403.     public function removeApplicationProduct(ApplicationProduct $applicationProduct): self
  404.     {
  405.         if ($this->applicationProducts->removeElement($applicationProduct)) {
  406.             if ($applicationProduct->getSubSubCategory() === $this) {
  407.                 $applicationProduct->setSubSubCategory(null);
  408.             }
  409.         }
  410.         return $this;
  411.     }
  412. }