<?php
namespace App\Entity;
use App\Repository\ProjectRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProjectRepository::class)]
class Project
{
public const TO_PROCESS = 1;
public const FINISHED = 2;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $description = null;
#[ORM\Column]
private ?int $progress = 0;
#[ORM\Column]
private ?int $status = self::TO_PROCESS;
#[ORM\Column]
private ?DateTimeImmutable $added_at = null;
#[ORM\Column(nullable: true)]
private ?DateTimeImmutable $updated_at = null;
#[ORM\Column]
private ?int $is_active = 1;
#[ORM\OneToMany(mappedBy: 'project', targetEntity: Task::class, orphanRemoval: true)]
private Collection $task;
#[ORM\ManyToOne(inversedBy: 'projects')]
private ?User $user = null;
#[ORM\OneToOne(mappedBy: 'project', cascade: ['persist', 'remove'])]
private ?Step $step = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $endAt = null;
#[ORM\OneToMany(mappedBy: 'project', targetEntity: Ressource::class, orphanRemoval: true)]
private Collection $ressource;
#[ORM\OneToMany(mappedBy: 'project', targetEntity: RessourceDirectory::class, orphanRemoval: true)]
#[ORM\OrderBy(['id' => 'DESC'])]
private Collection $ressourceDirectories;
public function __toString(): string
{
return $this->name;
}
public function __construct()
{
$this->setAddedAt(new DateTimeImmutable());
$this->task = new ArrayCollection();
$this->ressource = new ArrayCollection();
$this->ressourceDirectories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getProgress(): ?int
{
return $this->progress;
}
public function setProgress(int $progress): self
{
$this->progress = $progress;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getAddedAt(): ?DateTimeImmutable
{
return $this->added_at;
}
public function setAddedAt(DateTimeImmutable $added_at): self
{
$this->added_at = $added_at;
return $this;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updated_at;
}
public function setUpdatedAt(?DateTimeImmutable $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getIsActive(): ?int
{
return $this->is_active;
}
public function setIsActive(?int $is_active): self
{
$this->is_active = $is_active;
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->task;
}
public function addTask(Task $task): self
{
if (!$this->task->contains($task)) {
$this->task->add($task);
$task->setProject($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->task->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getProject() === $this) {
$task->setProject(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getStep(): ?Step
{
return $this->step;
}
public function setStep(?Step $step): self
{
// unset the owning side of the relation if necessary
if ($step === null && $this->step !== null) {
$this->step->setProject(null);
}
// set the owning side of the relation if necessary
if ($step !== null && $step->getProject() !== $this) {
$step->setProject($this);
}
$this->step = $step;
return $this;
}
/**
* @return Collection<int, Ressource>
*/
public function getRessources(): Collection
{
return $this->ressource;
}
public function addRessource(Ressource $ressource): self
{
if (!$this->ressource->contains($ressource)) {
$this->ressource->add($ressource);
$ressource->setProject($this);
}
return $this;
}
public function removeRessource(Ressource $ressource): self
{
if ($this->ressource->removeElement($ressource)) {
// set the owning side to null (unless already changed)
if ($ressource->getProject() === $this) {
$ressource->setProject(null);
}
}
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->endAt;
}
public function setEndAt(?\DateTimeImmutable $endAt): self
{
$this->endAt = $endAt;
return $this;
}
/**
* @return Collection<int, Ressource>
*/
public function getRessource(): Collection
{
return $this->ressource;
}
/**
* @return Collection<int, RessourceDirectory>
*/
public function getRessourceDirectories(): Collection
{
return $this->ressourceDirectories;
}
public function addRessourceDirectory(RessourceDirectory $ressourceDirectory): self
{
if (!$this->ressourceDirectories->contains($ressourceDirectory)) {
$this->ressourceDirectories->add($ressourceDirectory);
$ressourceDirectory->setProject($this);
}
return $this;
}
public function removeRessourceDirectory(RessourceDirectory $ressourceDirectory): self
{
if ($this->ressourceDirectories->removeElement($ressourceDirectory)) {
// set the owning side to null (unless already changed)
if ($ressourceDirectory->getProject() === $this) {
$ressourceDirectory->setProject(null);
}
}
return $this;
}
}