src/Entity/Agro/Operation.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Agro;
  3. use App\Entity\Report\TaskList;
  4. use App\Entity\Report\Task;
  5. use App\Entity\Task\MonitoringObjective;
  6. use App\Entity\Task\Objective;
  7. use App\Entity\CopyTechcardList;
  8. use App\Entity\Techcard\ParametersValue;
  9. use App\Entity\Techcard\Techcard;
  10. use App\Model\CacheRemover;
  11. use App\Repository\Agro\OperationRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use phpDocumentor\Reflection\Types\Integer;
  16. /**
  17.  * @ORM\Entity(repositoryClass=OperationRepository::class)
  18.  */
  19. class Operation
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $name;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Card::class, mappedBy="operation",cascade={"persist","remove"})
  33.      */
  34.     private $cards;
  35.     /**
  36.      * @ORM\ManyToMany(targetEntity=Techcard::class, inversedBy="operations")
  37.      */
  38.     private $techcard;
  39.     /**
  40.      * @ORM\Column(type="boolean", nullable=true, options={"default":false})
  41.      */
  42.     private $removed;
  43.     /**
  44.      * @ORM\Column(type="integer", nullable=true, options={"default":1})
  45.      */
  46.     private $position;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=Objective::class, mappedBy="operation")
  49.      */
  50.     private $objectives;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=MonitoringObjective::class, mappedBy="operation")
  53.      */
  54.     private $monitoringObjectives;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Task::class, mappedBy="operation",cascade={"persist","remove"})
  57.      */
  58.     private $tasks;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=CopyTechcardList::class, mappedBy="operation",cascade={"persist","remove"})
  61.      */
  62.     private $copyTechcartList;
  63.     /**
  64.      * @ORM\Column(type="string", length=255, nullable=true)
  65.      */
  66.     private $hash;
  67.     /**
  68.      * @ORM\Column(type="integer", nullable=true)
  69.      */
  70.     private $cropWiseTemplateId;
  71.     /**
  72.      * @ORM\Column(type="integer", nullable=true)
  73.      */
  74.     private $cropWiseGrowthStageId;
  75.     public function __construct()
  76.     {
  77.         if(is_null($this->id)){
  78.             $this->setHash();
  79.             $this->removed false;
  80.             $this->position 0;
  81.             $this->name "Новая процедура";
  82.         }
  83.         $this->cards = new ArrayCollection();
  84.         $this->techcard = new ArrayCollection();
  85.         $this->objectives = new ArrayCollection();
  86.         $this->monitoringObjectives = new ArrayCollection();
  87.     }
  88.     
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getName(): ?string
  94.     {
  95.         return $this->name;
  96.     }
  97.     public function setName(string $name): self
  98.     {
  99.         $this->name $name;
  100.         return $this;
  101.     }
  102.     public function __toString()
  103.     {
  104.         return $this->name;
  105.     }
  106.     /**
  107.      * @return Collection|Card[]
  108.      */
  109.     public function getCards(): Collection
  110.     {
  111.         $cards = [];
  112.         foreach ($this->cards as $key => $item){
  113.             $cards[$key] = $item->getPosition();
  114.         }
  115.         $array $this->cards->toArray();
  116.         array_multisort($cardsSORT_DESC$array);
  117.         $newCards = new ArrayCollection();
  118.         foreach ($array as $item) {
  119.             $newCards->add($item);
  120.         }
  121.         return $newCards;
  122.     }
  123.     public function addCard(Card $card): self
  124.     {
  125.         if (!$this->cards->contains($card)) {
  126.             $this->cards[] = $card;
  127.             $card->setOperation($this);
  128.         }
  129.         return $this;
  130.     }
  131.     public function removeCard(Card $card): self
  132.     {
  133.         if ($this->cards->removeElement($card)) {
  134.             // set the owning side to null (unless already changed)
  135.             if ($card->getOperation() === $this) {
  136.                 $card->setOperation(null);
  137.             }
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeAllCards()
  142.     {
  143.         $cards $this->getCards();
  144.         foreach ($cards as $card) {
  145.             $card->setOperation(null);
  146.             $this->removeCard($card);
  147.         }
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection|Techcard[]
  152.      */
  153.     public function getTechcard(): Collection
  154.     {
  155.         return $this->techcard;
  156.     }
  157.     public function addTechcard(Techcard $techcard): self
  158.     {
  159.         if (!$this->techcard->contains($techcard)) {
  160.             $this->techcard[] = $techcard;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeTechcard(Techcard $techcard): self
  165.     {
  166.         $this->techcard->removeElement($techcard);
  167.         return $this;
  168.     }
  169.     public function removeAllTechcard()
  170.     {
  171.         $techCards $this->getTechcard();
  172.         foreach ($techCards as $techCard) {
  173.             $this->removeTechcard($techCard);
  174.         }
  175.         return $this;
  176.     }
  177.     public function getCountParameter(): int
  178.     {
  179.         $count 0;
  180.         foreach ($this->getCards() as $card){
  181.             $count += $card->getParams()->count();
  182.         }
  183.         return $count;
  184.     }
  185.     public function isRemoved(): ?bool
  186.     {
  187.         return $this->removed;
  188.     }
  189.     public function setRemoved(?bool $removed): self
  190.     {
  191.         $this->removed $removed;
  192.         return $this;
  193.     }
  194.     public function getPosition(): ?int
  195.     {
  196.         return $this->position;
  197.     }
  198.     public function setPosition(?int $position): self
  199.     {
  200.         $this->position $position;
  201.         return $this;
  202.     }
  203.     public function __clone()
  204.     {
  205.         $this->id null;
  206.         $this->cards = new ArrayCollection();
  207.         $this->techcard = new ArrayCollection();
  208.     }
  209.     /**
  210.      * @return Collection<int, Objective>
  211.      */
  212.     public function getObjectives(): Collection
  213.     {
  214.         return $this->objectives;
  215.     }
  216.     public function addObjective(Objective $objective): self
  217.     {
  218.         if (!$this->objectives->contains($objective)) {
  219.             $this->objectives[] = $objective;
  220.             $objective->setOperation($this);
  221.         }
  222.         return $this;
  223.     }
  224.     public function removeObjective(Objective $objective): self
  225.     {
  226.         if ($this->objectives->removeElement($objective)) {
  227.             // set the owning side to null (unless already changed)
  228.             if ($objective->getOperation() === $this) {
  229.                 $objective->setOperation(null);
  230.             }
  231.         }
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return Collection<int, MonitoringObjective>
  236.      */
  237.     public function getMonitoringObjectives(): Collection
  238.     {
  239.         return $this->monitoringObjectives;
  240.     }
  241.     public function addMonitoringObjective(MonitoringObjective $monitoringObjective): self
  242.     {
  243.         if (!$this->monitoringObjectives->contains($monitoringObjective)) {
  244.             $this->monitoringObjectives[] = $monitoringObjective;
  245.             $monitoringObjective->setOperation($this);
  246.         }
  247.         return $this;
  248.     }
  249.     public function removeMonitoringObjective(MonitoringObjective $monitoringObjective): self
  250.     {
  251.         if ($this->monitoringObjectives->removeElement($monitoringObjective)) {
  252.             // set the owning side to null (unless already changed)
  253.             if ($monitoringObjective->getOperation() === $this) {
  254.                 $monitoringObjective->setOperation(null);
  255.             }
  256.         }
  257.         return $this;
  258.     }
  259.     public function getHash(): ?string
  260.     {
  261.         return $this->hash;
  262.     }
  263.     public function setHash(): self
  264.     {
  265.         $this->hash md5($this->id.date('YmdHis').microtime(true).rand(0,999999));
  266.         return $this;
  267.     }
  268.     public function getCropWiseTemplateId()
  269.     {
  270.         return $this->cropWiseTemplateId;
  271.     }
  272.     public function setCropWiseTemplateId($cropWiseTemplateId): void
  273.     {
  274.         $this->cropWiseTemplateId $cropWiseTemplateId;
  275.     }
  276.     /**
  277.      * @return mixed
  278.      */
  279.     public function getCropWiseGrowthStageId()
  280.     {
  281.         return $this->cropWiseGrowthStageId;
  282.     }
  283.     /**
  284.      * @param mixed $cropWiseGrowthStageId
  285.      */
  286.     public function setCropWiseGrowthStageId($cropWiseGrowthStageId): void
  287.     {
  288.         $this->cropWiseGrowthStageId $cropWiseGrowthStageId;
  289.     }
  290. }