src/Entity/Commentaire.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommentaireRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use App\Controller\UploadController;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Controller\ExtensionController;
  9. /**
  10.  * @ORM\Entity(repositoryClass=CommentaireRepository::class)
  11.  */
  12. class Commentaire
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="commentaires")
  22.      * @ORM\JoinColumn(nullable=false)
  23.      */
  24.     private $user;
  25.     /**
  26.      * @ORM\Column(type="text")
  27.      */
  28.     private $content;
  29.     /**
  30.      * @ORM\Column(type="datetime_immutable")
  31.      */
  32.     private $date;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity=Commentaire::class, inversedBy="commentaires")
  35.      */
  36.     private $commentaireRep;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=Article::class, inversedBy="commentaires")
  39.      * @ORM\JoinColumn(nullable=false)
  40.      */
  41.     private $article;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity=Commentaire::class, mappedBy="commentaireRep")
  44.      */
  45.     private $commentaires;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=Fichier::class, mappedBy="commentaire", orphanRemoval=true)
  48.      */
  49.     private $fichiers;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=ReportCommentaire::class, mappedBy="commentaire", orphanRemoval=true)
  52.      */
  53.     private $reportCommentaires;
  54.     /**
  55.      * @ORM\Column(type="boolean")
  56.      */
  57.     private $verified;
  58.     public function __construct()
  59.     {
  60.         $this->commentaires = new ArrayCollection();
  61.         $this->fichiers = new ArrayCollection();
  62.         $this->reportCommentaires = new ArrayCollection();
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getUser(): ?User
  69.     {
  70.         return $this->user;
  71.     }
  72.     public function setUser(?User $user): self
  73.     {
  74.         $this->user $user;
  75.         return $this;
  76.     }
  77.     public function getContent(): ?string
  78.     {
  79.         return $this->content;
  80.     }
  81.     public function setContent(string $content): self
  82.     {
  83.         $this->content $content;
  84.         return $this;
  85.     }
  86.     public function getDate(): ?\DateTimeImmutable
  87.     {
  88.         return $this->date;
  89.     }
  90.     public function setDate(\DateTimeImmutable $date): self
  91.     {
  92.         $this->date $date;
  93.         return $this;
  94.     }
  95.     public function getCommentaireRep(): ?self
  96.     {
  97.         return $this->commentaireRep;
  98.     }
  99.     public function setCommentaireRep(?self $commentaireRep): self
  100.     {
  101.         $this->commentaireRep $commentaireRep;
  102.         return $this;
  103.     }
  104.     
  105.     public function addReponse(self $commentaire): self
  106.     {
  107.         if (!$this->commentaires->contains($commentaire)) {
  108.             $this->commentaires[] = $commentaire;
  109.             $commentaire->setCommentaireRep($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeReponse(self $commentaire): self
  114.     {
  115.         if ($this->commentaires->removeElement($commentaire)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($commentaire->getCommentaireRep() === $this) {
  118.                 $commentaire->setCommentaireRep(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.     public function getArticle(): ?Article
  124.     {
  125.         return $this->article;
  126.     }
  127.     public function setArticle(?Article $article): self
  128.     {
  129.         $this->article $article;
  130.         return $this;
  131.     }
  132.     public function toArray(): Array
  133.     {
  134.         $controllerExt = new ExtensionController();
  135.         $extImage $controllerExt->getExtImage();
  136.         $extPDF $controllerExt->getExtPDF();
  137.         $rep null;
  138.         $mainComment null;
  139.         if($this->commentaireRep != null){
  140.             $rep $this->commentaireRep->toArray();
  141.         }
  142.         if($this->commentaireRep != null){
  143.             $mainComment $this->commentaireRep->toArray();
  144.         }
  145.         $controller = new UpLoadController();
  146.         $count count($this->commentaires);    
  147.         $tmp = [
  148.             'id' => $this->id,
  149.             'user' =>  $this->user->toArray(),
  150.             'date' => $this->getDateFomatFR(),
  151.             'heure' => $this->getHeureFomatFR(),
  152.             'content' => $this->content
  153.             'timestamp'=> intval($this->date->getTimestamp()),
  154.             'commentaireRep' => $rep,
  155.             'mainComment' => $mainComment,
  156.             'nbRep' => $count,
  157.             // 'images' => [],
  158.             'image' => [],
  159.             'pdf' => [],
  160.             'fichier' => [],
  161.             'verified' => $this->verified
  162.         ];
  163.         foreach($this->getFichiers() as $fichier)
  164.         {
  165.             $arrayFichier $fichier->toArray(); 
  166.             $tmp["fichier"][] = $arrayFichier;
  167.             if(in_array($arrayFichier["ext"], $extImage)){
  168.                 // $tmp['images'][] = $arrayFichier;   
  169.                 $tmp['image'][] = $arrayFichier;   
  170.             }
  171.             if(in_array($arrayFichier["ext"], $extPDF)){
  172.                 $tmp['pdf'][] = $arrayFichier;   
  173.             }
  174.   
  175.         }
  176.         // foreach($this->getFichiers() as $fichier)
  177.         // {
  178.         //     $arrayFichier = $fichier->toArray();
  179.         //     $tmp['test'][] = $arrayFichier["ext"];      
  180.         // }
  181.         return $tmp;
  182.     }
  183.     public function getDateFomatFR()
  184.     {
  185.         setlocale(LC_TIME'fr_FR.UTF8''fr.UTF8''fr_FR.UTF-8''fr.UTF-8');
  186.         date_default_timezone_set('Europe/Paris');
  187.             $date $this->date->getTimestamp();
  188.             $res strftime('%A %d %B %Y',$date);
  189.         return $res;
  190.     }
  191.     public function getHeureFomatFR()
  192.     {
  193.         setlocale(LC_TIME'fr_FR.UTF8''fr.UTF8''fr_FR.UTF-8''fr.UTF-8');
  194.         date_default_timezone_set('Europe/Paris');
  195.             $date $this->date->getTimestamp();
  196.             $res strftime('%HH%M',$date);
  197.         return $res;
  198.     }
  199.     /**
  200.      * @return Collection|self[]
  201.      */
  202.     public function getCommentaires(): Collection
  203.     {
  204.         return $this->commentaires;
  205.     }
  206.     public function addCommentaire(self $commentaire): self
  207.     {
  208.         if (!$this->commentaires->contains($commentaire)) {
  209.             $this->commentaires[] = $commentaire;
  210.             $commentaire->setCommentaireRep($this);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeCommentaire(self $commentaire): self
  215.     {
  216.         if ($this->commentaires->removeElement($commentaire)) {
  217.             // set the owning side to null (unless already changed)
  218.             if ($commentaire->getCommentaireRep() === $this) {
  219.                 $commentaire->setCommentaireRep(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return Collection|Fichier[]
  226.      */
  227.     public function getFichiers(): Collection
  228.     {
  229.         return $this->fichiers;
  230.     }
  231.     public function addFichier(Fichier $fichier): self
  232.     {
  233.         if (!$this->fichiers->contains($fichier)) {
  234.             $this->fichiers[] = $fichier;
  235.             $fichier->setCommentaire($this);
  236.         }
  237.         return $this;
  238.     }
  239.     public function removeFichier(Fichier $fichier): self
  240.     {
  241.         if ($this->fichiers->removeElement($fichier)) {
  242.             // set the owning side to null (unless already changed)
  243.             if ($fichier->getCommentaire() === $this) {
  244.                 $fichier->setCommentaire(null);
  245.             }
  246.         }
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return Collection|ReportCommentaire[]
  251.      */
  252.     public function getReportCommentaires(): Collection
  253.     {
  254.         return $this->reportCommentaires;
  255.     }
  256.     public function addReportCommentaire(ReportCommentaire $reportCommentaire): self
  257.     {
  258.         if (!$this->reportCommentaires->contains($reportCommentaire)) {
  259.             $this->reportCommentaires[] = $reportCommentaire;
  260.             $reportCommentaire->setCommentaire($this);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeReportCommentaire(ReportCommentaire $reportCommentaire): self
  265.     {
  266.         if ($this->reportCommentaires->removeElement($reportCommentaire)) {
  267.             // set the owning side to null (unless already changed)
  268.             if ($reportCommentaire->getCommentaire() === $this) {
  269.                 $reportCommentaire->setCommentaire(null);
  270.             }
  271.         }
  272.         return $this;
  273.     }
  274.     public function to_arraytabcom(): Array
  275.     {            
  276.         $tmp = [
  277.             'id' => $this->id,
  278.             'user' => $this->user->to_arraytab(),
  279.             'content' => $this->content,
  280.             'date' => $this->date,
  281.             'commentaireRep' => $this->commentaireRep,
  282.             'article' => $this->article,
  283.             'commentaires' => $this->commentaires,
  284.             'fichiers' => $this->fichiers,
  285.             'reportCommentaires' => $this->reportCommentaires,
  286.             'verified' => $this->verified
  287.         ];
  288.         return $tmp;
  289.     }
  290.     public function getVerified(): ?bool
  291.     {
  292.         return $this->verified;
  293.     }
  294.     public function setVerified(bool $verified): self
  295.     {
  296.         $this->verified $verified;
  297.         return $this;
  298.     }
  299. }