<?php
namespace App\Entity;
use App\Enum\Status;
use App\Repository\ProjetRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity(repositoryClass: ProjetRepository::class)]
class Projet
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $code = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $title = null;
#[ORM\Column(length: 2000)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $objectifGeneral = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?\DateTimeInterface $dateDebut = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?\DateTimeInterface $dateFin = null;
#[ORM\Column]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?int $budget = null;
#[ORM\Column]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?int $contrubutionEtat = null;
#[ORM\OneToMany(mappedBy: 'projet', targetEntity: Resultat::class)]
private Collection $resultats;
#[ORM\Column(length: 255)]
private ?string $status = null;
#[ORM\Column(length: 255)]
private ?string $priority = null;
#[ORM\OneToMany(mappedBy: 'projet', targetEntity: ProjetBailleur::class)]
private Collection $projetBailleurs;
#[ORM\Column(length: 255)]
private ?string $privacy = null;
#[ORM\ManyToOne(inversedBy: 'projets')]
private ?CategorieProjet $categorieProjet = null;
#[ORM\ManyToOne(inversedBy: 'projets')]
private ?User $gestionnaire = null;
#[ORM\OneToMany(mappedBy: 'projet', targetEntity: ProjetMembre::class)]
private Collection $projetMembres;
#[ORM\ManyToOne(inversedBy: 'projets')]
private ?Currency $currency = null;
#[ORM\OneToMany(mappedBy: 'projet', targetEntity: Task::class)]
#[Groups(['taskProjet:read'])]
private Collection $tasks;
#[ORM\OneToMany(mappedBy: 'projet', targetEntity: Document::class, cascade: ['persist'])]
#[Groups(['documentProjet:read'])]
private Collection $documents;
public function __construct()
{
$this->resultats = new ArrayCollection();
$this->status = Status::BROUILLON;
$this->projetBailleurs = new ArrayCollection();
$this->projetMembres = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->documents = new ArrayCollection();
}
#[Assert\Callback]
public function validateDates(ExecutionContextInterface $context):void {
if( $this->dateFin < $this->dateDebut){
$context
->buildViolation('La date de fin ne peut pas être inférieure à la date de début')
->atPath('dateFin')
->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getObjectifGeneral(): ?string
{
return $this->objectifGeneral;
}
public function setObjectifGeneral(?string $objectifGeneral): self
{
$this->objectifGeneral = $objectifGeneral;
return $this;
}
public function getDateDebut(): ?\DateTimeInterface
{
return $this->dateDebut;
}
public function setDateDebut(?\DateTimeInterface $dateDebut): self
{
$this->dateDebut = $dateDebut;
return $this;
}
public function getDateFin(): ?\DateTimeInterface
{
return $this->dateFin;
}
public function setDateFin(?\DateTimeInterface $dateFin): self
{
$this->dateFin = $dateFin;
return $this;
}
public function getBudget(): ?int
{
return $this->budget;
}
public function setBudget(?int $budget): self
{
$this->budget = $budget;
return $this;
}
public function getContrubutionEtat(): ?int
{
return $this->contrubutionEtat;
}
public function setContrubutionEtat(?int $contrubutionEtat): self
{
$this->contrubutionEtat = $contrubutionEtat;
return $this;
}
/**
* @return Collection<int, Resultat>
*/
public function getResultats(): Collection
{
return $this->resultats;
}
public function addResultat(Resultat $resultat): self
{
if (!$this->resultats->contains($resultat)) {
$this->resultats->add($resultat);
$resultat->setProjet($this);
}
return $this;
}
public function removeResultat(Resultat $resultat): self
{
if ($this->resultats->removeElement($resultat)) {
// set the owning side to null (unless already changed)
if ($resultat->getProjet() === $this) {
$resultat->setProjet(null);
}
}
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getPriority(): ?string
{
return $this->priority;
}
public function setPriority(?string $priority): self
{
$this->priority = $priority;
return $this;
}
public function __toString()
{
return $this->getTitle();
}
/**
* @return Collection<int, ProjetBailleur>
*/
public function getProjetBailleurs(): Collection
{
return $this->projetBailleurs;
}
public function addProjetBailleur(ProjetBailleur $projetBailleur): self
{
if (!$this->projetBailleurs->contains($projetBailleur)) {
$this->projetBailleurs->add($projetBailleur);
$projetBailleur->setProjet($this);
}
return $this;
}
public function removeProjetBailleur(ProjetBailleur $projetBailleur): self
{
if ($this->projetBailleurs->removeElement($projetBailleur)) {
// set the owning side to null (unless already changed)
if ($projetBailleur->getProjet() === $this) {
$projetBailleur->setProjet(null);
}
}
return $this;
}
public function getPrivacy(): ?string
{
return $this->privacy;
}
public function setPrivacy(string $privacy): self
{
$this->privacy = $privacy;
return $this;
}
public function getCategorieProjet(): ?CategorieProjet
{
return $this->categorieProjet;
}
public function setCategorieProjet(?CategorieProjet $categorieProjet): self
{
$this->categorieProjet = $categorieProjet;
$this->categorieProjet->setIsDeleted(false);
return $this;
}
public function getGestionnaire(): ?User
{
return $this->gestionnaire;
}
public function setGestionnaire(?User $gestionnaire): self
{
$this->gestionnaire = $gestionnaire;
return $this;
}
/**
* @return Collection<int, ProjetMembre>
*/
public function getProjetMembres(): Collection
{
return $this->projetMembres;
}
public function addProjetMembre(ProjetMembre $projetMembre): self
{
if (!$this->projetMembres->contains($projetMembre)) {
$this->projetMembres->add($projetMembre);
$projetMembre->setProjet($this);
}
return $this;
}
public function removeProjetMembre(ProjetMembre $projetMembre): self
{
if ($this->projetMembres->removeElement($projetMembre)) {
// set the owning side to null (unless already changed)
if ($projetMembre->getProjet() === $this) {
$projetMembre->setProjet(null);
}
}
return $this;
}
public function getCurrency(): ?Currency
{
return $this->currency;
}
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTasks(Task $tasks): self
{
if (!$this->tasks->contains($tasks)) {
$this->tasks->add($tasks);
$tasks->getPriority()->setIsDeleted(false);
$tasks->setProjet($this);
}
return $this;
}
public function removeTasks(Task $tasks): self
{
if ($this->tasks->removeElement($tasks)) {
// set the owning side to null (unless already changed)
if ($tasks->getProjet() === $this) {
$tasks->getPriority()->setIsDeleted(true);
$tasks->setProjet(null);
}
}
return $this;
}
public function getMembreProjet(): array
{
$membres = [];
foreach ($this->projetMembres as $membre) {
$membres[] = $membre->getUser();
}
return $membres;
}
public function getUserNotMembre(array $users): array
{
$membres = $this->getMembreProjet();
$notMembre = array_diff($users, $membres);
return $notMembre;
}
public function taskValided() {
$cpt = 0;
foreach($this->tasks as $task) {
if($task->isIsValided() == true){
$cpt = $cpt + 1;
}
}
return $cpt;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setProjet($this);
}
return $this;
}
public function removeDocument(Document $document): static
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getProjet() === $this) {
$document->setProjet(null);
}
}
return $this;
}
}