Files
contribIA/src/Entity/Projet.php
2025-10-23 18:31:42 +02:00

167 lines
4.4 KiB
PHP

<?php
namespace App\Entity;
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\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ProjetRepository::class)]
#[ORM\Table(name: 'projet')]
class Projet
{
public const STATUT_EN_COURS = 'en_cours';
public const STATUT_TERMINE = 'termine';
public const STATUT_ANNULE = 'annule';
public const STATUT_EN_ATTENTE = 'en_attente';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 50)]
#[Assert\NotBlank(message: 'Le nom du projet est obligatoire.')]
#[Assert\Length(max: 50, maxMessage: 'Le nom ne peut pas dépasser {{ limit }} caractères.')]
private ?string $nom = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $commentaire = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateLancement = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Assert\GreaterThanOrEqual(propertyPath: 'dateLancement', message: 'La date de clôture doit être après la date de lancement.')]
private ?\DateTimeInterface $dateCloture = null;
#[ORM\Column(type: 'string', length: 20)]
#[Assert\NotBlank(message: 'Le statut est obligatoire.')]
#[Assert\Choice(
choices: [self::STATUT_EN_COURS, self::STATUT_TERMINE, self::STATUT_ANNULE, self::STATUT_EN_ATTENTE],
message: 'Le statut doit être valide.'
)]
private ?string $statut = null;
#[ORM\OneToMany(targetEntity: Contribution::class, mappedBy: 'projet', cascade: ['persist'], orphanRemoval: true)]
private Collection $contributions;
public function __construct()
{
$this->contributions = new ArrayCollection();
$this->statut = self::STATUT_EN_ATTENTE;
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): static
{
$this->commentaire = $commentaire;
return $this;
}
public function getDateLancement(): ?\DateTimeInterface
{
return $this->dateLancement;
}
public function setDateLancement(?\DateTimeInterface $dateLancement): static
{
$this->dateLancement = $dateLancement;
return $this;
}
public function getDateCloture(): ?\DateTimeInterface
{
return $this->dateCloture;
}
public function setDateCloture(?\DateTimeInterface $dateCloture): static
{
$this->dateCloture = $dateCloture;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
/**
* @return Collection<int, Contribution>
*/
public function getContributions(): Collection
{
return $this->contributions;
}
public function addContribution(Contribution $contribution): static
{
if (!$this->contributions->contains($contribution)) {
$this->contributions->add($contribution);
$contribution->setProjet($this);
}
return $this;
}
public function removeContribution(Contribution $contribution): static
{
if ($this->contributions->removeElement($contribution)) {
// set the owning side to null (unless already changed)
if ($contribution->getProjet() === $this) {
$contribution->setProjet(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->nom ?? '';
}
public static function getStatutChoices(): array
{
return [
'En attente' => self::STATUT_EN_ATTENTE,
'En cours' => self::STATUT_EN_COURS,
'Terminé' => self::STATUT_TERMINE,
'Annulé' => self::STATUT_ANNULE,
];
}
}