<?php
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Action\ActionPlansReportController;
use App\Controller\Action\EvaluationAutoConformity;
use App\Controller\Action\UploadFileApController;
use App\Controller\ActionPlanController;
use App\Filter\ActionPlanDateFilter;
use App\Filter\ActionPlanSiteFilter;
use App\Repository\ActionPlanRepository;
use App\State\ActionPlanDeleteProcessor;
use App\Traits\AutoTimestampTrait;
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 ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
#[ORM\Entity(repositoryClass: ActionPlanRepository::class)]
#[ApiResource(
operations: [
new GetCollection(),
new Post(
securityPostDenormalize: "is_granted('CREATE', object) or user.isMasterAdmin()",
),
new Get(),
new GetCollection(
name: '_api_/action_plans_report',
uriTemplate: '/action_plans_report',
controller: ActionPlansReportController::class,
write: false,
read: false
),
new Put(
name: '_api_/action_plans{id}',
uriTemplate: '/action_plans/{id}',
controller: EvaluationAutoConformity::class,
write: false,
read: false,
security: "is_granted('EDIT', object) or user.isMasterAdmin()",
),
new Delete(
processor: ActionPlanDeleteProcessor::class, security: "is_granted('DELETE', object) or user.isMasterAdmin()"
),
new Delete(
name: '_api_/action_plans/clone/{action_plan_id}/{evaluation_id}',
uriTemplate: 'action_plans/clone/{action_plan_id}/{evaluation_id}',
controller: ActionPlanController::class,
write: false,
read: false, security: "is_granted('DELETE', object) or user.isMasterAdmin()"
)
],
normalizationContext: ['groups' => ['plan.get']],
denormalizationContext: ['groups' => ['plan.write']],
order: ['id' => 'ASC'],
)]
#[ApiFilter(ActionPlanSiteFilter::class)]
#[ApiFilter(
SearchFilter::class, properties: [
'site' => 'exact',
'title' => 'ipartial',
'priority' => 'exact',
'evaluation' => 'exact',
]
)]
#[ApiFilter(ActionPlanDateFilter::class)]
#[ApiFilter(RangeFilter::class, properties: ['rateProgress'])]
#[ApiFilter(DateFilter::class, properties: ['startDate', 'endDate', 'revisedEndDate'])]
#[ORM\HasLifecycleCallbacks]
class ActionPlan
{
use AutoTimestampTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['plan.get', 'plan.write'])]
private ?int $id = null;
#[ORM\Column(name: 'title', type: Types::TEXT)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $title = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $reference = null;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?Category $subDomain = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $priority = null;
#[ORM\Column(name: 'start_date', type: 'datetime')]
#[Groups(['plan.get', 'plan.write'])]
private $startDate;
#[ORM\Column(name: 'end_date', type: 'datetime')]
#[Groups(['plan.get', 'plan.write'])]
private $endDate;
#[ORM\Column(name: 'revised_end_date', type: 'datetime')]
#[Groups(['plan.get', 'plan.write'])]
private $revisedEndDate;
#[ORM\Column(type: 'datetime', nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private $verificationDate;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?User $userPilot = null;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?User $userInCharge = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $typeProgression = null;
#[ORM\Column(nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?int $rateProgress = null;
#[ORM\Column(nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?int $periodicReminderTime = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $others = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $risksOpportunities = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $verificationType = null;
#[ORM\Column(name: 'comment', type: 'text', nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $comment = null;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?User $verifierUser = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $financialResources = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $operationalResource = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $technologicalResources = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $humainResources = null;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?User $createdBy = null;
#[ORM\ManyToOne]
#[Groups(['plan.get', 'plan.write'])]
private ?User $updatedBy = null;
#[ORM\Column(nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?bool $reminderFixed = null;
#[ORM\Column(nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?bool $reminderPeriodic = null;
#[ORM\Column(nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?int $reminderBeforeDeadline = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['plan.get', 'plan.write'])]
private ?Site $site = null;
#[ORM\OneToMany(mappedBy: 'actionPlan', targetEntity: ActionPlanTasks::class)]
#[Groups(['plan.get'])]
private Collection $actionPlanTasks;
#[ORM\OneToMany(mappedBy: 'actionPlan', targetEntity: ActionPlanComment::class)]
#[Groups(['plan.get'])]
private Collection $actionPlanComments;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private ?string $process = null;
#[ORM\ManyToMany(targetEntity: Evaluation::class, inversedBy: 'actionPlans', orphanRemoval: false, cascade: ['persist'])]
#[Groups(['plan.get', 'plan.write'])]
private Collection $evaluation;
#[ORM\Column(name: 'last_notification', type: 'datetime', nullable: true)]
#[Groups(['plan.get', 'plan.write'])]
private $lastNotification = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $oldId = null;
#[ORM\ManyToOne(inversedBy: 'actionsPlanFile')]
#[Groups(['plan.get', 'plan.write'])]
private ?Media $action_plan_file = null;
public function __construct()
{
$this->actionPlanTasks = new ArrayCollection();
$this->actionPlanComments = new ArrayCollection();
$this->evaluation = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getSubDomain(): ?Category
{
return $this->subDomain;
}
public function setSubDomain(?Category $subDomain): self
{
$this->subDomain = $subDomain;
return $this;
}
public function getPriority(): ?string
{
return $this->priority;
}
public function setPriority(string $priority): self
{
$this->priority = $priority;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(\DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getRevisedEndDate(): ?\DateTimeInterface
{
return $this->revisedEndDate;
}
public function setRevisedEndDate(\DateTimeInterface $revisedEndDate): self
{
$this->revisedEndDate = $revisedEndDate;
return $this;
}
public function getVerificationDate(): ?\DateTimeInterface
{
return $this->verificationDate;
}
public function setVerificationDate(?\DateTimeInterface $verificationDate): self
{
$this->verificationDate = $verificationDate;
return $this;
}
// public function getUpdatedAt(): ?\DateTimeInterface
// {
// return $this->updatedAt;
// }
//
// public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
// {
// $this->updatedAt = $updatedAt;
//
// return $this;
// }
//
// public function getCreatedAt(): ?\DateTimeInterface
// {
// return $this->createdAt;
// }
//
// public function setCreatedAt(?\DateTimeInterface $createdAt): self
// {
// $this->createdAt = $createdAt;
//
// return $this;
// }
public function getUserPilot(): ?User
{
return $this->userPilot;
}
public function setUserPilot(?User $userPilot): self
{
$this->userPilot = $userPilot;
return $this;
}
public function getUserInCharge(): ?User
{
return $this->userInCharge;
}
public function setUserInCharge(?User $userInCharge): self
{
$this->userInCharge = $userInCharge;
return $this;
}
public function getTypeProgression(): ?string
{
return $this->typeProgression;
}
public function setTypeProgression(string $typeProgression): self
{
$this->typeProgression = $typeProgression;
return $this;
}
public function getRateProgress(): ?int
{
return $this->rateProgress;
}
public function setRateProgress(?int $rateProgress): self
{
$this->rateProgress = $rateProgress;
return $this;
}
public function getPeriodicReminderTime(): ?int
{
return $this->periodicReminderTime;
}
public function setPeriodicReminderTime(?int $periodicReminderTime): self
{
$this->periodicReminderTime = $periodicReminderTime;
return $this;
}
public function getOthers(): ?string
{
return $this->others;
}
public function setOthers(?string $others): self
{
$this->others = $others;
return $this;
}
public function getRisksOpportunities(): ?string
{
return $this->risksOpportunities;
}
public function setRisksOpportunities(string $risksOpportunities): self
{
$this->risksOpportunities = $risksOpportunities;
return $this;
}
public function getVerificationType(): ?string
{
return $this->verificationType;
}
public function setVerificationType(?string $verificationType): self
{
$this->verificationType = $verificationType;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getVerifierUser(): ?User
{
return $this->verifierUser;
}
public function setVerifierUser(?User $verifierUser): self
{
$this->verifierUser = $verifierUser;
return $this;
}
public function getFinancialResources(): ?string
{
return $this->financialResources;
}
public function setFinancialResources(?string $financialResources): self
{
$this->financialResources = $financialResources;
return $this;
}
public function getOperationalResource(): ?string
{
return $this->operationalResource;
}
public function setOperationalResource(?string $operationalResource): self
{
$this->operationalResource = $operationalResource;
return $this;
}
public function getTechnologicalResources(): ?string
{
return $this->technologicalResources;
}
public function setTechnologicalResources(?string $technologicalResources): self
{
$this->technologicalResources = $technologicalResources;
return $this;
}
public function getHumainResources(): ?string
{
return $this->humainResources;
}
public function setHumainResources(?string $humainResources): self
{
$this->humainResources = $humainResources;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function isReminderFixed(): ?bool
{
return $this->reminderFixed;
}
public function setReminderFixed(?bool $reminderFixed): self
{
$this->reminderFixed = $reminderFixed;
return $this;
}
public function isReminderPeriodic(): ?bool
{
return $this->reminderPeriodic;
}
public function setReminderPeriodic(?bool $reminderPeriodic): self
{
$this->reminderPeriodic = $reminderPeriodic;
return $this;
}
public function getReminderBeforeDeadline(): ?int
{
return $this->reminderBeforeDeadline;
}
public function setReminderBeforeDeadline(?int $reminderBeforeDeadline): self
{
$this->reminderBeforeDeadline = $reminderBeforeDeadline;
return $this;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): self
{
$this->site = $site;
return $this;
}
/**
* @return Collection<int, ActionPlanTasks>
*/
public function getActionPlanTasks(): Collection
{
return $this->actionPlanTasks;
}
public function addActionPlanTask(ActionPlanTasks $actionPlanTask): self
{
if (!$this->actionPlanTasks->contains($actionPlanTask)) {
$this->actionPlanTasks->add($actionPlanTask);
$actionPlanTask->setActionPlan($this);
}
return $this;
}
public function removeActionPlanTask(ActionPlanTasks $actionPlanTask): self
{
if ($this->actionPlanTasks->removeElement($actionPlanTask)) {
// set the owning side to null (unless already changed)
if ($actionPlanTask->getActionPlan() === $this) {
$actionPlanTask->setActionPlan(null);
}
}
return $this;
}
/**
* @return Collection<int, ActionPlanComment>
*/
public function getActionPlanComments(): Collection
{
return $this->actionPlanComments;
}
public function addActionPlanComment(ActionPlanComment $actionPlanComment): self
{
if (!$this->actionPlanComments->contains($actionPlanComment)) {
$this->actionPlanComments->add($actionPlanComment);
$actionPlanComment->setActionPlan($this);
}
return $this;
}
public function removeActionPlanComment(ActionPlanComment $actionPlanComment): self
{
if ($this->actionPlanComments->removeElement($actionPlanComment)) {
// set the owning side to null (unless already changed)
if ($actionPlanComment->getActionPlan() === $this) {
$actionPlanComment->setActionPlan(null);
}
}
return $this;
}
public function getProcess(): ?string
{
return $this->process;
}
public function setProcess(?string $process): self
{
$this->process = $process;
return $this;
}
/**
* @return Collection<int, Evaluation>
*/
public function getEvaluation(): Collection
{
return $this->evaluation;
}
public function addEvaluation(Evaluation $evaluation): self
{
if (!$this->evaluation->contains($evaluation)) {
$this->evaluation->add($evaluation);
}
return $this;
}
public function removeEvaluation(Evaluation $evaluation): self
{
$this->evaluation->removeElement($evaluation);
return $this;
}
/**
* @return mixed
*/
public function getLastNotification(): mixed
{
return $this->lastNotification;
}
/**
* @param mixed $lastNotification
*/
public function setLastNotification($lastNotification): void
{
$this->lastNotification = $lastNotification;
}
#[Groups(['plan.get'])]
public function getPathSite(): ?string
{
return $this->site->getPath()['full_path'] ?? '';
}
public function getOldId(): ?string
{
return $this->oldId;
}
public function setOldId(?string $oldId): self
{
$this->oldId = $oldId;
return $this;
}
/**
* @return Media|null
*/
public function getActionPlanFile(): ?Media
{
return $this->action_plan_file;
}
/**
* @param Media|null $action_plan_file
*/
public function setActionPlanFile(?Media $action_plan_file): void
{
$this->action_plan_file = $action_plan_file;
}
}