<?php
namespace App\Entity;
use App\Enum\PipelineIdentiteVisuelleMajStatus;
use App\Repository\PipelineIdentiteVisuelleMajRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PipelineIdentiteVisuelleMajRepository::class)]
class PipelineIdentiteVisuelleMaj
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: AccountingFirm::class)]
#[ORM\JoinColumn(nullable: false)]
private ?AccountingFirm $accountingFirm = null;
#[ORM\Column(type: 'string', length: 30)]
private string $status = PipelineIdentiteVisuelleMajStatus::OPEN;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $trelloCardId = null;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $updatedAt;
#[ORM\OneToMany(mappedBy: 'pipeline', targetEntity: PipelineIdentiteVisuelleMajItem::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $items;
public function __construct()
{
$this->items = new ArrayCollection();
$now = new \DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
}
public function getId(): ?int { return $this->id; }
public function getAccountingFirm(): ?AccountingFirm { return $this->accountingFirm; }
public function setAccountingFirm(AccountingFirm $firm): self { $this->accountingFirm = $firm; return $this; }
public function getStatus(): string { return $this->status; }
public function setStatus(string $status): self { $this->status = $status; return $this; }
public function getTrelloCardId(): ?string { return $this->trelloCardId; }
public function setTrelloCardId(?string $id): self { $this->trelloCardId = $id; return $this; }
public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
public function setCreatedAt(\DateTimeImmutable $dt): self { $this->createdAt = $dt; return $this; }
public function getUpdatedAt(): \DateTimeImmutable { return $this->updatedAt; }
public function setUpdatedAt(\DateTimeImmutable $dt): self { $this->updatedAt = $dt; return $this; }
/** @return Collection<int, PipelineIdentiteVisuelleMajItem> */
public function getItems(): Collection { return $this->items; }
public function addItem(PipelineIdentiteVisuelleMajItem $item): self
{
if (!$this->items->contains($item)) {
$this->items->add($item);
$item->setPipeline($this);
}
return $this;
}
public function removeItem(PipelineIdentiteVisuelleMajItem $item): self
{
if ($this->items->removeElement($item)) {
if ($item->getPipeline() === $this) {
$item->setPipeline(null);
}
}
return $this;
}
public function refreshGlobalStatus(): void
{
foreach ($this->items as $item) {
if ($item->getStatus() !== \App\Enum\PipelineIdentiteVisuelleMajItemStatus::VALIDATED) {
$this->status = PipelineIdentiteVisuelleMajStatus::OPEN;
return;
}
}
$this->status = PipelineIdentiteVisuelleMajStatus::DONE;
}
}