<?php
namespace App\Entity\Monitoring;
use App\Entity\Report\TaskList;
use App\Entity\Techcard\Techcard;
use App\Repository\Monitoring\MonitoringRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=MonitoringRepository::class)
*/
class Monitoring
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateFrom;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateTo;
/**
* @ORM\ManyToOne(targetEntity=Period::class, inversedBy="monitorings")
*/
private $period;
/**
* @ORM\ManyToOne(targetEntity=Techcard::class, inversedBy="monitorings")
*/
private $techcard;
/**
* @ORM\OneToMany(targetEntity=MonitoringParameter::class, mappedBy="monitoring", cascade={"persist"})
*/
private $parameters;
/**
* @ORM\OneToMany(targetEntity=MonitoringParameterValue::class, mappedBy="monitoring")
*/
private $monitoringParameterValues;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":false})
*/
private $removed;
/**
* @ORM\Column(type="integer", nullable=true, options={"efault": 0})
*/
private $position;
public function __construct()
{
if (is_null($this->id)) {
$this->removed = false;
$this->position = 0;
}
$this->parameters = new ArrayCollection();
$this->monitoringParameterValues = 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 getDateFrom(): ?\DateTimeInterface
{
return $this->dateFrom;
}
public function setDateFrom(?\DateTimeInterface $dateFrom): self
{
$this->dateFrom = $dateFrom;
return $this;
}
public function getDateTo(): ?\DateTimeInterface
{
return $this->dateTo;
}
public function setDateTo(?\DateTimeInterface $dateTo): self
{
$this->dateTo = $dateTo;
return $this;
}
public function getPeriod(): ?Period
{
return $this->period;
}
public function setPeriod(?Period $period): self
{
$this->period = $period;
return $this;
}
public function getTechcard(): ?Techcard
{
return $this->techcard;
}
public function setTechcard(?Techcard $techcard): self
{
$this->techcard = $techcard;
return $this;
}
/**
* @return Collection|MonitoringParameter[]
*/
public function getParameters($removed = false): Collection
{
$oldParameters = $this->getAllParameters($removed)->filter(function ($param) {
if (empty($param->getQuestion())) {
return $param;
}
})->toArray();
$parameters = [];
foreach ($oldParameters as $key => $item) {
$parameters[$key] = $item->getPosition();
}
array_multisort($parameters, SORT_DESC, $oldParameters);
$newParameters = new ArrayCollection();
foreach ($oldParameters as $item) {
$newParameters->add($item);
}
return $newParameters;
}
public function getAllParameters($removed = false): Collection
{
if ($removed) {
return $this->parameters;
} else {
return $this->parameters->filter(function ($item) {
if (!$item->isRemoved()) {
return $item;
}
return null;
});
}
}
public function addParameter(MonitoringParameter $parameter): self
{
if (!$this->parameters->contains($parameter)) {
$this->parameters[] = $parameter;
$parameter->setMonitoring($this);
}
return $this;
}
public function removeParameter(MonitoringParameter $parameter): self
{
if ($this->parameters->removeElement($parameter)) {
// set the owning side to null (unless already changed)
if ($parameter->getMonitoring() === $this) {
$parameter->setMonitoring(null);
}
}
return $this;
}
public function removeAllMonitoringParameters()
{
if ($this->getAllParameters()->count()) {
foreach ($this->getAllParameters() as $value) {
$this->removeParameter($value);
}
}
return $this;
}
public function __toString()
{
return $this->name;
}
/**
* @return Collection|MonitoringParameterValue[]
*/
public function getMonitoringParameterValues(): Collection
{
return $this->monitoringParameterValues;
}
public function addMonitoringParameterValue(MonitoringParameterValue $monitoringParameterValue): self
{
if (!$this->monitoringParameterValues->contains($monitoringParameterValue)) {
$this->monitoringParameterValues[] = $monitoringParameterValue;
$monitoringParameterValue->setMonitoring($this);
}
return $this;
}
public function removeMonitoringParameterValue(MonitoringParameterValue $monitoringParameterValue): self
{
if ($this->monitoringParameterValues->removeElement($monitoringParameterValue)) {
// set the owning side to null (unless already changed)
if ($monitoringParameterValue->getMonitoring() === $this) {
$monitoringParameterValue->setMonitoring(null);
}
}
return $this;
}
public function removeAllMonitoringParameterValues()
{
if ($this->getMonitoringParameterValues()->count()) {
foreach ($this->getMonitoringParameterValues() as $value) {
$this->removeMonitoringParameterValue($value);
}
}
return $this;
}
public function __clone()
{
$this->id = null;
}
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;
}
}