src/Entity/Monitoring/Monitoring.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Monitoring;
  3. use App\Entity\Report\TaskList;
  4. use App\Entity\Techcard\Techcard;
  5. use App\Repository\Monitoring\MonitoringRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=MonitoringRepository::class)
  11.  */
  12. class Monitoring
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $name;
  24.     /**
  25.      * @ORM\Column(type="date", nullable=true)
  26.      */
  27.     private $dateFrom;
  28.     /**
  29.      * @ORM\Column(type="date", nullable=true)
  30.      */
  31.     private $dateTo;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Period::class, inversedBy="monitorings")
  34.      */
  35.     private $period;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity=Techcard::class, inversedBy="monitorings")
  38.      */
  39.     private $techcard;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=MonitoringParameter::class, mappedBy="monitoring", cascade={"persist"})
  42.      */
  43.     private $parameters;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity=MonitoringParameterValue::class, mappedBy="monitoring")
  46.      */
  47.     private $monitoringParameterValues;
  48.     /**
  49.      * @ORM\Column(type="boolean", nullable=true, options={"default":false})
  50.      */
  51.     private $removed;
  52.     /**
  53.      * @ORM\Column(type="integer", nullable=true, options={"efault": 0})
  54.      */
  55.     private $position;
  56.     public function __construct()
  57.     {
  58.         if (is_null($this->id)) {
  59.             $this->removed false;
  60.             $this->position 0;
  61.         }
  62.         $this->parameters = new ArrayCollection();
  63.         $this->monitoringParameterValues = new ArrayCollection();
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getName(): ?string
  70.     {
  71.         return $this->name;
  72.     }
  73.     public function setName(string $name): self
  74.     {
  75.         $this->name $name;
  76.         return $this;
  77.     }
  78.     public function getDateFrom(): ?\DateTimeInterface
  79.     {
  80.         return $this->dateFrom;
  81.     }
  82.     public function setDateFrom(?\DateTimeInterface $dateFrom): self
  83.     {
  84.         $this->dateFrom $dateFrom;
  85.         return $this;
  86.     }
  87.     public function getDateTo(): ?\DateTimeInterface
  88.     {
  89.         return $this->dateTo;
  90.     }
  91.     public function setDateTo(?\DateTimeInterface $dateTo): self
  92.     {
  93.         $this->dateTo $dateTo;
  94.         return $this;
  95.     }
  96.     public function getPeriod(): ?Period
  97.     {
  98.         return $this->period;
  99.     }
  100.     public function setPeriod(?Period $period): self
  101.     {
  102.         $this->period $period;
  103.         return $this;
  104.     }
  105.     public function getTechcard(): ?Techcard
  106.     {
  107.         return $this->techcard;
  108.     }
  109.     public function setTechcard(?Techcard $techcard): self
  110.     {
  111.         $this->techcard $techcard;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection|MonitoringParameter[]
  116.      */
  117.     public function getParameters($removed false): Collection
  118.     {
  119.         $oldParameters $this->getAllParameters($removed)->filter(function ($param) {
  120.             if (empty($param->getQuestion())) {
  121.                 return $param;
  122.             }
  123.         })->toArray();
  124.         $parameters = [];
  125.         foreach ($oldParameters as $key => $item) {
  126.             $parameters[$key] = $item->getPosition();
  127.         }
  128.         array_multisort($parametersSORT_DESC$oldParameters);
  129.         $newParameters = new ArrayCollection();
  130.         foreach ($oldParameters as $item) {
  131.             $newParameters->add($item);
  132.         }
  133.         return $newParameters;
  134.     }
  135.     public function getAllParameters($removed false): Collection
  136.     {
  137.         if ($removed) {
  138.             return $this->parameters;
  139.         } else {
  140.             return $this->parameters->filter(function ($item) {
  141.                 if (!$item->isRemoved()) {
  142.                     return $item;
  143.                 }
  144.                 return null;
  145.             });
  146.         }
  147.     }
  148.     public function addParameter(MonitoringParameter $parameter): self
  149.     {
  150.         if (!$this->parameters->contains($parameter)) {
  151.             $this->parameters[] = $parameter;
  152.             $parameter->setMonitoring($this);
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeParameter(MonitoringParameter $parameter): self
  157.     {
  158.         if ($this->parameters->removeElement($parameter)) {
  159.             // set the owning side to null (unless already changed)
  160.             if ($parameter->getMonitoring() === $this) {
  161.                 $parameter->setMonitoring(null);
  162.             }
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeAllMonitoringParameters()
  167.     {
  168.         if ($this->getAllParameters()->count()) {
  169.             foreach ($this->getAllParameters() as $value) {
  170.                 $this->removeParameter($value);
  171.             }
  172.         }
  173.         return $this;
  174.     }
  175.     public function __toString()
  176.     {
  177.         return $this->name;
  178.     }
  179.     /**
  180.      * @return Collection|MonitoringParameterValue[]
  181.      */
  182.     public function getMonitoringParameterValues(): Collection
  183.     {
  184.         return $this->monitoringParameterValues;
  185.     }
  186.     public function addMonitoringParameterValue(MonitoringParameterValue $monitoringParameterValue): self
  187.     {
  188.         if (!$this->monitoringParameterValues->contains($monitoringParameterValue)) {
  189.             $this->monitoringParameterValues[] = $monitoringParameterValue;
  190.             $monitoringParameterValue->setMonitoring($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeMonitoringParameterValue(MonitoringParameterValue $monitoringParameterValue): self
  195.     {
  196.         if ($this->monitoringParameterValues->removeElement($monitoringParameterValue)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($monitoringParameterValue->getMonitoring() === $this) {
  199.                 $monitoringParameterValue->setMonitoring(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeAllMonitoringParameterValues()
  205.     {
  206.         if ($this->getMonitoringParameterValues()->count()) {
  207.             foreach ($this->getMonitoringParameterValues() as $value) {
  208.                 $this->removeMonitoringParameterValue($value);
  209.             }
  210.         }
  211.         return $this;
  212.     }
  213.     public function __clone()
  214.     {
  215.         $this->id null;
  216.     }
  217.     public function isRemoved(): ?bool
  218.     {
  219.         return $this->removed;
  220.     }
  221.     public function setRemoved(?bool $removed): self
  222.     {
  223.         $this->removed $removed;
  224.         return $this;
  225.     }
  226.     public function getPosition(): ?int
  227.     {
  228.         return $this->position;
  229.     }
  230.     public function setPosition(?int $position): self
  231.     {
  232.         $this->position $position;
  233.         return $this;
  234.     }
  235. }