src/Entity/Produit/Produit/Souscategorie.php line 27

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\Validator\Validatortext\Siteweb;
  7. use App\Service\Servicetext\GeneralServicetext;
  8. use App\Validator\Validatorfile\Image;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use App\Repository\Produit\Produit\SouscategorieRepository;
  11. use App\Entity\Users\User\User;
  12. use App\Entity\Produit\Produit\Categorie;
  13. use App\Entity\Produit\Produit\Cataloguechantier;
  14. use App\Entity\Produit\Produit\Produit;
  15. use App\Entity\Produit\Produit\Caracteristique;
  16. use Doctrine\Common\Collections\Collection;
  17. /**
  18.  * Souscategorie
  19.  *
  20.  * @ORM\Table("souscategorie")
  21.  * @ORM\Entity(repositoryClass=SouscategorieRepository::class)
  22.  ** @ORM\HasLifecycleCallbacks
  23. */
  24. class Souscategorie
  25. {
  26.     /**
  27.      * @var integer
  28.      *
  29.      * @ORM\Column(name="id", type="integer")
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue(strategy="AUTO")
  32.      */
  33.     private $id;
  34.     /**
  35.      * @var string
  36.      *
  37.      * @ORM\Column(name="nom", type="string", length=255)
  38.      * @Taillemin(valeur=3, message="Au moins 3 caractères")
  39.      * @Taillemax(valeur=70, message="Au plus 70 caractès")
  40.     */
  41.     private $nom;
  42.     
  43.     /**
  44.      * @var text
  45.      *
  46.      * @ORM\Column(name="description", type="text")
  47.      * @Taillemin(valeur=3, message="Au moins 3 caractères")
  48.      * @Taillemax(valeur=500, message="Au plus 500 caractès")
  49.      */
  50.     private $description;
  51.     
  52.     /**
  53.      * @var text
  54.      *
  55.      * @ORM\Column(name="helpdashboard", type="text", nullable=true)
  56.      * @Taillemax(valeur=500, message="Au plus 500 caractès")
  57.      */
  58.     private $helpdashboard;
  59.     
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(name="link", type="string", length=255,nullable=true)
  64.      * @Siteweb()
  65.     */
  66.     private $link;
  67.     /**
  68.      * @var \DateTime
  69.      *
  70.      * @ORM\Column(name="date", type="datetime")
  71.      */
  72.     private $date;
  73.     
  74.     /**
  75.      * @var integer
  76.      *
  77.      * @ORM\Column(name="nbvente", type="integer")
  78.      */
  79.     private $nbvente;
  80.     
  81.     /**
  82.      * @var integer
  83.      *
  84.      * @ORM\Column(name="rang", type="integer")
  85.      */
  86.     private $rang;
  87.     
  88.     /**
  89.      * @var string
  90.      *
  91.      * @ORM\Column(name="src", type="string", length=255, nullable=true)
  92.      */
  93.     private $src;
  94.     /**
  95.      * @var string
  96.      *
  97.      * @ORM\Column(name="alt", type="string", length=255, nullable=true)
  98.      */
  99.     private $alt;
  100.     
  101.     /**
  102.     * @Image(taillemax=1500000, message="la taille de l'image  %string% est grande.")
  103.     */
  104.     private $file;
  105.     
  106.     // permet le stocage temporaire du nom du fichier
  107.     private $tempFilename;
  108.     
  109.     /**
  110.       * @ORM\ManyToOne(targetEntity=User::class)
  111.       * @ORM\JoinColumn(nullable=false)
  112.     */
  113.     private $user;
  114.     
  115.      /**
  116.        * @ORM\ManyToOne(targetEntity=Categorie::class, inversedBy="souscategories")
  117.        * @ORM\JoinColumn(nullable=false)
  118.     */
  119.     private $categorie;
  120.     
  121.      /**
  122.        * @ORM\ManyToOne(targetEntity=Cataloguechantier::class, inversedBy="souscategories")
  123.        * @ORM\JoinColumn(nullable=true)
  124.     */
  125.     private $cataloguechantier;
  126.     
  127.     /**
  128.      * @ORM\OneToMany(targetEntity=Produit::class, mappedBy="souscategorie")
  129.      */
  130.     private $produits;
  131.     
  132.     /**
  133.      * @ORM\OneToMany(targetEntity=Caracteristique::class, mappedBy="souscategorie")
  134.      */
  135.     private $caracteristiques;
  136.     
  137.     private $servicetext;
  138.     
  139.     private $element;
  140.     
  141.     private $em;
  142.     
  143.     public function __construct(GeneralServicetext $service)
  144.     {
  145.         $this->servicetext $service;
  146.         $this->date = new \Datetime();
  147.         $this->produits = new \Doctrine\Common\Collections\ArrayCollection();
  148.         $this->caracteristiques = new \Doctrine\Common\Collections\ArrayCollection();
  149.         $this->nbvente 0;
  150.         $this->rang 0;
  151.         $this->domaine false;
  152.     }
  153.     
  154.     public function getServicetext()
  155.     {
  156.         return $this->servicetext;
  157.     }
  158.     
  159.     public function setServicetext(GeneralServicetext $service)
  160.     {
  161.         $this->servicetext $service;
  162.         return $this;
  163.     }
  164.     
  165.     public function getElement()
  166.     {
  167.         return $this->element;
  168.     }
  169.     
  170.     public function setElement($element)
  171.     {
  172.         $this->element $element;
  173.         return $this;
  174.     }
  175.     
  176.     public function getEm()
  177.     {
  178.         return $this->em;
  179.     }
  180.     
  181.     public function setEm($em)
  182.     {
  183.         $this->em $em;
  184.         return $this;
  185.     }
  186.     /**
  187.      * Get id
  188.      *
  189.      * @return integer 
  190.      */
  191.     public function getId()
  192.     {
  193.         return $this->id;
  194.     }
  195.     /**
  196.      * Set nom
  197.      *
  198.      * @param string $nom
  199.      * @return Souscategorie
  200.      */
  201.     public function setNom($nom)
  202.     {
  203.         $this->nom $nom;
  204.         return $this;
  205.     }
  206.     /**
  207.      * Get nom
  208.      *
  209.      * @return string 
  210.      */
  211.     public function getNom()
  212.     {
  213.         return $this->nom;
  214.     }
  215.     /**
  216.      * Set date
  217.      *
  218.      * @param \DateTime $date
  219.      * @return Souscategorie
  220.      */
  221.     public function setDate($date)
  222.     {
  223.         $this->date $date;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get date
  228.      *
  229.      * @return \DateTime 
  230.      */
  231.     public function getDate()
  232.     {
  233.         return $this->date;
  234.     }
  235.     
  236.     /**
  237.      * @ORM\PrePersist()
  238.      * @ORM\PreUpdate()
  239.      */
  240.     public function premajuscule()
  241.     {
  242.     }
  243.     /**
  244.      * Set categorie
  245.      * @return Souscategorie
  246.      */
  247.     public function setCategorie(Categorie $categorie): self
  248.     {
  249.         $this->categorie $categorie;
  250.         $categorie->addSouscategory($this);
  251.         return $this;
  252.     }
  253.     /**
  254.      * Get categorie 
  255.      */
  256.     public function getCategorie(): ?Categorie
  257.     {
  258.         return $this->categorie;
  259.     }
  260.     /**
  261.      * Set user
  262.      * @return Souscategorie
  263.      */
  264.     public function setUser(User $user): self
  265.     {
  266.         $this->user $user;
  267.         return $this;
  268.     }
  269.     /**
  270.      * Get user
  271.      */
  272.     public function getUser(): ?User
  273.     {
  274.         return $this->user;
  275.     }
  276.     /**
  277.      * Add produits
  278.      * @return Souscategorie
  279.      */
  280.     public function addProduit(Produit $produits): self
  281.     {
  282.         $this->produits[] = $produits;
  283.         return $this;
  284.     }
  285.     /**
  286.      * Remove produits
  287.      */
  288.     public function removeProduit(Produit $produits)
  289.     {
  290.         $this->produits->removeElement($produits);
  291.     }
  292.     /**
  293.      * Get produits 
  294.      */
  295.     public function getProduits(): ?Collection
  296.     {
  297.         return $this->produits;
  298.     }
  299.     /**
  300.      * Set nbvente
  301.      *
  302.      * @param integer $nbvente
  303.      * @return Souscategorie
  304.      */
  305.     public function setNbvente($nbvente)
  306.     {
  307.         $this->nbvente $nbvente;
  308.         return $this;
  309.     }
  310.     /**
  311.      * Get nbvente
  312.      *
  313.      * @return integer 
  314.      */
  315.     public function getNbvente()
  316.     {
  317.         return $this->nbvente;
  318.     }
  319.     
  320.     //permet la récupération du nom du fichier temporaire
  321.     public function getTempFilename()
  322.     {
  323.     return $this->tempFilename;
  324.     }
  325.     //permet de modifier le contenu de la variable tempFilename
  326.     public function setTempFilename($temp)
  327.     {
  328.     $this->tempFilename=$temp;
  329.     }
  330.     // permet la récupération du nom du fiechier
  331.     public function getFile()
  332.     {
  333.     return $this->file;
  334.     }
  335.     
  336.     public function getUploadDir()
  337.     {
  338.     // On retourne le chemin relatif vers l'image pour un navigateur
  339.     return 'bundles/produit/produit/images/souscategorie';
  340.     }
  341.     protected function getUploadRootDir()
  342.     {
  343.     // On retourne le chemin relatif vers l'image pour notre codePHP
  344.     return  __DIR__.'/../../../../public/'.$this->getUploadDir();
  345.     }
  346.     public function setFile(UploadedFile $file)
  347.     {
  348.     $this->file $file;
  349.     // On vérifie si on avait déjà un fichier pour cette entité
  350.     if (null !== $this->src) {
  351.     // On sauvegarde l'extension du fichier pour le supprimer plus tard
  352.     $this->tempFilename $this->src;
  353.     // On réinitialise les valeurs des attributs url et alt
  354.     $this->src null;
  355.     $this->alt null;
  356.     }
  357.     }
  358.     /**
  359.     * @ORM\PrePersist()
  360.     * @ORM\PreUpdate()
  361.     */
  362.     public function preUpload()
  363.     {
  364.     if (null === $this->file) {
  365.     return;
  366.     }
  367.     $text $this->file->getClientOriginalName();
  368.     $this->src $this->servicetext->normaliseText($text);
  369.     $this->alt $this->src;
  370.     }
  371.     
  372.     /**
  373.     * @ORM\PostPersist()
  374.     * @ORM\PostUpdate()
  375.     */
  376.     public function upload()
  377.     {
  378.     // Si jamais il n'y a pas de fichier (champ facultatif)
  379.     if (null === $this->file) {
  380.     return;
  381.     }
  382.     if (null !== $this->tempFilename) {
  383.     $oldFile $this->getUploadRootDir().'/'.$this->id.'.'.$this->tempFilename;
  384.     if (file_exists($oldFile)) {
  385.     unlink($oldFile);
  386.     }
  387.     }
  388.     $this->file->move$this->getUploadRootDir(), $this->id.'.'.$this->src);
  389.     }
  390.     /**
  391.     *@ORM\PreRemove()
  392.     */
  393.     public function preRemoveUpload()
  394.     {
  395.     $this->tempFilename $this->getUploadRootDir().'/'.$this->id.'.'.$this->src;
  396.     }
  397.     
  398.     /**
  399.     * @ORM\PostRemove()
  400.     */
  401.     public function postRemoveUpload()
  402.     {
  403.     // En PostRemove, on n'a pas accès à l'id, on utilise notre nom sauvegardé
  404.     if (file_exists($this->tempFilename)) {
  405.     // On supprime le fichier
  406.     unlink($this->tempFilename);
  407.     }
  408.     }
  409.     
  410.     public function getWebPath()
  411.     {
  412.     return $this->getUploadDir().'/'.$this->getId().'.'.$this->getSrc();
  413.     }
  414.     /**
  415.      * Set description
  416.      *
  417.      * @param string $description
  418.      * @return Souscategorie
  419.      */
  420.     public function setDescription($description)
  421.     {
  422.         $this->description $description;
  423.         return $this;
  424.     }
  425.     /**
  426.      * Get description
  427.      *
  428.      * @return string 
  429.      */
  430.     public function getDescription()
  431.     {
  432.         return $this->description;
  433.     }
  434.     /**
  435.      * Set rang
  436.      *
  437.      * @param integer $rang
  438.      * @return Souscategorie
  439.      */
  440.     public function setRang($rang)
  441.     {
  442.         $this->rang $rang;
  443.         return $this;
  444.     }
  445.     /**
  446.      * Get rang
  447.      *
  448.      * @return integer 
  449.      */
  450.     public function getRang()
  451.     {
  452.         return $this->rang;
  453.     }
  454.     /**
  455.      * Set src
  456.      *
  457.      * @param string $src
  458.      * @return Souscategorie
  459.      */
  460.     public function setSrc($src)
  461.     {
  462.         $this->src $src;
  463.         return $this;
  464.     }
  465.     /**
  466.      * Get src
  467.      *
  468.      * @return string 
  469.      */
  470.     public function getSrc()
  471.     {
  472.         return $this->src;
  473.     }
  474.     /**
  475.      * Set alt
  476.      *
  477.      * @param string $alt
  478.      * @return Souscategorie
  479.      */
  480.     public function setAlt($alt)
  481.     {
  482.         $this->alt $alt;
  483.         return $this;
  484.     }
  485.     /**
  486.      * Get alt
  487.      *
  488.      * @return string 
  489.      */
  490.     public function getAlt()
  491.     {
  492.         return $this->alt;
  493.     }
  494.     /**
  495.      * Set link
  496.      *
  497.      * @param string $link
  498.      * @return Souscategorie
  499.      */
  500.     public function setLink($link)
  501.     {
  502.         $this->link $link;
  503.         return $this;
  504.     }
  505.     /**
  506.      * Get link
  507.      *
  508.      * @return string 
  509.      */
  510.     public function getLink()
  511.     {
  512.         return $this->link;
  513.     }
  514.     /**
  515.      * Add caracteristiques
  516.      * @return Souscategorie
  517.      */
  518.     public function addCaracteristique(Caracteristique $caracteristiques): self
  519.     {
  520.         $this->caracteristiques[] = $caracteristiques;
  521.         return $this;
  522.     }
  523.     /**
  524.      * Remove caracteristiques
  525.      */
  526.     public function removeCaracteristique(Caracteristique $caracteristiques)
  527.     {
  528.         $this->caracteristiques->removeElement($caracteristiques);
  529.     }
  530.     /**
  531.      * Get caracteristiques
  532.      */
  533.     public function getCaracteristiques(): ?Collection
  534.     {
  535.         return $this->caracteristiques;
  536.     }
  537.     
  538.     public function subdescription($tail)
  539.     {
  540.         if(strlen($this->description) <= $tail)
  541.         {
  542.             return $this->description;
  543.         }else{
  544.             $text wordwrap($this->description,$tail,'~',true);
  545.             $tab explode('~',$text);
  546.             $text $tab[0];
  547.             return $text.'...';
  548.         }
  549.     }
  550.     /**
  551.      * Set helpdashboard
  552.      *
  553.      * @param string $helpdashboard
  554.      * @return Souscategorie
  555.      */
  556.     public function setHelpdashboard($helpdashboard)
  557.     {
  558.         $this->helpdashboard $helpdashboard;
  559.         return $this;
  560.     }
  561.     /**
  562.      * Get helpdashboard
  563.      *
  564.      * @return string 
  565.      */
  566.     public function getHelpdashboard()
  567.     {
  568.         return $this->helpdashboard;
  569.     }
  570.     
  571.     public function getProduitScat()
  572.     {
  573.         $liste_prod $this->em->getRepository(Produit::class)
  574.                                ->findBy(array('souscategorie'=>$this), array('rang'=>'asc'));
  575.         return $liste_prod;
  576.     }
  577.     /**
  578.      * Set cataloguechantier
  579.      * @return Souscategorie
  580.      */
  581.     public function setCataloguechantier(Cataloguechantier $cataloguechantier null): self
  582.     {
  583.         $this->cataloguechantier $cataloguechantier;
  584.         return $this;
  585.     }
  586.     /**
  587.      * Get cataloguechantier
  588.     */
  589.     public function getCataloguechantier(): ?Cataloguechantier
  590.     {
  591.         return $this->cataloguechantier;
  592.     }
  593. }