src/Entity/Produit/Produit/Produit.php line 26

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