src/Entity/Product.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\DiscriminatorColumn;
  6. use Doctrine\ORM\Mapping\DiscriminatorMap;
  7. use Doctrine\ORM\Mapping\Entity;
  8. use Doctrine\ORM\Mapping\InheritanceType;
  9. use Doctrine\ORM\Mapping\JoinColumn;
  10. use Doctrine\ORM\Mapping\JoinTable;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\ORM\Mapping\Table;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. #[ORM\Entity(repositoryClass'App\Repository\ProductRepository')]
  17. #[ORM\Table(name'product')]
  18. #[ORM\InheritanceType('JOINED')]
  19. #[ORM\DiscriminatorColumn(name'discr'type'string')]
  20. #[ORM\DiscriminatorMap(['product' => Product::class, 'service' => Service::class, 'marchandise' => Marchandise::class])]
  21. #[ORM\HasLifecycleCallbacks()]
  22. class Product
  23. {
  24.     public function __construct()
  25.     {
  26.         $this->creationdate = new \Datetime();
  27.         $this->subcategories = new ArrayCollection();
  28.         $this->cartlines = new ArrayCollection();
  29.         $this->productclicks = new ArrayCollection();
  30.         $this->comments = new ArrayCollection();
  31.         $this->productFavProducts = new ArrayCollection();
  32.         //$this->latitude=0;
  33.         //$this->longitude=0;
  34.     }
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue(strategy'AUTO')]
  37.     #[ORM\Column(type'integer'uniquetrue)]
  38.     #[Groups(['company''category'])]
  39.     protected $id;
  40.     #[ORM\OneToMany(targetEntity'ProductFav'mappedBy'product'cascade: ['remove'], orphanRemovaltrue)]
  41.     private $productFavProducts;
  42.     #[ORM\ManyToOne(targetEntityUser::class)]
  43.     #[ORM\JoinColumn(name'owner'referencedColumnName'id')]
  44.     #[Groups(['company''category'])]
  45.     private $owner//all
  46.     #[ORM\Column(name'name'type'string'length255uniquefalse)]
  47.     #[Groups(['company''category'])]
  48.     protected $name//all
  49.     #[ORM\Column(name'latitude'type'decimal'nullabletrue)]
  50.     #[Groups(['company''category'])]
  51.     protected $latitude//all
  52.     #[ORM\Column(name'longitude'type'decimal'nullabletrue)]
  53.     #[Groups(['company''category'])]
  54.     protected $longitude//all
  55.     #[ORM\Column(name'description'type'text'nullabletrue)]
  56.     #[Groups(['company''category'])]
  57.     protected $description//all
  58.     #[ORM\Column(name'niveau'type'string'nullabletrue)]
  59.     #[Groups(['company''category'])]
  60.     private $niveau;
  61.     #[ORM\ManyToOne(targetEntity'Category'inversedBy'products')]
  62.     #[ORM\Column(name'category_id'type'integer'nullabletrue)]
  63.     #[Groups(['company''category'])]
  64.     private $category;
  65.     #[ORM\Column(name'origin'type'string'length255nullabletrue)]
  66.     #[Groups(['company''category'])]
  67.     protected $origin//all
  68.     #[ORM\Column(name'slug'type'string'length255)]
  69.     #[Groups(['company''category'])]
  70.     protected $slug//all
  71.     #[ORM\Column(name'certification'type'string'length255)]
  72.     #[Groups(['company''category'])]
  73.     protected $certification//all
  74.     #[ORM\Column(name'price'type'float'nullabletrue)]
  75.     #[Groups(['company''category'])]
  76.     protected $price//all
  77.     #[ORM\Column(name'currency'type'string'length255nullabletrue)]
  78.     #[Groups(['company''category'])]
  79.     protected $currency//all
  80.     #[ORM\Column(name'wantevaluation'type'boolean')]
  81.     #[Groups(['company''category'])]
  82.     protected $wantevaluation//all
  83.     #[ORM\Column(name'gaearecommanded'type'boolean')]
  84.     #[Groups(['company''category'])]
  85.     protected $gaearecommanded//all
  86.     #[ORM\Column(name'creation_date'type'date')]
  87.     #[Groups(['company''category'])]
  88.     protected $creationdate//all
  89.     #[ORM\Column(name'updated_date'type'date'nullabletrue)]
  90.     #[Groups(['company''category'])]
  91.     protected $updateddate//all
  92.     #[ORM\Column(name'image'type'string'nullabletrue)]
  93.     #[Groups(['company''category'])]
  94.     protected $image//all
  95.     #[ORM\OneToMany(targetEntity'App\Entity\ProductComment'mappedBy'product'cascade: ['remove'], orphanRemovaltrue)]
  96.     // #[Groups(['company', 'category'])]
  97.     private $comments;
  98.     #[Assert\File(maxSize'1024k'mimeTypesMessage'Merci de télécharger une image de votre produit')]
  99.     #[Groups(['company''category'])]
  100.     private $image2;
  101.     #[ORM\OneToMany(targetEntityCartline::class, mappedBy'produit'cascade: ['persist'], orphanRemovaltrue)]
  102.     #[Groups(['company''category'])]
  103.     private $cartlines;
  104.     #[ORM\ManyToMany(targetEntity'App\Entity\Subcategory'mappedBy'products'cascade: ['persist'])]
  105.     #[JoinTable(name'product_subcategory')]
  106.     #[Groups(['company''category'])]
  107.     private $subcategories;
  108.     #[ORM\OneToMany(targetEntityProductClick::class, mappedBy'product'cascade: ['persist'], orphanRemovaltrue)]
  109.     #[Groups(['company''category'])]
  110.     private $productclicks;
  111.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'products')]
  112.     #[ORM\JoinColumn(nullablefalse)]
  113.     private $company;
  114.     #[ORM\Column(type'string'length255)]
  115.     #[Groups(['company''category'])]
  116.     private $type;
  117.     #[ORM\OneToOne(targetEntityAdapterContent::class, mappedBy'product'cascade: ['persist''remove'])]
  118.     #[Groups(['company''category'])]
  119.     private $adapterContent;
  120.     /**
  121.      * @return Collection|ProductClick[]
  122.      */
  123.     public function getProductclicks(): Collection
  124.     {
  125.         return $this->productclicks;
  126.     }
  127.     public function addProductclick(ProductClick $productclick): self
  128.     {
  129.         if (!$this->productclicks->contains($productclick)) {
  130.             $this->productclicks[] = $productclick;
  131.             $productclick->setProduct($this);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeProductclick(ProductClick $productclick): self
  136.     {
  137.         if ($this->productclicks->removeElement($productclick)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($productclick->getProduct() === $this) {
  140.                 $productclick->setProduct(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection|Subcategory[]
  147.      */
  148.     public function getSubCategories()
  149.     {
  150.         return $this->subcategories;
  151.     }
  152.     public function addSubCategory(Subcategory $subcategory)
  153.     {
  154.         if (!$this->subcategories->contains($subcategory)) {
  155.             $this->subcategories[] = $subcategory;
  156.             $subcategory->addProduct($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeSubCategory(Subcategory $subcategory)
  161.     {
  162.         if ($this->subcategories->removeElement($subcategory)) {
  163.             // set the owning side to null (unless already changed)
  164.             $subcategory->removeProduct($this);
  165.         }
  166.         return $this;
  167.     }
  168.     /**
  169.      * Get id
  170.      *
  171.      * @return int
  172.      */
  173.     public function getId()
  174.     {
  175.         return $this->id;
  176.     }
  177.     /**
  178.      * @return string
  179.      */
  180.     public function getCertification()
  181.     {
  182.         return $this->certification;
  183.     }
  184.     /**
  185.      * @param string $certification
  186.      */
  187.     public function setCertification($certification)
  188.     {
  189.         $this->certification $certification;
  190.     }
  191.     /**
  192.      * @return \DateTime
  193.      */
  194.     public function getCreationdate()
  195.     {
  196.         return $this->creationdate;
  197.     }
  198.     /**
  199.      * @param \DateTime $creationdate
  200.      */
  201.     public function setCreationdate($creationdate)
  202.     {
  203.         $this->creationdate $creationdate;
  204.     }
  205.     /**
  206.      * @return text
  207.      */
  208.     public function getDescription()
  209.     {
  210.         return $this->description;
  211.     }
  212.     /**
  213.      * @param text $description
  214.      */
  215.     public function setDescription($description)
  216.     {
  217.         $this->description $description;
  218.     }
  219.     /**
  220.      * @return string
  221.      */
  222.     public function getName()
  223.     {
  224.         return $this->name;
  225.     }
  226.     /**
  227.      * @param string $niveau
  228.      */
  229.     public function setName($name)
  230.     {
  231.         $this->name $name;
  232.     }
  233.     /**
  234.      * @return string
  235.      */
  236.     public function getNiveau()
  237.     {
  238.         return $this->niveau;
  239.     }
  240.     /**
  241.      * @param string $niveau
  242.      */
  243.     public function setNiveau($niveau)
  244.     {
  245.         $this->niveau $niveau;
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getSlug()
  251.     {
  252.         return $this->slug;
  253.     }
  254.     /**
  255.      * @param string $slug
  256.      */
  257.     public function setSlug($slug)
  258.     {
  259.         $this->slug $slug;
  260.     }
  261.     /**
  262.      * @return \DateTime
  263.      */
  264.     public function getUpdateddate()
  265.     {
  266.         return $this->updateddate;
  267.     }
  268.     /**
  269.      * @param \DateTime $updateddate
  270.      */
  271.     public function setUpdateddate($updateddate)
  272.     {
  273.         $this->updateddate $updateddate;
  274.     }
  275.     /**
  276.      * @return boolean
  277.      */
  278.     public function isWantevaluation()
  279.     {
  280.         return $this->wantevaluation;
  281.     }
  282.     /**
  283.      * @param boolean $wantevaluation
  284.      */
  285.     public function setWantevaluation($wantevaluation)
  286.     {
  287.         $this->wantevaluation $wantevaluation;
  288.     }
  289.     /**
  290.      * @return string
  291.      */
  292.     public function getOrigin()
  293.     {
  294.         return $this->origin;
  295.     }
  296.     /**
  297.      * @param string $origin
  298.      */
  299.     public function setOrigin($origin)
  300.     {
  301.         $this->origin $origin;
  302.     }
  303.     /**
  304.      * @return double
  305.      */
  306.     public function getPrice()
  307.     {
  308.         return $this->price;
  309.     }
  310.     /**
  311.      * @param double $price
  312.      */
  313.     public function setPrice($price)
  314.     {
  315.         $this->price $price;
  316.     }
  317.     /**
  318.      * @return string
  319.      */
  320.     public function getCurrency()
  321.     {
  322.         return $this->currency;
  323.     }
  324.     /**
  325.      * @param string $currency
  326.      */
  327.     public function setCurrency($currency)
  328.     {
  329.         $this->currency $currency;
  330.     }
  331.     /**
  332.      * @return bool
  333.      */
  334.     public function isGaearecommanded()
  335.     {
  336.         return $this->gaearecommanded;
  337.     }
  338.     /**
  339.      * @param bool $gaearecommanded
  340.      */
  341.     public function setGaearecommanded($gaearecommanded)
  342.     {
  343.         $this->gaearecommanded $gaearecommanded;
  344.     }
  345.     /**
  346.      * @return string
  347.      */
  348.     public function getImage()
  349.     {
  350.         return $this->image;
  351.     }
  352.     /**
  353.      * @param string $image
  354.      * @return mixed
  355.      */
  356.     public function setImage($image)
  357.     {
  358.         $this->image $image;
  359.         return $this;
  360.     }
  361.     public function getImage2()
  362.     {
  363.         return $this->image2;
  364.     }
  365.     public function setImage2($image2)
  366.     {
  367.         $this->image2 $image2;
  368.         return $this;
  369.     }
  370.     /**
  371.      * @return mixed
  372.      */
  373.     public function getCategory()
  374.     {
  375.         return $this->category;
  376.     }
  377.     /**
  378.      * @param mixed $category
  379.      */
  380.     public function setCategory($category): void
  381.     {
  382.         $this->category $category;
  383.     }
  384.     /**
  385.      * @return Collection|ProductComment[]
  386.      */
  387.     public function getProductComments()
  388.     {
  389.         return $this->comments;
  390.     }
  391.     public function addProductComment(ProductComment $comment)
  392.     {
  393.         $this->comments[] = $comment;
  394.         return $this;
  395.     }
  396.     public function removeProductComment(ProductComment $comment)
  397.     {
  398.         return $this->comments->removeElement($comment);
  399.     }
  400.     /**
  401.      * @return mixed
  402.      */
  403.     public function getOwner()
  404.     {
  405.         return $this->owner;
  406.     }
  407.     /**
  408.      * @param mixed $owner
  409.      */
  410.     public function setOwner($owner): void
  411.     {
  412.         $this->owner $owner;
  413.     }
  414.     /**
  415.      * @return float
  416.      */
  417.     public function getLatitude(): ?float
  418.     {
  419.         return $this->latitude;
  420.     }
  421.     /**
  422.      * @param float $latitude
  423.      */
  424.     public function setLatitude(float $latitude): void
  425.     {
  426.         $this->latitude $latitude;
  427.     }
  428.     /**
  429.      * @return float
  430.      */
  431.     public function getLongitude(): ?float
  432.     {
  433.         return $this->longitude;
  434.     }
  435.     /**
  436.      * @param float $longitude
  437.      */
  438.     public function setLongitude(float $longitude): void
  439.     {
  440.         $this->longitude $longitude;
  441.     }
  442.     /**
  443.      * @return Collection|Cartline[]
  444.      */
  445.     public function getCartlines(): Collection
  446.     {
  447.         return $this->cartlines;
  448.     }
  449.     public function addCartline(Cartline $cartline): self
  450.     {
  451.         if (!$this->cartlines->contains($cartline)) {
  452.             $this->cartlines[] = $cartline;
  453.             $cartline->setProduit($this);
  454.         }
  455.         return $this;
  456.     }
  457.     public function removeCartline(Cartline $cartline): self
  458.     {
  459.         if ($this->cartlines->removeElement($cartline)) {
  460.             // set the owning side to null (unless already changed)
  461.             if ($cartline->getProduit() === $this) {
  462.                 $cartline->setProduit(null);
  463.             }
  464.         }
  465.         return $this;
  466.     }
  467.     // PRODUCT FAV
  468.     /**
  469.      * @return Collection|ProductFav[]
  470.      */
  471.     public function getProductFavProducts(): Collection
  472.     {
  473.         return $this->productFavProducts;
  474.     }
  475.     public function addProductFavProduct(ProductFav $productFavProduct): self
  476.     {
  477.         if (!$this->productFavProducts->contains($productFavProduct)) {
  478.             $this->productFavProducts[] = $productFavProduct;
  479.             $productFavProduct->setProduct($this);
  480.         }
  481.         return $this;
  482.     }
  483.     public function removeProductFavProduct(ProductFav $productFavProduct): self
  484.     {
  485.         if ($this->productFavProducts->removeElement($productFavProduct)) {
  486.             // set the owning side to null (unless already changed)
  487.             if ($productFavProduct->getProduct() === $this) {
  488.                 $productFavProduct->setProduct(null);
  489.             }
  490.         }
  491.         return $this;
  492.     }
  493.     public function getCompany(): ?int
  494.     {
  495.         return $this->company->getId();
  496.     }
  497.     public function setCompany(?Company $company): self
  498.     {
  499.         $this->company $company;
  500.         return $this;
  501.     }
  502.     public function getType(): ?string
  503.     {
  504.         return $this->type;
  505.     }
  506.     public function setType(string $type): self
  507.     {
  508.         $this->type $type;
  509.         return $this;
  510.     }
  511.     public function getAdapterContent(): ?AdapterContent
  512.     {
  513.         return $this->adapterContent;
  514.     }
  515.     public function setAdapterContent(?AdapterContent $adapterContent): self
  516.     {
  517.         // unset the owning side of the relation if necessary
  518.         if ($adapterContent === null && $this->adapterContent !== null) {
  519.             $this->adapterContent->setProduct(null);
  520.         }
  521.         // set the owning side of the relation if necessary
  522.         if ($adapterContent !== null && $adapterContent->getProduct() !== $this) {
  523.             $adapterContent->setProduct($this);
  524.         }
  525.         $this->adapterContent $adapterContent;
  526.         return $this;
  527.     }
  528. }