<?php
namespace App\Entity\Task;
use App\Constant\StatusConstant;
use App\Constant\StatusObjectiveConstant;
use App\Entity\Agro\Operation;
use App\Entity\Client;
use App\Entity\Culture;
use App\Entity\Field;
use App\Entity\Report\Report;
use App\Entity\Report\Task;
use App\Entity\Season;
use App\Entity\Techcard\Techcard;
use App\Entity\User;
use App\Model\CacheRemover;
use App\Repository\Task\ObjectiveRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Faker\Provider\DateTime;
/**
* @ORM\Entity(repositoryClass=ObjectiveRepository::class)
*/
class Objective
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Client::class, inversedBy="objectives")
*/
private $client;
/**
* @ORM\ManyToOne(targetEntity=Season::class, inversedBy="objectives")
*/
private $season;
/**
* @ORM\ManyToOne(targetEntity=Culture::class, inversedBy="objectives")
*/
private $culture;
/**
* @ORM\Column(type="boolean")
*/
private $typeProcedure;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $priority;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateCompletion;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="ownerObjectives")
*/
private $owner;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="viewerObjectives")
*/
private $viewer;
/**
* @ORM\ManyToOne(targetEntity=Techcard::class, inversedBy="objectives")
*/
private $techcard;
/**
* @ORM\ManyToOne(targetEntity=Operation::class, inversedBy="objectives")
*/
private $operation;
/**
* @ORM\Column(type="string", length=255)
*/
private $status;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $infoFiles = [];
/**
* @ORM\ManyToOne(targetEntity=Field::class, inversedBy="objectives")
*/
private $field;
/**
* @ORM\ManyToOne(targetEntity=MonitoringObjective::class, inversedBy="objectives", cascade={"persist", "remove"})
*/
private $monitoringObjective;
/**
* @ORM\OneToOne(targetEntity=Task::class, mappedBy="objective", cascade={"persist", "remove"})
*/
private $task;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="creatorObjectives")
*/
private $creator;
/**
* @ORM\OneToMany(targetEntity=Report::class, mappedBy="objective", cascade={"remove"})
*/
private $reports;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updateAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $hash;
public function __construct()
{
if($this->id === null){
$this->name = 'Новая задача';
$this->priority = StatusObjectiveConstant::NORMAL;
$this->typeProcedure = false;
$this->status = StatusConstant::NEW;
$this->setHash();
}
$this->updateAt = new \DateTime();
$this->fields = new ArrayCollection();
$this->reports = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
public function getCulture(): ?Culture
{
return $this->culture;
}
public function setCulture(?Culture $culture): self
{
$this->culture = $culture;
return $this;
}
public function isTypeProcedure(): ?bool
{
return $this->typeProcedure;
}
public function setTypeProcedure(bool $typeProcedure): self
{
$this->typeProcedure = $typeProcedure;
return $this;
}
public function getName(?bool $operation = true): ?string
{
if(!empty($this->getOperation()) && $operation){
return $this->getOperation()->getName();
}
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 getPriority(): ?string
{
return $this->priority;
}
public function setPriority(?string $priority): self
{
$this->priority = $priority;
return $this;
}
public function getDateCompletion(): ?\DateTimeInterface
{
return $this->dateCompletion;
}
public function setDateCompletion(\DateTimeInterface $dateCompletion): self
{
$this->dateCompletion = $dateCompletion;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): self
{
$this->owner = $owner;
return $this;
}
public function getViewer(): ?User
{
return $this->viewer;
}
public function setViewer(?User $viewer): self
{
$this->viewer = $viewer;
if(!empty($viewer) && empty($this->dateCompletion)){
$this->dateCompletion = new \DateTime();
}
return $this;
}
public function getTechcard(): ?Techcard
{
return $this->techcard;
}
public function setTechcard(?Techcard $techcard): self
{
$this->techcard = $techcard;
return $this;
}
public function getOperation(): ?Operation
{
return $this->operation;
}
public function setOperation(?Operation $operation): self
{
$this->operation = $operation;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
if($status == StatusConstant::IN_PROGRESS && empty($this->dateCompletion)){
$this->dateCompletion = new \DateTime();
}
return $this;
}
public function getInfoFiles(): ?array
{
return $this->infoFiles;
}
public function setInfoFiles(?array $infoFiles): self
{
$this->infoFiles = $infoFiles;
return $this;
}
public function getField(): ?Field
{
return $this->field;
}
public function setField(?Field $field): self
{
$this->field = $field;
return $this;
}
public function getMonitoringObjective(): ?MonitoringObjective
{
return $this->monitoringObjective;
}
public function setMonitoringObjective(?MonitoringObjective $monitoringObjective): self
{
$this->monitoringObjective = $monitoringObjective;
return $this;
}
public function getTask(): ?Task
{
return $this->task;
}
public function setTask(?Task $task): self
{
// unset the owning side of the relation if necessary
if ($task === null && $this->task !== null) {
$this->task->setObjective(null);
}
// set the owning side of the relation if necessary
if ($task !== null && $task->getObjective() !== $this) {
$task->setObjective($this);
}
$this->task = $task;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
/**
* @return Collection<int, Report>
*/
public function getReports(): Collection
{
return $this->reports;
}
public function addReport(Report $report): self
{
if (!$this->reports->contains($report)) {
$this->reports[] = $report;
$report->setObjective($this);
}
return $this;
}
public function removeReport(Report $report): self
{
if ($this->reports->removeElement($report)) {
// set the owning side to null (unless already changed)
if ($report->getObjective() === $this) {
$report->setObjective(null);
}
}
return $this;
}
public function getUpdateAt(): ?\DateTimeInterface
{
return $this->updateAt;
}
public function setUpdateAt(?\DateTimeInterface $updateAt): self
{
$this->updateAt = $updateAt;
return $this;
}
public function __clone()
{
$this->id = null;
$this->field = null;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(): self
{
$this->hash = md5(date('YmdHis').microtime(true).rand(0,999999));
return $this;
}
}