src/Entity/Projet.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Status;
  4. use App\Repository\ProjetRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  12. #[ORM\Entity(repositoryClass: ProjetRepository::class)]
  13. class Projet
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id = null;
  19.     #[ORM\Column(length: 255)]
  20.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  21.     private ?string $code = null;
  22.     #[ORM\Column(length: 255)]
  23.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  24.     private ?string $title = null;
  25.     #[ORM\Column(length: 2000)]
  26.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  27.     private ?string $objectifGeneral = null;
  28.     #[ORM\Column(type: Types::DATE_MUTABLE)]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?\DateTimeInterface $dateDebut = null;
  31.     #[ORM\Column(type: Types::DATE_MUTABLE)]
  32.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  33.     private ?\DateTimeInterface $dateFin = null;
  34.     #[ORM\Column]
  35.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  36.     private ?int $budget = null;
  37.     #[ORM\Column]
  38.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  39.     private ?int $contrubutionEtat = null;
  40.     #[ORM\OneToMany(mappedBy: 'projet', targetEntity: Resultat::class)]
  41.     private Collection $resultats;
  42.     #[ORM\Column(length: 255)]
  43.     private ?string $status = null;
  44.     #[ORM\Column(length: 255)]
  45.     private ?string $priority = null;
  46.     #[ORM\OneToMany(mappedBy: 'projet', targetEntity: ProjetBailleur::class)]
  47.     private Collection $projetBailleurs;
  48.     #[ORM\Column(length: 255)]
  49.     private ?string $privacy = null;
  50.     #[ORM\ManyToOne(inversedBy: 'projets')]
  51.     private ?CategorieProjet $categorieProjet = null;
  52.     #[ORM\ManyToOne(inversedBy: 'projets')]
  53.     private ?User $gestionnaire = null;
  54.     #[ORM\OneToMany(mappedBy: 'projet', targetEntity: ProjetMembre::class)]
  55.     private Collection $projetMembres;
  56.     #[ORM\ManyToOne(inversedBy: 'projets')]
  57.     private ?Currency $currency = null;
  58.     #[ORM\OneToMany(mappedBy: 'projet', targetEntity: Task::class)]
  59.     #[Groups(['taskProjet:read'])]
  60.     private Collection $tasks;
  61.     #[ORM\OneToMany(mappedBy: 'projet', targetEntity: Document::class, cascade: ['persist'])]
  62.     #[Groups(['documentProjet:read'])]
  63.     private Collection $documents;
  64.     public function __construct()
  65.     {
  66.         $this->resultats = new ArrayCollection();
  67.         $this->status = Status::BROUILLON;
  68.         $this->projetBailleurs = new ArrayCollection();
  69.         $this->projetMembres = new ArrayCollection();
  70.         $this->tasks = new ArrayCollection();
  71.         $this->documents = new ArrayCollection();
  72.     }
  73.     #[Assert\Callback]
  74.     public function validateDates(ExecutionContextInterface $context):void {
  75.         if( $this->dateFin < $this->dateDebut){
  76.             $context
  77.                 ->buildViolation('La date de fin ne peut pas être inférieure à la date de début')
  78.                 ->atPath('dateFin')
  79.                 ->addViolation();
  80.         }
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getCode(): ?string
  87.     {
  88.         return $this->code;
  89.     }
  90.     public function setCode(string $code): self
  91.     {
  92.         $this->code = $code;
  93.         return $this;
  94.     }
  95.     public function getTitle(): ?string
  96.     {
  97.         return $this->title;
  98.     }
  99.     public function setTitle(?string $title): self
  100.     {
  101.         $this->title = $title;
  102.         return $this;
  103.     }
  104.     public function getObjectifGeneral(): ?string
  105.     {
  106.         return $this->objectifGeneral;
  107.     }
  108.     public function setObjectifGeneral(?string $objectifGeneral): self
  109.     {
  110.         $this->objectifGeneral = $objectifGeneral;
  111.         return $this;
  112.     }
  113.     public function getDateDebut(): ?\DateTimeInterface
  114.     {
  115.         return $this->dateDebut;
  116.     }
  117.     public function setDateDebut(?\DateTimeInterface $dateDebut): self
  118.     {
  119.         $this->dateDebut = $dateDebut;
  120.         return $this;
  121.     }
  122.     public function getDateFin(): ?\DateTimeInterface
  123.     {
  124.         return $this->dateFin;
  125.     }
  126.     public function setDateFin(?\DateTimeInterface $dateFin): self
  127.     {
  128.         $this->dateFin = $dateFin;
  129.         return $this;
  130.     }
  131.     public function getBudget(): ?int
  132.     {
  133.         return $this->budget;
  134.     }
  135.     public function setBudget(?int $budget): self
  136.     {
  137.         $this->budget = $budget;
  138.         return $this;
  139.     }
  140.     public function getContrubutionEtat(): ?int
  141.     {
  142.         return $this->contrubutionEtat;
  143.     }
  144.     public function setContrubutionEtat(?int $contrubutionEtat): self
  145.     {
  146.         $this->contrubutionEtat = $contrubutionEtat;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection<int, Resultat>
  151.      */
  152.     public function getResultats(): Collection
  153.     {
  154.         return $this->resultats;
  155.     }
  156.     public function addResultat(Resultat $resultat): self
  157.     {
  158.         if (!$this->resultats->contains($resultat)) {
  159.             $this->resultats->add($resultat);
  160.             $resultat->setProjet($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeResultat(Resultat $resultat): self
  165.     {
  166.         if ($this->resultats->removeElement($resultat)) {
  167.             // set the owning side to null (unless already changed)
  168.             if ($resultat->getProjet() === $this) {
  169.                 $resultat->setProjet(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174.     public function getStatus(): ?string
  175.     {
  176.         return $this->status;
  177.     }
  178.     public function setStatus(?string $status): self
  179.     {
  180.         $this->status = $status;
  181.         return $this;
  182.     }
  183.     public function getPriority(): ?string
  184.     {
  185.         return $this->priority;
  186.     }
  187.     public function setPriority(?string $priority): self
  188.     {
  189.         $this->priority = $priority;
  190.         return $this;
  191.     }
  192.     public function __toString()
  193.     {
  194.         return $this->getTitle();
  195.     }
  196.     /**
  197.      * @return Collection<int, ProjetBailleur>
  198.      */
  199.     public function getProjetBailleurs(): Collection
  200.     {
  201.         return $this->projetBailleurs;
  202.     }
  203.     public function addProjetBailleur(ProjetBailleur $projetBailleur): self
  204.     {
  205.         if (!$this->projetBailleurs->contains($projetBailleur)) {
  206.             $this->projetBailleurs->add($projetBailleur);
  207.             $projetBailleur->setProjet($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeProjetBailleur(ProjetBailleur $projetBailleur): self
  212.     {
  213.         if ($this->projetBailleurs->removeElement($projetBailleur)) {
  214.             // set the owning side to null (unless already changed)
  215.             if ($projetBailleur->getProjet() === $this) {
  216.                 $projetBailleur->setProjet(null);
  217.             }
  218.         }
  219.         return $this;
  220.     }
  221.     public function getPrivacy(): ?string
  222.     {
  223.         return $this->privacy;
  224.     }
  225.     public function setPrivacy(string $privacy): self
  226.     {
  227.         $this->privacy = $privacy;
  228.         return $this;
  229.     }
  230.     public function getCategorieProjet(): ?CategorieProjet
  231.     {
  232.         return $this->categorieProjet;
  233.     }
  234.     public function setCategorieProjet(?CategorieProjet $categorieProjet): self
  235.     {
  236.         $this->categorieProjet = $categorieProjet;
  237.         $this->categorieProjet->setIsDeleted(false);
  238.         return $this;
  239.     }
  240.     public function getGestionnaire(): ?User
  241.     {
  242.         return $this->gestionnaire;
  243.     }
  244.     public function setGestionnaire(?User $gestionnaire): self
  245.     {
  246.         $this->gestionnaire = $gestionnaire;
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return Collection<int, ProjetMembre>
  251.      */
  252.     public function getProjetMembres(): Collection
  253.     {
  254.         return $this->projetMembres;
  255.     }
  256.     public function addProjetMembre(ProjetMembre $projetMembre): self
  257.     {
  258.         if (!$this->projetMembres->contains($projetMembre)) {
  259.             $this->projetMembres->add($projetMembre);
  260.             $projetMembre->setProjet($this);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeProjetMembre(ProjetMembre $projetMembre): self
  265.     {
  266.         if ($this->projetMembres->removeElement($projetMembre)) {
  267.             // set the owning side to null (unless already changed)
  268.             if ($projetMembre->getProjet() === $this) {
  269.                 $projetMembre->setProjet(null);
  270.             }
  271.         }
  272.         return $this;
  273.     }
  274.     public function getCurrency(): ?Currency
  275.     {
  276.         return $this->currency;
  277.     }
  278.     public function setCurrency(?Currency $currency): self
  279.     {
  280.         $this->currency = $currency;
  281.         return $this;
  282.     }
  283.     /**
  284.      * @return Collection<int, Task>
  285.      */
  286.     public function getTasks(): Collection
  287.     {
  288.         return $this->tasks;
  289.     }
  290.     public function addTasks(Task $tasks): self
  291.     {
  292.         if (!$this->tasks->contains($tasks)) {
  293.             $this->tasks->add($tasks);
  294.             $tasks->getPriority()->setIsDeleted(false);
  295.             $tasks->setProjet($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removeTasks(Task $tasks): self
  300.     {
  301.         if ($this->tasks->removeElement($tasks)) {
  302.             // set the owning side to null (unless already changed)
  303.             if ($tasks->getProjet() === $this) {
  304.                 $tasks->getPriority()->setIsDeleted(true);
  305.                 $tasks->setProjet(null);
  306.             }
  307.         }
  308.         return $this;
  309.     }
  310.     public function getMembreProjet(): array
  311.     {
  312.         $membres = [];
  313.         foreach ($this->projetMembres as $membre) {
  314.             $membres[] = $membre->getUser();
  315.         }
  316.         return $membres;
  317.     }
  318.     public function getUserNotMembre(array $users): array
  319.     {
  320.         $membres = $this->getMembreProjet();
  321.         $notMembre = array_diff($users, $membres);
  322.         return $notMembre;
  323.     }
  324.     public function taskValided() {
  325.         $cpt = 0;
  326.         foreach($this->tasks as $task) {
  327.             if($task->isIsValided() == true){
  328.                 $cpt = $cpt + 1;
  329.             }
  330.         }
  331.         
  332.         return $cpt;
  333.     }
  334.     /**
  335.      * @return Collection<int, Document>
  336.      */
  337.     public function getDocuments(): Collection
  338.     {
  339.         return $this->documents;
  340.     }
  341.     public function addDocument(Document $document): static
  342.     {
  343.         if (!$this->documents->contains($document)) {
  344.             $this->documents->add($document);
  345.             $document->setProjet($this);
  346.         }
  347.         return $this;
  348.     }
  349.     public function removeDocument(Document $document): static
  350.     {
  351.         if ($this->documents->removeElement($document)) {
  352.             // set the owning side to null (unless already changed)
  353.             if ($document->getProjet() === $this) {
  354.                 $document->setProjet(null);
  355.             }
  356.         }
  357.         return $this;
  358.     }
  359. }