src/Entity/Ticket.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TicketRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassTicketRepository::class)]
  9. #[ORM\Index(columns: ['statut'], name'idx_ticket_statut')]
  10. #[ORM\Index(columns: ['priorite'], name'idx_ticket_priorite')]
  11. #[ORM\Index(columns: ['date_creation'], name'idx_ticket_date')]
  12. class Ticket
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length20uniquetrue)]
  19.     private ?string $numeroTicket null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $titre null;
  22.     #[ORM\Column(typeTypes::TEXT)]
  23.     private ?string $description null;
  24.     #[ORM\Column(length50)]
  25.     private ?string $type 'support'
  26.     // support, bug, demande_fonctionnalite, demande_client, tache, incident, autre
  27.     #[ORM\Column(length50)]
  28.     private ?string $statut 'ouvert'
  29.     // ouvert, en_cours, en_attente, resolu, ferme, annule
  30.     #[ORM\Column(length50)]
  31.     private ?string $priorite 'moyenne'
  32.     // basse, moyenne, haute, urgente, critique
  33.     #[ORM\Column(length50nullabletrue)]
  34.     private ?string $categorie null
  35.     // technique, commercial, administratif, rh, finance, stock, autre
  36.     #[ORM\ManyToOne(targetEntityUser::class)]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     private ?User $createdBy null;
  39.     #[ORM\ManyToOne(targetEntityUser::class)]
  40.     private ?User $assignedTo null;
  41.     #[ORM\ManyToOne(targetEntityClient::class)]
  42.     private ?Client $client null;
  43.     #[ORM\ManyToOne(targetEntityBoutique::class)]
  44.     private ?Boutique $boutique null;
  45.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  46.     private ?\DateTimeInterface $dateCreation null;
  47.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  48.     private ?\DateTimeInterface $dateEcheance null;
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  50.     private ?\DateTimeInterface $dateResolution null;
  51.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  52.     private ?\DateTimeInterface $dateFermeture null;
  53.     #[ORM\Column(nullabletrue)]
  54.     private ?\DateTimeImmutable $updatedAt null;
  55.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  56.     private ?int $tempsEstime null// en minutes
  57.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  58.     private ?int $tempsReel null// en minutes
  59.     #[ORM\OneToMany(mappedBy'ticket'targetEntityCommentaireTicket::class, orphanRemovaltrue)]
  60.     #[ORM\OrderBy(['createdAt' => 'DESC'])]
  61.     private Collection $commentaires;
  62.     #[ORM\OneToMany(mappedBy'ticket'targetEntityPieceJointeTicket::class, orphanRemovaltrue)]
  63.     private Collection $piecesJointes;
  64.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  65.     private ?string $resolution null;
  66.     #[ORM\ManyToOne(targetEntityUser::class)]
  67.     private ?User $resolvedBy null;
  68.     #[ORM\ManyToMany(targetEntityUser::class)]
  69.     #[ORM\JoinTable(name'ticket_watchers')]
  70.     private Collection $watchers;
  71.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  72.     private ?array $tags = [];
  73.     public function __construct()
  74.     {
  75.         $this->commentaires = new ArrayCollection();
  76.         $this->piecesJointes = new ArrayCollection();
  77.         $this->watchers = new ArrayCollection();
  78.         $this->dateCreation = new \DateTime();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getNumeroTicket(): ?string
  85.     {
  86.         return $this->numeroTicket;
  87.     }
  88.     public function setNumeroTicket(string $numeroTicket): static
  89.     {
  90.         $this->numeroTicket $numeroTicket;
  91.         return $this;
  92.     }
  93.     public function getTitre(): ?string
  94.     {
  95.         return $this->titre;
  96.     }
  97.     public function setTitre(string $titre): static
  98.     {
  99.         $this->titre $titre;
  100.         return $this;
  101.     }
  102.     public function getDescription(): ?string
  103.     {
  104.         return $this->description;
  105.     }
  106.     public function setDescription(string $description): static
  107.     {
  108.         $this->description $description;
  109.         return $this;
  110.     }
  111.     public function getType(): ?string
  112.     {
  113.         return $this->type;
  114.     }
  115.     public function setType(string $type): static
  116.     {
  117.         $this->type $type;
  118.         return $this;
  119.     }
  120.     public function getStatut(): ?string
  121.     {
  122.         return $this->statut;
  123.     }
  124.     public function setStatut(string $statut): static
  125.     {
  126.         $oldStatut $this->statut;
  127.         $this->statut $statut;
  128.         
  129.         // Enregistrer les dates selon le statut
  130.         if ($statut === 'resolu' && $oldStatut !== 'resolu') {
  131.             $this->dateResolution = new \DateTime();
  132.         }
  133.         
  134.         if ($statut === 'ferme' && $oldStatut !== 'ferme') {
  135.             $this->dateFermeture = new \DateTime();
  136.         }
  137.         
  138.         return $this;
  139.     }
  140.     public function getPriorite(): ?string
  141.     {
  142.         return $this->priorite;
  143.     }
  144.     public function setPriorite(string $priorite): static
  145.     {
  146.         $this->priorite $priorite;
  147.         return $this;
  148.     }
  149.     public function getCategorie(): ?string
  150.     {
  151.         return $this->categorie;
  152.     }
  153.     public function setCategorie(?string $categorie): static
  154.     {
  155.         $this->categorie $categorie;
  156.         return $this;
  157.     }
  158.     public function getCreatedBy(): ?User
  159.     {
  160.         return $this->createdBy;
  161.     }
  162.     public function setCreatedBy(?User $createdBy): static
  163.     {
  164.         $this->createdBy $createdBy;
  165.         return $this;
  166.     }
  167.     public function getAssignedTo(): ?User
  168.     {
  169.         return $this->assignedTo;
  170.     }
  171.     public function setAssignedTo(?User $assignedTo): static
  172.     {
  173.         $this->assignedTo $assignedTo;
  174.         return $this;
  175.     }
  176.     public function getClient(): ?Client
  177.     {
  178.         return $this->client;
  179.     }
  180.     public function setClient(?Client $client): static
  181.     {
  182.         $this->client $client;
  183.         return $this;
  184.     }
  185.     public function getBoutique(): ?Boutique
  186.     {
  187.         return $this->boutique;
  188.     }
  189.     public function setBoutique(?Boutique $boutique): static
  190.     {
  191.         $this->boutique $boutique;
  192.         return $this;
  193.     }
  194.     public function getDateCreation(): ?\DateTimeInterface
  195.     {
  196.         return $this->dateCreation;
  197.     }
  198.     public function setDateCreation(\DateTimeInterface $dateCreation): static
  199.     {
  200.         $this->dateCreation $dateCreation;
  201.         return $this;
  202.     }
  203.     public function getDateEcheance(): ?\DateTimeInterface
  204.     {
  205.         return $this->dateEcheance;
  206.     }
  207.     public function setDateEcheance(?\DateTimeInterface $dateEcheance): static
  208.     {
  209.         $this->dateEcheance $dateEcheance;
  210.         return $this;
  211.     }
  212.     public function getDateResolution(): ?\DateTimeInterface
  213.     {
  214.         return $this->dateResolution;
  215.     }
  216.     public function setDateResolution(?\DateTimeInterface $dateResolution): static
  217.     {
  218.         $this->dateResolution $dateResolution;
  219.         return $this;
  220.     }
  221.     public function getDateFermeture(): ?\DateTimeInterface
  222.     {
  223.         return $this->dateFermeture;
  224.     }
  225.     public function setDateFermeture(?\DateTimeInterface $dateFermeture): static
  226.     {
  227.         $this->dateFermeture $dateFermeture;
  228.         return $this;
  229.     }
  230.     public function getUpdatedAt(): ?\DateTimeImmutable
  231.     {
  232.         return $this->updatedAt;
  233.     }
  234.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
  235.     {
  236.         $this->updatedAt $updatedAt;
  237.         return $this;
  238.     }
  239.     public function getTempsEstime(): ?int
  240.     {
  241.         return $this->tempsEstime;
  242.     }
  243.     public function setTempsEstime(?int $tempsEstime): static
  244.     {
  245.         $this->tempsEstime $tempsEstime;
  246.         return $this;
  247.     }
  248.     public function getTempsReel(): ?int
  249.     {
  250.         return $this->tempsReel;
  251.     }
  252.     public function setTempsReel(?int $tempsReel): static
  253.     {
  254.         $this->tempsReel $tempsReel;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return Collection<int, CommentaireTicket>
  259.      */
  260.     public function getCommentaires(): Collection
  261.     {
  262.         return $this->commentaires;
  263.     }
  264.     public function addCommentaire(CommentaireTicket $commentaire): static
  265.     {
  266.         if (!$this->commentaires->contains($commentaire)) {
  267.             $this->commentaires->add($commentaire);
  268.             $commentaire->setTicket($this);
  269.         }
  270.         return $this;
  271.     }
  272.     public function removeCommentaire(CommentaireTicket $commentaire): static
  273.     {
  274.         if ($this->commentaires->removeElement($commentaire)) {
  275.             if ($commentaire->getTicket() === $this) {
  276.                 $commentaire->setTicket(null);
  277.             }
  278.         }
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection<int, PieceJointeTicket>
  283.      */
  284.     public function getPiecesJointes(): Collection
  285.     {
  286.         return $this->piecesJointes;
  287.     }
  288.     public function addPiecesJointe(PieceJointeTicket $piecesJointe): static
  289.     {
  290.         if (!$this->piecesJointes->contains($piecesJointe)) {
  291.             $this->piecesJointes->add($piecesJointe);
  292.             $piecesJointe->setTicket($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removePiecesJointe(PieceJointeTicket $piecesJointe): static
  297.     {
  298.         if ($this->piecesJointes->removeElement($piecesJointe)) {
  299.             if ($piecesJointe->getTicket() === $this) {
  300.                 $piecesJointe->setTicket(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     public function getResolution(): ?string
  306.     {
  307.         return $this->resolution;
  308.     }
  309.     public function setResolution(?string $resolution): static
  310.     {
  311.         $this->resolution $resolution;
  312.         return $this;
  313.     }
  314.     public function getResolvedBy(): ?User
  315.     {
  316.         return $this->resolvedBy;
  317.     }
  318.     public function setResolvedBy(?User $resolvedBy): static
  319.     {
  320.         $this->resolvedBy $resolvedBy;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return Collection<int, User>
  325.      */
  326.     public function getWatchers(): Collection
  327.     {
  328.         return $this->watchers;
  329.     }
  330.     public function addWatcher(User $watcher): static
  331.     {
  332.         if (!$this->watchers->contains($watcher)) {
  333.             $this->watchers->add($watcher);
  334.         }
  335.         return $this;
  336.     }
  337.     public function removeWatcher(User $watcher): static
  338.     {
  339.         $this->watchers->removeElement($watcher);
  340.         return $this;
  341.     }
  342.     public function getTags(): ?array
  343.     {
  344.         return $this->tags;
  345.     }
  346.     public function setTags(?array $tags): static
  347.     {
  348.         $this->tags $tags;
  349.         return $this;
  350.     }
  351.     public function genererNumeroTicket(): string
  352.     {
  353.         $prefixes = [
  354.             'support' => 'SUP',
  355.             'bug' => 'BUG',
  356.             'demande_fonctionnalite' => 'FEAT',
  357.             'demande_client' => 'CLI',
  358.             'tache' => 'TSK',
  359.             'incident' => 'INC',
  360.         ];
  361.         
  362.         $prefix $prefixes[$this->type] ?? 'TKT';
  363.         $date $this->dateCreation ?? new \DateTime();
  364.         
  365.         return $prefix '-' $date->format('Ymd') . '-' str_pad($this->id ?? 04'0'STR_PAD_LEFT);
  366.     }
  367.     public function estEnRetard(): bool
  368.     {
  369.         if (!$this->dateEcheance || in_array($this->statut, ['resolu''ferme''annule'])) {
  370.             return false;
  371.         }
  372.         
  373.         return new \DateTime() > $this->dateEcheance;
  374.     }
  375.     public function getDelai(): ?int
  376.     {
  377.         if (!$this->dateEcheance) {
  378.             return null;
  379.         }
  380.         
  381.         $now = new \DateTime();
  382.         $diff $now->diff($this->dateEcheance);
  383.         
  384.         return $diff->invert ? -$diff->days $diff->days;
  385.     }
  386.     public function getDureeTraitement(): ?int
  387.     {
  388.         if (!$this->dateResolution) {
  389.             return null;
  390.         }
  391.         
  392.         $diff $this->dateCreation->diff($this->dateResolution);
  393.         return $diff->days;
  394.     }
  395.     public function __toString(): string
  396.     {
  397.         return $this->numeroTicket ?? $this->titre ?? 'Nouveau ticket';
  398.     }
  399. }