src/Entity/Product.php line 23

  1. <?php
  2. /*
  3.  * This file is part of the Doctrine-TestSet project created by
  4.  * https://github.com/MacFJA
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * at https://github.com/MacFJA/Doctrine-TestSet
  8.  */
  9. namespace App\Entity;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. #[ORM\Entity]
  17. #[Vich\Uploadable]
  18. class Product
  19. {
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(name"id"type"integer")]
  23.     #[Groups(["products"])]
  24.     private $id null;
  25.     #[ORM\Column(type"datetime"name"created_at")]
  26.     #[Groups(["products"])]
  27.     private $createdAt null;
  28.     #[ORM\Column(type"boolean")]
  29.     #[Groups(["products"])]
  30.     private $enabled false;
  31.     #[ORM\Column(type"string"length255nullabletrue)]
  32.     #[Groups(["products"])]
  33.     private $thumbnail;
  34.     #[Vich\UploadableField(mapping"product_images"fileNameProperty"thumbnail")]
  35.     private $thumbnailFile;
  36.     #[ORM\Column(type"datetime"nullabletrue)]
  37.     #[Groups(["products"])]
  38.     private $updatedAt;
  39.     #[ORM\Column(type"string")]
  40.     #[Groups(["products"])]
  41.     private $name;
  42.     #[ORM\Column(type"text"length2048nullabletrue)]
  43.     #[Groups(["products"])]
  44.     private $shortDescription;
  45.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy"products")]
  46.     #[ORM\JoinTable(name"product_category")]
  47.     #[Groups(["products"])]
  48.     private $categories;
  49.     #[ORM\Column(type"string"length2048nullabletrue)]
  50.     #[Groups(["products"])]
  51.     private $longDescription;
  52.     #[ORM\Column(type"boolean"nullabletrue)]
  53.     #[Groups(["products"])]
  54.     private $beta;
  55.     #[ORM\Column(type"boolean"nullabletrue)]
  56.     #[Groups(["products"])]
  57.     private $recommended;
  58.     #[ORM\ManyToMany(targetEntityPfosten::class, inversedBy"product")]
  59.     #[ORM\JoinTable(name"product_pfosten")]
  60.     #[Groups(["products"])]
  61.     private $pfosten;
  62.     #[ORM\ManyToMany(targetEntityZaunelement::class, inversedBy"product")]
  63.     #[ORM\JoinTable(name"product_zaunelement")]
  64.     #[Groups(["products"])]
  65.     private $zaunelemente;
  66.     #[ORM\ManyToMany(targetEntityTerrasse::class, inversedBy"product")]
  67.     #[ORM\JoinTable(name"product_terrasse")]
  68.     #[Groups(["products"])]
  69.     private $terrassen;
  70.     #[ORM\Column(type"string"length2048nullabletrue)]
  71.     #[Groups(["products"])]
  72.     private $adBannerText;
  73.     #[ORM\Column(type"string"length255nullabletrue)]
  74.     #[Groups(["products"])]
  75.     private $adBanner;
  76.     #[ORM\Column(type"string"length255nullabletrue)]
  77.     #[Groups(["products"])]
  78.     private $recommendedText;
  79.     #[Vich\UploadableField(mapping"product_images"fileNameProperty"adBanner")]
  80.     private $adBannerFile;
  81.     #[ORM\Column(type"integer"nullabletrue)]
  82.     #[Groups(["products"])]
  83.     private $default_pfosten_id = [];
  84.     #[ORM\Column(type"integer"nullabletrue)]
  85.     #[Groups(["products"])]
  86.     private $default_zaunelement_id = [];
  87.     #[ORM\Column(type"boolean"nullabletrue)]
  88.     #[Groups(["products"])]
  89.     private $pluggable;
  90.     #[ORM\Column(type"integer"nullabletrue)]
  91.     #[Groups(["products"])]
  92.     private $position;
  93.     public function __construct()
  94.     {
  95.         $this->categories = new ArrayCollection();
  96.         $this->createdAt = new \DateTime();
  97.         $this->pfosten = new ArrayCollection();
  98.         $this->zaunelemente = new ArrayCollection();
  99.         $this->terrassen = new ArrayCollection();
  100.     }
  101.     /**
  102.      * Add a category in the product association.
  103.      * (Owning side).
  104.      *
  105.      * @param $category Category the category to associate
  106.      */
  107.     public function addCategory($category)
  108.     {
  109.         if ($this->categories->contains($category)) {
  110.             return;
  111.         }
  112.         $this->categories->add($category);
  113.         $category->addProduct($this);
  114.     }
  115.     /**
  116.      * Remove a category in the product association.
  117.      * (Owning side).
  118.      *
  119.      * @param $category Category the category to associate
  120.      */
  121.     public function removeCategory($category)
  122.     {
  123.         if (!$this->categories->contains($category)) {
  124.             return;
  125.         }
  126.         $this->categories->removeElement($category);
  127.         $category->removeProduct($this);
  128.     }
  129.     /**
  130.      * Set the shortDescription of the product.
  131.      *
  132.      * @param string $shortDescription
  133.      */
  134.     public function setShortDescription($shortDescription)
  135.     {
  136.         $this->shortDescription $shortDescription;
  137.     }
  138.     /**
  139.      * The the full shortDescription of the product.
  140.      *
  141.      * @return string
  142.      */
  143.     public function getShortDescription()
  144.     {
  145.         return $this->shortDescription;
  146.     }
  147.     /**
  148.      * Set if the product is enable.
  149.      *
  150.      * @param bool $enabled
  151.      */
  152.     public function setEnabled($enabled)
  153.     {
  154.         $this->enabled $enabled;
  155.     }
  156.     /**
  157.      * Is the product enabled?
  158.      *
  159.      * @return bool
  160.      */
  161.     public function getEnabled()
  162.     {
  163.         return $this->enabled;
  164.     }
  165.     /**
  166.      * Alias of getEnabled.
  167.      *
  168.      * @return bool
  169.      */
  170.     public function isEnabled()
  171.     {
  172.         return $this->getEnabled();
  173.     }
  174.     /**
  175.      * @param File|null $image
  176.      */
  177.     public function setThumbnailFile(File $image null)
  178.     {
  179.         $this->thumbnailFile $image;
  180.         // VERY IMPORTANT:
  181.         // It is required that at least one field changes if you are using Doctrine,
  182.         // otherwise the event listeners won't be called and the file is lost
  183.         if ($image) {
  184.             // if 'updatedAt' is not defined in your entity, use another property
  185.             $this->updatedAt = new \DateTime('now');
  186.         }
  187.     }
  188.     /**
  189.      * @return File
  190.      */
  191.     public function getThumbnailFile()
  192.     {
  193.         return $this->thumbnailFile;
  194.     }
  195.     /**
  196.      * @param string $image
  197.      */
  198.     public function setThumbnail($image)
  199.     {
  200.         $this->thumbnail $image;
  201.     }
  202.     /**
  203.      * @return string
  204.      */
  205.     public function getThumbnail()
  206.     {
  207.         return $this->thumbnail;
  208.     }
  209.     /**
  210.      * Set the product name.
  211.      *
  212.      * @param string $name
  213.      */
  214.     public function setName($name)
  215.     {
  216.         $this->name $name;
  217.     }
  218.     /**
  219.      * Retrieve the name of the product.
  220.      *
  221.      * @return string
  222.      */
  223.     public function getName()
  224.     {
  225.         return $this->name;
  226.     }
  227.     /**
  228.      * Get all associated categories.
  229.      *
  230.      * @return Category[]
  231.      */
  232.     public function getCategories()
  233.     {
  234.         return $this->categories;
  235.     }
  236.     /**
  237.      * Set all categories of the product.
  238.      *
  239.      * @param Category[] $categories
  240.      */
  241.     public function setCategories($categories)
  242.     {
  243.         // This is the owning side, we have to call remove and add to have change in the category side too.
  244.         foreach ($this->getCategories() as $category) {
  245.             $this->removeCategory($category);
  246.         }
  247.         foreach ($categories as $category) {
  248.             $this->addCategory($category);
  249.         }
  250.     }
  251.     /**
  252.      * @return \DateTime
  253.      */
  254.     public function getCreatedAt()
  255.     {
  256.         if(!$this->createdAt) {
  257.             $this->createdAt = new \DateTime();
  258.         }
  259.         return $this->createdAt;
  260.     }
  261.     /**
  262.      *
  263.      */
  264.     public function setCreatedAt(\DateTime $createdAt): void
  265.     {
  266.         $this->createdAt $createdAt;
  267.     }
  268.     /**
  269.      * Get the id of the product.
  270.      *
  271.      * @return int
  272.      */
  273.     public function getId()
  274.     {
  275.         return $this->id;
  276.     }
  277.     /**
  278.      * {@inheritdoc}
  279.      */
  280.     public function __toString()
  281.     {
  282.         return $this->getName() ?? '';
  283.     }
  284.     /**
  285.      * @return string|null
  286.      */
  287.     public function getLongDescription(): ?string
  288.     {
  289.         return $this->longDescription;
  290.     }
  291.     /**
  292.      * @param string|null $longDescription
  293.      * @return $this
  294.      */
  295.     public function setLongDescription(?string $longDescription): static
  296.     {
  297.         $this->longDescription $longDescription;
  298.         return $this;
  299.     }
  300.     /**
  301.      * @return bool|null
  302.      */
  303.     public function getBeta(): ?bool
  304.     {
  305.         return $this->beta;
  306.     }
  307.     /**
  308.      * @param bool|null $beta
  309.      * @return $this
  310.      */
  311.     public function setBeta(?bool $beta): static
  312.     {
  313.         $this->beta $beta;
  314.         return $this;
  315.     }
  316.     /**
  317.      * @return bool|null
  318.      */
  319.     public function getRecommended(): ?bool
  320.     {
  321.         return $this->recommended;
  322.     }
  323.     /**
  324.      * @param bool|null $recommended
  325.      * @return $this
  326.      */
  327.     public function setRecommended(?bool $recommended): static
  328.     {
  329.         $this->recommended $recommended;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return \DateTime
  334.      */
  335.     public function getUpdatedAt(): \DateTime
  336.     {
  337.         return $this->updatedAt;
  338.     }
  339.     /**
  340.      * @param \DateTime|null $updatedAt
  341.      * @return $this
  342.      */
  343.     public function setUpdatedAt(?\DateTime $updatedAt): static
  344.     {
  345.         $this->updatedAt $updatedAt;
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return Collection|Pfosten[]
  350.      */
  351.     public function getPfosten(): Collection|array
  352.     {
  353.         return $this->pfosten;
  354.     }
  355.     /**
  356.      * Set all categories of the product.
  357.      *
  358.      * @param array $pfostens
  359.      */
  360.     public function setPfosten(array $pfostens)
  361.     {
  362.         // This is the owning side, we have to call remove and add to have change in the category side too.
  363.         foreach ($this->getPfosten() as $pfosten) {
  364.             $this->removePfosten($pfosten);
  365.         }
  366.         foreach ($pfostens as $pfosten) {
  367.             $this->addPfosten($pfosten);
  368.         }
  369.     }
  370.     public function addPfosten(Pfosten $pfosten)
  371.     {
  372.         if ($this->pfosten->contains($pfosten)) {
  373.             return;
  374.         }
  375.         $this->pfosten->add($pfosten);
  376.         $pfosten->addProduct($this);
  377.     }
  378.     public function removePfosten(Pfosten $pfosten)
  379.     {
  380.         if (!$this->pfosten->contains($pfosten)) {
  381.             return;
  382.         }
  383.         $this->pfosten->removeElement($pfosten);
  384.         $pfosten->removeProduct($this);
  385.     }
  386.     /**
  387.      * @return Collection|Zaunelement[]
  388.      */
  389.     public function getZaunelemente(): Collection|array
  390.     {
  391.         return $this->zaunelemente;
  392.     }
  393.     /**
  394.      * Set all Zaunelemente of the product.
  395.      *
  396.      * @param array $zaunelemente
  397.      */
  398.     public function setZaunelemente(array $zaunelemente)
  399.     {
  400.         // This is the owning side, we have to call remove and add to have change in the category side too.
  401.         foreach ($this->getZaunelemente() as $zaunelement) {
  402.             $this->removeZaunelemente($zaunelement);
  403.         }
  404.         foreach ($zaunelemente as $zaunelement) {
  405.             $this->addZaunelemente($zaunelement);
  406.         }
  407.     }
  408.     public function addZaunelemente(Zaunelement $zaunelemente)
  409.     {
  410.         if ($this->zaunelemente->contains($zaunelemente)) {
  411.             return;
  412.         }
  413.         $this->zaunelemente->add($zaunelemente);
  414.         $zaunelemente->addProduct($this);
  415.     }
  416.     public function removeZaunelemente(Zaunelement $zaunelemente)
  417.     {
  418.         if (!$this->zaunelemente->contains($zaunelemente)) {
  419.             return;
  420.         }
  421.         $this->zaunelemente->removeElement($zaunelemente);
  422.         $zaunelemente->removeProduct($this);
  423.     }
  424.     /**
  425.      * @return Collection|Terrasse[]
  426.      */
  427.     public function getTerrassen(): Collection|array
  428.     {
  429.         return $this->terrassen;
  430.     }
  431.     /**
  432.      * Set all Terrassen of the product.
  433.      *
  434.      * @param array $terrassen
  435.      */
  436.     public function setTerrassen(array $terrassen)
  437.     {
  438.         // This is the owning side, we have to call remove and add to have change in the category side too.
  439.         foreach ($this->getTerrassen() as $terrasse) {
  440.             $this->removeTerrassen($terrasse);
  441.         }
  442.         foreach ($terrassen as $terrasse) {
  443.             $this->addTerrassen($terrasse);
  444.         }
  445.     }
  446.     public function addTerrassen(Terrasse $terrassen)
  447.     {
  448.         if ($this->terrassen->contains($terrassen)) {
  449.             return;
  450.         }
  451.         $this->terrassen->add($terrassen);
  452.         $terrassen->addProduct($this);
  453.     }
  454.     public function removeTerrassen(Terrasse $terrassen)
  455.     {
  456.         if (!$this->terrassen->contains($terrassen)) {
  457.             return;
  458.         }
  459.         $this->terrassen->removeElement($terrassen);
  460.         $terrassen->removeProduct($this);
  461.     }
  462.     public function getAdBannerText(): ?string
  463.     {
  464.         return $this->adBannerText;
  465.     }
  466.     public function setAdBannerText(?string $adBannerText): self
  467.     {
  468.         $this->adBannerText $adBannerText;
  469.         return $this;
  470.     }
  471.     public function getAdBanner(): ?string
  472.     {
  473.         return $this->adBanner;
  474.     }
  475.     public function setAdBanner(?string $adBanner): self
  476.     {
  477.         $this->adBanner $adBanner;
  478.         return $this;
  479.     }
  480.     /**
  481.      * @param null|File $image
  482.      */
  483.     public function setAdBannerFile(File $image null)
  484.     {
  485.         $this->adBannerFile $image;
  486.         // VERY IMPORTANT:
  487.         // It is required that at least one field changes if you are using Doctrine,
  488.         // otherwise the event listeners won't be called and the file is lost
  489.         if ($image) {
  490.             // if 'updatedAt' is not defined in your entity, use another property
  491.             $this->updatedAt = new \DateTime('now');
  492.         }
  493.     }
  494.     /**
  495.      * @return null|File
  496.      */
  497.     public function getAdBannerFile(): ?File
  498.     {
  499.         return $this->adBannerFile;
  500.     }
  501.     public function getRecommendedText(): ?string
  502.     {
  503.         return $this->recommendedText;
  504.     }
  505.     public function setRecommendedText(?string $recommendedText): self
  506.     {
  507.         $this->recommendedText $recommendedText;
  508.         return $this;
  509.     }
  510.     public function getDefaultPfostenId(): ?int
  511.     {
  512.         return $this->default_pfosten_id;
  513.     }
  514.     public function setDefaultPfostenId(?int $default_pfosten_id): self
  515.     {
  516.         $this->default_pfosten_id $default_pfosten_id;
  517.         return $this;
  518.     }
  519.     public function getDefaultZaunelementId(): ?int
  520.     {
  521.         return $this->default_zaunelement_id;
  522.     }
  523.     public function setDefaultZaunelementId(?int $default_zaunelement_id): self
  524.     {
  525.         $this->default_zaunelement_id $default_zaunelement_id;
  526.         return $this;
  527.     }
  528.     public function getPluggable(): ?bool
  529.     {
  530.         return $this->pluggable;
  531.     }
  532.     public function setPluggable(?bool $pluggable): self
  533.     {
  534.         $this->pluggable $pluggable;
  535.         return $this;
  536.     }
  537.     public function getPosition(): ?int
  538.     {
  539.         return $this->position;
  540.     }
  541.     public function setPosition(?int $position): self
  542.     {
  543.         $this->position $position;
  544.         return $this;
  545.     }
  546. }