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