<?php
namespace App\Entity;
use App\Repository\ChecklistRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ChecklistRepository::class)]
class Checklist
{
// Enum values for ChecklistType
public const TYPE_ONBOARDING = 'ONBOARDING';
public const TYPE_PROJECT = 'PROJECT';
public const TYPE_DEPARTMENT = 'DEPARTMENT';
public const TYPE_OFFBOARDING = 'OFFBOARDING';
public const TYPE_PERMANENT = 'PERMANENT';
// Enum values for ChecklistStatus
public const STATUS_ACTIVE = 'ACTIVE';
public const STATUS_INACTIVE = 'INACTIVE';
public const STATUS_DRAFT = 'DRAFT';
public const STATUS_COMPLETED = 'COMPLETED';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 50)]
private ?string $type = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dueDate = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startDate = null;
#[ORM\Column(length: 50)]
private ?string $status = null;
#[ORM\Column]
private ?bool $isTemplate = null;
#[ORM\Column(nullable: true)]
private ?int $position = null;
#[ORM\OneToMany(mappedBy: 'checklist', targetEntity: ChecklistTask::class, orphanRemoval: true)]
private Collection $tasks;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'checklistsFromTemplate')]
private ?self $template = null;
#[ORM\OneToMany(mappedBy: 'template', targetEntity: self::class)]
private Collection $checklistsFromTemplate;
#[ORM\ManyToOne(inversedBy: 'checklists', targetEntity: Project::class, cascade: ['persist'])]
private ?Project $project = null;
#[ORM\ManyToOne(inversedBy: 'checklists')]
private ?Department $department = null;
#[ORM\ManyToOne(inversedBy: 'checklistsAsAssignee')]
#[ORM\JoinColumn(name: "default_assignee_id", referencedColumnName: "id", nullable: true, onDelete: "SET NULL")]
private ?User $defaultAssignee = null;
#[ORM\ManyToOne(inversedBy: 'checklistsAsOwner')]
#[ORM\JoinColumn(name: "owner_id", referencedColumnName: "id", nullable: true, onDelete: "SET NULL")]
private ?User $owner = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $mattermostUrl = null;
#[ORM\Column(nullable: true)]
private ?bool $isPrivate = null;
#[ORM\ManyToOne(inversedBy: 'onboardedChecklists')]
private ?User $onboardUser = null;
#[ORM\OneToMany(mappedBy: 'checklist', targetEntity: ChecklistActivity::class)]
private Collection $checklistActivities;
#[ORM\OneToMany(mappedBy: 'checklist', targetEntity: ChecklistNotification::class)]
private Collection $checklistNotifications;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
public function __construct()
{
$this->tasks = new ArrayCollection();
$this->checklistsFromTemplate = new ArrayCollection();
$this->checklistActivities = new ArrayCollection();
$this->checklistNotifications = 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 getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getDueDate(): ?\DateTimeInterface
{
return $this->dueDate;
}
public function setDueDate(?\DateTimeInterface $dueDate): self
{
$this->dueDate = $dueDate;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function isIsTemplate(): ?bool
{
return $this->isTemplate;
}
public function setIsTemplate(bool $isTemplate): self
{
$this->isTemplate = $isTemplate;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection<int, ChecklistTask>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(ChecklistTask $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks->add($task);
$task->setChecklist($this);
}
return $this;
}
public function removeTask(ChecklistTask $task): self
{
if ($this->tasks->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getChecklist() === $this) {
$task->setChecklist(null);
}
}
return $this;
}
public function getTasksStatus(): array
{
$tasksStatus['COUNTER'] = ['TO_DO' => 0, 'TO_VERIFY' => 0, 'DONE' => 0, 'TOTAL' => 0];
$tasksStatus['IS_DONE'] = false;
$total = 0;
foreach ($this->tasks as $task) {
if($task->getVisibility() != 'PUBLIC') continue;
$tasksStatus['COUNTER'][$task->getStatus()]++;
$total++;
}
$tasksStatus['COUNTER']['TOTAL'] = $total;
$tasksStatus['IS_DONE'] = $tasksStatus['COUNTER']['TOTAL'] > 0 && $tasksStatus['COUNTER']['TOTAL'] == $tasksStatus['COUNTER']['DONE'];
return $tasksStatus;
}
public function getTemplate(): ?self
{
return $this->template;
}
public function setTemplate(?self $template): self
{
$this->template = $template;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChecklistsFromTemplate(): Collection
{
return $this->checklistsFromTemplate;
}
public function addChecklistsFromTemplate(self $checklistsFromTemplate): self
{
if (!$this->checklistsFromTemplate->contains($checklistsFromTemplate)) {
$this->checklistsFromTemplate->add($checklistsFromTemplate);
$checklistsFromTemplate->setTemplate($this);
}
return $this;
}
public function removeChecklistsFromTemplate(self $checklistsFromTemplate): self
{
if ($this->checklistsFromTemplate->removeElement($checklistsFromTemplate)) {
// set the owning side to null (unless already changed)
if ($checklistsFromTemplate->getTemplate() === $this) {
$checklistsFromTemplate->setTemplate(null);
}
}
return $this;
}
public function getProject(): ?Project
{
return $this->project;
}
public function setProject(?Project $project): self
{
$this->project = $project;
return $this;
}
public function getDepartment(): ?Department
{
return $this->department;
}
public function setDepartment(?Department $department): self
{
$this->department = $department;
return $this;
}
public function getDefaultAssignee(): ?User
{
return $this->defaultAssignee;
}
public function setDefaultAssignee(?User $defaultAssignee): self
{
$this->defaultAssignee = $defaultAssignee;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): self
{
$this->owner = $owner;
return $this;
}
public function getMattermostUrl(): ?string
{
return $this->mattermostUrl;
}
public function setMattermostUrl(?string $mattermostUrl): self
{
$this->mattermostUrl = $mattermostUrl;
return $this;
}
public function isIsPrivate(): ?bool
{
return $this->isPrivate;
}
public function setIsPrivate(?bool $isPrivate): self
{
$this->isPrivate = $isPrivate;
return $this;
}
public function getOnboardUser(): ?User
{
return $this->onboardUser;
}
public function setOnboardUser(?User $onboardUser): self
{
$this->onboardUser = $onboardUser;
return $this;
}
/**
* @return Collection<int, ChecklistActivity>
*/
public function getChecklistActivities(): Collection
{
return $this->checklistActivities;
}
public function addChecklistActivity(ChecklistActivity $checklistActivity): self
{
if (!$this->checklistActivities->contains($checklistActivity)) {
$this->checklistActivities->add($checklistActivity);
$checklistActivity->setChecklist($this);
}
return $this;
}
public function removeChecklistActivity(ChecklistActivity $checklistActivity): self
{
if ($this->checklistActivities->removeElement($checklistActivity)) {
// set the owning side to null (unless already changed)
if ($checklistActivity->getChecklist() === $this) {
$checklistActivity->setChecklist(null);
}
}
return $this;
}
/**
* @return Collection<int, ChecklistNotification>
*/
public function getChecklistNotifications(): Collection
{
return $this->checklistNotifications;
}
public function addChecklistNotification(ChecklistNotification $checklistNotification): self
{
if (!$this->checklistNotifications->contains($checklistNotification)) {
$this->checklistNotifications->add($checklistNotification);
$checklistNotification->setChecklist($this);
}
return $this;
}
public function removeChecklistNotification(ChecklistNotification $checklistNotification): self
{
if ($this->checklistNotifications->removeElement($checklistNotification)) {
// set the owning side to null (unless already changed)
if ($checklistNotification->getChecklist() === $this) {
$checklistNotification->setChecklist(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}