<?php
namespace App\Entity\Agro;
use App\Entity\Report\TaskList;
use App\Entity\Report\Task;
use App\Entity\Task\MonitoringObjective;
use App\Entity\Task\Objective;
use App\Entity\CopyTechcardList;
use App\Entity\Techcard\ParametersValue;
use App\Entity\Techcard\Techcard;
use App\Model\CacheRemover;
use App\Repository\Agro\OperationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\Integer;
/**
* @ORM\Entity(repositoryClass=OperationRepository::class)
*/
class Operation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Card::class, mappedBy="operation",cascade={"persist","remove"})
*/
private $cards;
/**
* @ORM\ManyToMany(targetEntity=Techcard::class, inversedBy="operations")
*/
private $techcard;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":false})
*/
private $removed;
/**
* @ORM\Column(type="integer", nullable=true, options={"default":1})
*/
private $position;
/**
* @ORM\OneToMany(targetEntity=Objective::class, mappedBy="operation")
*/
private $objectives;
/**
* @ORM\OneToMany(targetEntity=MonitoringObjective::class, mappedBy="operation")
*/
private $monitoringObjectives;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="operation",cascade={"persist","remove"})
*/
private $tasks;
/**
* @ORM\OneToMany(targetEntity=CopyTechcardList::class, mappedBy="operation",cascade={"persist","remove"})
*/
private $copyTechcartList;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $hash;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseTemplateId;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseGrowthStageId;
public function __construct()
{
if(is_null($this->id)){
$this->setHash();
$this->removed = false;
$this->position = 0;
$this->name = "Новая процедура";
}
$this->cards = new ArrayCollection();
$this->techcard = new ArrayCollection();
$this->objectives = new ArrayCollection();
$this->monitoringObjectives = 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 __toString()
{
return $this->name;
}
/**
* @return Collection|Card[]
*/
public function getCards(): Collection
{
$cards = [];
foreach ($this->cards as $key => $item){
$cards[$key] = $item->getPosition();
}
$array = $this->cards->toArray();
array_multisort($cards, SORT_DESC, $array);
$newCards = new ArrayCollection();
foreach ($array as $item) {
$newCards->add($item);
}
return $newCards;
}
public function addCard(Card $card): self
{
if (!$this->cards->contains($card)) {
$this->cards[] = $card;
$card->setOperation($this);
}
return $this;
}
public function removeCard(Card $card): self
{
if ($this->cards->removeElement($card)) {
// set the owning side to null (unless already changed)
if ($card->getOperation() === $this) {
$card->setOperation(null);
}
}
return $this;
}
public function removeAllCards()
{
$cards = $this->getCards();
foreach ($cards as $card) {
$card->setOperation(null);
$this->removeCard($card);
}
return $this;
}
/**
* @return Collection|Techcard[]
*/
public function getTechcard(): Collection
{
return $this->techcard;
}
public function addTechcard(Techcard $techcard): self
{
if (!$this->techcard->contains($techcard)) {
$this->techcard[] = $techcard;
}
return $this;
}
public function removeTechcard(Techcard $techcard): self
{
$this->techcard->removeElement($techcard);
return $this;
}
public function removeAllTechcard()
{
$techCards = $this->getTechcard();
foreach ($techCards as $techCard) {
$this->removeTechcard($techCard);
}
return $this;
}
public function getCountParameter(): int
{
$count = 0;
foreach ($this->getCards() as $card){
$count += $card->getParams()->count();
}
return $count;
}
public function isRemoved(): ?bool
{
return $this->removed;
}
public function setRemoved(?bool $removed): self
{
$this->removed = $removed;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
public function __clone()
{
$this->id = null;
$this->cards = new ArrayCollection();
$this->techcard = new ArrayCollection();
}
/**
* @return Collection<int, Objective>
*/
public function getObjectives(): Collection
{
return $this->objectives;
}
public function addObjective(Objective $objective): self
{
if (!$this->objectives->contains($objective)) {
$this->objectives[] = $objective;
$objective->setOperation($this);
}
return $this;
}
public function removeObjective(Objective $objective): self
{
if ($this->objectives->removeElement($objective)) {
// set the owning side to null (unless already changed)
if ($objective->getOperation() === $this) {
$objective->setOperation(null);
}
}
return $this;
}
/**
* @return Collection<int, MonitoringObjective>
*/
public function getMonitoringObjectives(): Collection
{
return $this->monitoringObjectives;
}
public function addMonitoringObjective(MonitoringObjective $monitoringObjective): self
{
if (!$this->monitoringObjectives->contains($monitoringObjective)) {
$this->monitoringObjectives[] = $monitoringObjective;
$monitoringObjective->setOperation($this);
}
return $this;
}
public function removeMonitoringObjective(MonitoringObjective $monitoringObjective): self
{
if ($this->monitoringObjectives->removeElement($monitoringObjective)) {
// set the owning side to null (unless already changed)
if ($monitoringObjective->getOperation() === $this) {
$monitoringObjective->setOperation(null);
}
}
return $this;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(): self
{
$this->hash = md5($this->id.date('YmdHis').microtime(true).rand(0,999999));
return $this;
}
public function getCropWiseTemplateId()
{
return $this->cropWiseTemplateId;
}
public function setCropWiseTemplateId($cropWiseTemplateId): void
{
$this->cropWiseTemplateId = $cropWiseTemplateId;
}
/**
* @return mixed
*/
public function getCropWiseGrowthStageId()
{
return $this->cropWiseGrowthStageId;
}
/**
* @param mixed $cropWiseGrowthStageId
*/
public function setCropWiseGrowthStageId($cropWiseGrowthStageId): void
{
$this->cropWiseGrowthStageId = $cropWiseGrowthStageId;
}
}