src/Entity/Produit/Produit/Produit.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Produit\Produit;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Validator\Validatortext\Taillemin;
  5. use App\Validator\Validatortext\Taillemax;
  6. use App\Service\Servicetext\GeneralServicetext;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use App\Repository\Produit\Produit\ProduitRepository;
  9. use App\Entity\Users\User\User;
  10. use App\Entity\Produit\Produit\Imgproduit;
  11. use App\Entity\Produit\Produit\Coutlivraison;
  12. use App\Entity\Produit\Produit\Caracteristiqueproduit;
  13. use App\Entity\Produit\Produit\Souscategorie;
  14. use Doctrine\Common\Collections\Collection;
  15. /**
  16.  * Produit
  17.  *
  18.  * @ORM\Table("produit")
  19.  * @ORM\Entity(repositoryClass=ProduitRepository::class)
  20.  ** @ORM\HasLifecycleCallbacks
  21.  */
  22. class Produit
  23. {
  24.     /**
  25.      * @var integer
  26.      *
  27.      * @ORM\Column(name="id", type="integer")
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     private $id;
  32.     /**
  33.      * @var string
  34.      *
  35.      * @ORM\Column(name="nom", type="string", length=255)
  36.      * @Taillemin(valeur=3, message="Au moins 3 caractères")
  37.      * @Taillemax(valeur=200, message="Au plus 200 caractès")
  38.      */
  39.     private $nom;
  40.     
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(name="contenu", type="text",nullable=true)
  45.      * @Taillemax(valeur=500, message="Au plus 500 caractès")
  46.      */
  47.     private $contenu;
  48.     
  49.     /**
  50.      * @var string
  51.      *
  52.      * @ORM\Column(name="rapport", type="string",nullable=true)
  53.      * @Taillemax(valeur=50, message="Au plus 50 caractès")
  54.      */
  55.     private $rapport;
  56.     
  57.     /**
  58.      * @var integer
  59.      *
  60.      * @ORM\Column(name="rang", type="integer")
  61.      */
  62.     private $rang;
  63.     
  64.     /**
  65.      * @var integer
  66.      *
  67.      * @ORM\Column(name="choixauteur", type="boolean")
  68.      */
  69.     private $choixauteur;
  70.     /**
  71.      * @var \DateTime
  72.      *
  73.      * @ORM\Column(name="date", type="datetime")
  74.      */
  75.     private $date;
  76.     /**
  77.      * @var integer
  78.      *
  79.      * @ORM\Column(name="nblike", type="integer")
  80.      */
  81.     private $nblike;
  82.     /**
  83.      * @var integer
  84.      *
  85.      * @ORM\Column(name="nbvente", type="integer")
  86.      */
  87.     private $nbvente;
  88.     /**
  89.      * @var integer
  90.      *
  91.      * @ORM\Column(name="newprise", type="integer")
  92.      */
  93.     private $newprise;
  94.     /**
  95.      * @var integer
  96.      *
  97.      * @ORM\Column(name="lastprise", type="integer")
  98.      */
  99.     private $lastprise;
  100.     /**
  101.      * @var integer
  102.      *
  103.      * @ORM\Column(name="difference", type="integer")
  104.      */
  105.     private $difference;
  106.     
  107.     /**
  108.        * @ORM\ManyToOne(targetEntity=User::class)
  109.        * @ORM\JoinColumn(nullable=false)
  110.      */
  111.     private $user;
  112.     
  113.     /**
  114.        * @ORM\ManyToMany(targetEntity=User::class)
  115.        * @ORM\JoinColumn(nullable=true)
  116.      */
  117.     private $userlikes;
  118.     
  119.     /**
  120.      * @var integer
  121.      *
  122.      * @ORM\Column(name="prixlivraison", type="integer")
  123.      */
  124.     private $prixlivraison;
  125.     
  126.     /**
  127.      * @var integer
  128.      *
  129.      * @ORM\Column(name="nbvote", type="integer")
  130.      */
  131.     private $nbvote;
  132.     
  133.     /**
  134.      * @var integer
  135.      *
  136.      * @ORM\Column(name="totalnote", type="integer")
  137.      */
  138.     private $totalnote;
  139.     
  140.     /**
  141.        * @ORM\OneToOne(targetEntity=Imgproduit::class, cascade={"persist", "remove"})
  142.       * @Assert\Valid()
  143.        */
  144.     private $imgproduit;
  145.     
  146.     /**
  147.          * @ORM\OneToMany(targetEntity=Coutlivraison::class, mappedBy="produit")
  148.          */
  149.     private $coutlivraisons;
  150.     
  151.     /**
  152.      * @ORM\OneToMany(targetEntity=Caracteristiqueproduit::class, mappedBy="produit")
  153.      */
  154.     private $caracteristiqueproduits;
  155.     
  156.      /**
  157.        * @ORM\ManyToOne(targetEntity=Souscategorie::class, inversedBy="produits")
  158.        * @ORM\JoinColumn(nullable=false)
  159.     */
  160.     private $souscategorie;
  161.     
  162.     private $servicetext;
  163.     
  164.     private $em;
  165.     
  166.     public function __construct(GeneralServicetext $service)
  167.     {
  168.         $this->servicetext $service;
  169.         $this->nblike 0;
  170.         $this->nbvente 0;
  171.         $this->difference 0;
  172.         $this->rang 0;
  173.         $this->nbvote 1;
  174.         $this->totalnote 4;
  175.         $this->date = new \Datetime();
  176.         $this->coutlivraisons = new \Doctrine\Common\Collections\ArrayCollection();
  177.         $this->userlikes = new \Doctrine\Common\Collections\ArrayCollection();
  178.         $this->caracteristiqueproduits = new \Doctrine\Common\Collections\ArrayCollection();
  179.     }
  180.     
  181.     public function setEm($em)
  182.     {
  183.     $this->em $em;
  184.     }
  185.     public function getEm()
  186.     {
  187.     return $this->em;
  188.     }
  189.     
  190.     public function priseLivraison($ville)
  191.     {
  192.         $coutlivraison $this->em->getRepository(Coutlivraison::class)
  193.                          ->findOneBy(array('ville'=>$ville,'produit'=>$this));
  194.         if($coutlivraison != null)
  195.         {
  196.             return $coutlivraison->getMontant();
  197.         }else{
  198.             return $this->prixlivraison;
  199.         }
  200.     }
  201.     
  202.     public function getServicetext()
  203.     {
  204.         return $this->servicetext;
  205.     }
  206.     
  207.     public function setServicetext(GeneralServicetext $service)
  208.     {
  209.         $this->servicetext $service;
  210.         return $this;
  211.     }
  212.     
  213.     public function ancienPrixProduit()
  214.     {
  215.     $aprix $this->newprise $this->difference;
  216.     return $aprix;
  217.     }
  218.     
  219.     /**
  220.       * @ORM\PrePersist()
  221.      * @ORM\PreUpdate()
  222.      */
  223.     public function preSave()
  224.     {
  225.     if($this->newprise != $this->lastprise)
  226.     {
  227.         $this->difference = ($this->lastprise $this->newprise);
  228.     }
  229.     $this->lastprise $this->newprise;
  230.     }
  231.     /**
  232.      * Get id
  233.      *
  234.      * @return integer 
  235.      */
  236.     public function getId()
  237.     {
  238.         return $this->id;
  239.     }
  240.     /**
  241.      * Set nom
  242.      *
  243.      * @param string $nom
  244.      * @return Produit
  245.      */
  246.     public function setNom($nom)
  247.     {
  248.         $this->nom $nom;
  249.         return $this;
  250.     }
  251.     /**
  252.      * Get nom
  253.      *
  254.      * @return string 
  255.      */
  256.     public function getNom()
  257.     {
  258.         return $this->nom;
  259.     }
  260.     /**
  261.      * Set date
  262.      *
  263.      * @param \DateTime $date
  264.      * @return Produit
  265.      */
  266.     public function setDate($date)
  267.     {
  268.         $this->date $date;
  269.         return $this;
  270.     }
  271.     /**
  272.      * Get date
  273.      *
  274.      * @return \DateTime 
  275.      */
  276.     public function getDate()
  277.     {
  278.         return $this->date;
  279.     }
  280.     /**
  281.      * Set nblike
  282.      *
  283.      * @param integer $nblike
  284.      * @return Produit
  285.      */
  286.     public function setNblike($nblike)
  287.     {
  288.         $this->nblike $nblike;
  289.         return $this;
  290.     }
  291.     /**
  292.      * Get nblike
  293.      *
  294.      * @return integer 
  295.      */
  296.     public function getNblike()
  297.     {
  298.         return $this->nblike;
  299.     }
  300.     /**
  301.      * Set nbvente
  302.      *
  303.      * @param integer $nbvente
  304.      * @return Produit
  305.      */
  306.     public function setNbvente($nbvente)
  307.     {
  308.         $this->nbvente $nbvente;
  309.         return $this;
  310.     }
  311.     /**
  312.      * Get nbvente
  313.      *
  314.      * @return integer 
  315.      */
  316.     public function getNbvente()
  317.     {
  318.         return $this->nbvente;
  319.     }
  320.     /**
  321.      * Set newprise
  322.      *
  323.      * @param integer $newprise
  324.      * @return Produit
  325.      */
  326.     public function setNewprise($newprise)
  327.     {
  328.         $this->newprise $newprise;
  329.         return $this;
  330.     }
  331.     /**
  332.      * Get newprise
  333.      *
  334.      * @return integer 
  335.      */
  336.     public function getNewprise()
  337.     {
  338.         return $this->newprise;
  339.     }
  340.     /**
  341.      * Set lastprise
  342.      *
  343.      * @param integer $lastprise
  344.      * @return Produit
  345.      */
  346.     public function setLastprise($lastprise)
  347.     {
  348.         $this->lastprise $lastprise;
  349.         return $this;
  350.     }
  351.     /**
  352.      * Get lastprise
  353.      *
  354.      * @return integer 
  355.      */
  356.     public function getLastprise()
  357.     {
  358.         return $this->lastprise;
  359.     }
  360.     /**
  361.      * Set difference
  362.      *
  363.      * @param integer $difference
  364.      * @return Produit
  365.      */
  366.     public function setDifference($difference)
  367.     {
  368.         $this->difference $difference;
  369.         return $this;
  370.     }
  371.     /**
  372.      * Get difference
  373.      *
  374.      * @return integer 
  375.      */
  376.     public function getDifference()
  377.     {
  378.         return $this->difference;
  379.     }
  380.     /**
  381.      * Set user
  382.      * @return Produit
  383.      */
  384.     public function setUser(User $user): self
  385.     {
  386.         $this->user $user;
  387.         return $this;
  388.     }
  389.     /**
  390.      * Get user
  391.      */
  392.     public function getUser(): ?User
  393.     {
  394.         return $this->user;
  395.     }
  396.     /**
  397.      * Set souscategorie
  398.      * @return Produit
  399.      */
  400.     public function setSouscategorie(Souscategorie $souscategorie): self
  401.     {
  402.         $this->souscategorie $souscategorie;
  403.         $souscategorie->addProduit($this);
  404.         return $this;
  405.     }
  406.     /**
  407.      * Get souscategorie 
  408.      */
  409.     public function getSouscategorie(): ?Souscategorie
  410.     {
  411.         return $this->souscategorie;
  412.     }
  413.     
  414.     /**
  415.      * Set prixlivraison
  416.      *
  417.      * @param integer $prixlivraison
  418.      * @return Produit
  419.      */
  420.     public function setPrixlivraison($prixlivraison)
  421.     {
  422.         $this->prixlivraison $prixlivraison;
  423.         return $this;
  424.     }
  425.     /**
  426.      * Get prixlivraison
  427.      *
  428.      * @return integer 
  429.      */
  430.     public function getPrixlivraison()
  431.     {
  432.         return $this->prixlivraison;
  433.     }
  434.     /**
  435.      * Set contenu
  436.      *
  437.      * @param string $contenu
  438.      * @return Produit
  439.      */
  440.     public function setContenu($contenu)
  441.     {
  442.         $this->contenu $contenu;
  443.         return $this;
  444.     }
  445.     /**
  446.      * Get contenu
  447.      *
  448.      * @return string 
  449.      */
  450.     public function getContenu()
  451.     {
  452.         return $this->contenu;
  453.     }
  454.     /**
  455.      * Add userlikes
  456.      * @return Produit
  457.      */
  458.     public function addUserlike(User $userlikes): self
  459.     {
  460.         $this->userlikes[] = $userlikes;
  461.         $this->nblike $this->nblike 1;
  462.         return $this;
  463.     }
  464.     /**
  465.      * Remove userlikes
  466.      */
  467.     public function removeUserlike(User $userlikes)
  468.     {
  469.         $this->userlikes->removeElement($userlikes);
  470.     }
  471.     /**
  472.      * Get userlikes 
  473.      */
  474.     public function getUserlikes(): ?Collection
  475.     {
  476.         return $this->userlikes;
  477.     }
  478.     
  479.     /**
  480.      * Add coutlivraisons
  481.      * @return Produit
  482.      */
  483.     public function addCoutlivraison(Coutlivraison $coutlivraisons): self
  484.     {
  485.         $this->coutlivraisons[] = $coutlivraisons;
  486.         return $this;
  487.     }
  488.     /**
  489.      * Remove coutlivraisons
  490.      */
  491.     public function removeCoutlivraison(Coutlivraison $coutlivraisons)
  492.     {
  493.         $this->coutlivraisons->removeElement($coutlivraisons);
  494.     }
  495.     /**
  496.      * Get coutlivraisons 
  497.      */
  498.     public function getCoutlivraisons(): ?Collection
  499.     {
  500.         return $this->coutlivraisons;
  501.     }
  502.     /**
  503.      * Add caracteristiqueproduits
  504.      * @return Produit
  505.      */
  506.     public function addCaracteristiqueproduit(Caracteristiqueproduit $caracteristiqueproduits): self
  507.     {
  508.         $this->caracteristiqueproduits[] = $caracteristiqueproduits;
  509.         return $this;
  510.     }
  511.     /**
  512.      * Remove caracteristiqueproduits
  513.      */
  514.     public function removeCaracteristiqueproduit(Caracteristiqueproduit $caracteristiqueproduits)
  515.     {
  516.         $this->caracteristiqueproduits->removeElement($caracteristiqueproduits);
  517.     }
  518.     /**
  519.      * Get caracteristiqueproduits
  520.      */
  521.     public function getCaracteristiqueproduits(): ?Collection
  522.     {
  523.         return $this->caracteristiqueproduits;
  524.     }
  525.     /**
  526.      * Set rapport
  527.      *
  528.      * @param string $rapport
  529.      * @return Produit
  530.      */
  531.     public function setRapport($rapport)
  532.     {
  533.         $this->rapport $rapport;
  534.         return $this;
  535.     }
  536.     /**
  537.      * Get rapport
  538.      *
  539.      * @return string 
  540.      */
  541.     public function getRapport()
  542.     {
  543.         return $this->rapport;
  544.     }
  545.     /**
  546.      * Set rang
  547.      *
  548.      * @param integer $rang
  549.      * @return Produit
  550.      */
  551.     public function setRang($rang)
  552.     {
  553.         $this->rang $rang;
  554.         return $this;
  555.     }
  556.     /**
  557.      * Get rang
  558.      *
  559.      * @return integer 
  560.      */
  561.     public function getRang()
  562.     {
  563.         return $this->rang;
  564.     }
  565.     /**
  566.      * Set imgproduit
  567.      * @return Produit
  568.      */
  569.     public function setImgproduit(Imgproduit $imgproduit null): self
  570.     {
  571.         $this->imgproduit $imgproduit;
  572.         return $this;
  573.     }
  574.     /**
  575.      * Get imgproduit
  576.      */
  577.     public function getImgproduit(): ?Imgproduit
  578.     {
  579.         return $this->imgproduit;
  580.     }
  581.     /**
  582.      * Set choixauteur
  583.      *
  584.      * @param boolean $choixauteur
  585.      * @return Produit
  586.      */
  587.     public function setChoixauteur($choixauteur)
  588.     {
  589.         $this->choixauteur $choixauteur;
  590.         return $this;
  591.     }
  592.     /**
  593.      * Get choixauteur
  594.      *
  595.      * @return boolean 
  596.      */
  597.     public function getChoixauteur()
  598.     {
  599.         return $this->choixauteur;
  600.     }
  601.     /**
  602.      * Set nbvote
  603.      *
  604.      * @param integer $nbvote
  605.      * @return Produit
  606.      */
  607.     public function setNbvote($nbvote)
  608.     {
  609.         $this->nbvote $nbvote;
  610.         return $this;
  611.     }
  612.     /**
  613.      * Get nbvote
  614.      *
  615.      * @return integer 
  616.      */
  617.     public function getNbvote()
  618.     {
  619.         return $this->nbvote;
  620.     }
  621.     /**
  622.      * Set totalnote
  623.      *
  624.      * @param integer $totalnote
  625.      * @return Produit
  626.      */
  627.     public function setTotalnote($totalnote)
  628.     {
  629.         $this->totalnote $totalnote;
  630.         return $this;
  631.     }
  632.     /**
  633.      * Get totalnote
  634.      *
  635.      * @return integer 
  636.      */
  637.     public function getTotalnote()
  638.     {
  639.         return $this->totalnote;
  640.     }
  641. }