src/Entity/Report/Report.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Report;
  3. use App\Entity\Agro\Operation;
  4. use App\Entity\Field;
  5. use App\Entity\Monitoring\Monitoring;
  6. use App\Entity\Recommendation;
  7. use App\Entity\Task\Objective;
  8. use App\Entity\Techcard\Techcard;
  9. use App\Entity\TelegramSenderLog;
  10. use App\Entity\User;
  11. use App\Repository\Report\ReportRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. /**
  16.  * @ORM\Entity(repositoryClass=ReportRepository::class)
  17.  */
  18. class Report
  19. {
  20.   /**
  21.    * @ORM\Id
  22.    * @ORM\GeneratedValue
  23.    * @ORM\Column(type="integer")
  24.    */
  25.   private $id;
  26.   /**
  27.    * @ORM\Column(type="string", length=255)
  28.    */
  29.   private $formKey;
  30.   /**
  31.    * @ORM\ManyToOne(targetEntity=Operation::class)
  32.    */
  33.   private $operation;
  34.   /**
  35.    * @ORM\ManyToOne(targetEntity=Monitoring::class)
  36.    */
  37.   private $monitoring;
  38.   /**
  39.    * @ORM\ManyToOne(targetEntity=Techcard::class)
  40.    * @ORM\JoinColumn(nullable=true)
  41.    */
  42.   private $techcard;
  43.   /**
  44.    * @ORM\ManyToOne(targetEntity=Field::class, inversedBy="reports")
  45.    * @ORM\JoinColumn(nullable=false)
  46.    */
  47.   private $field;
  48.   /**
  49.    * @ORM\OneToMany(targetEntity=ReportValue::class, mappedBy="report", cascade={"persist","remove"})
  50.    */
  51.   private $reportValues;
  52.   /**
  53.    * @ORM\ManyToOne(targetEntity=Task::class, inversedBy="reports")
  54.    */
  55.   private $task;
  56.   /**
  57.    * @ORM\ManyToOne(targetEntity=User::class)
  58.    * @ORM\JoinColumn(nullable=false)
  59.    */
  60.   private $user;
  61.   /**
  62.    * @ORM\Column(type="string", length=2)
  63.    */
  64.   private $type;
  65.   /**
  66.    * @ORM\Column(type="datetime", nullable=true)
  67.    */
  68.   private $createdAt;
  69.   /**
  70.    * @ORM\Column(type="text", nullable=true)
  71.    */
  72.   private $coordinat;
  73.   /**
  74.    * @ORM\Column(type="string", length=255, nullable=true)
  75.    */
  76.   private $distance;
  77.   /**
  78.    * @ORM\Column(type="string", length=255, nullable=true)
  79.    */
  80.   private $accuracy;
  81.   /**
  82.    * @ORM\Column(type="text", nullable=true)
  83.    */
  84.   private $comment;
  85.   /**
  86.    * @ORM\ManyToOne(targetEntity=Objective::class, inversedBy="reports")
  87.    */
  88.   private $objective;
  89.   /**
  90.    * @ORM\Column(type="integer", nullable=true)
  91.    */
  92.   private $errorsCount;
  93.   /**
  94.    * @ORM\OneToMany(targetEntity=Recommendation::class, mappedBy="report",cascade={"persist","remove"})
  95.    */
  96.   private $recommendations;
  97.   /**
  98.    * @ORM\Column(type="string", length=255, nullable=true)
  99.    */
  100.   private $cropWiseStatusLoad;
  101.   /**
  102.    * @ORM\Column(type="integer", nullable=true)
  103.    */
  104.   private $cropWiseReportId;
  105.   /**
  106.    * @ORM\Column(type="integer", nullable=true)
  107.    */
  108.   private $cropWiseReportPointId;
  109.     /**
  110.      * @ORM\Column(type="boolean", nullable=true)
  111.      */
  112.     private $telegramSend;
  113.     /**
  114.      * @ORM\Column(type="boolean", nullable=true)
  115.      */
  116.     private $removed;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=TelegramSenderLog::class, mappedBy="report")
  119.      */
  120.     private $telegramSenderLogs;
  121.     /**
  122.      * @ORM\Column(type="string", length=255, nullable=true)
  123.      */
  124.     private $cropWiseStatusDownload;
  125.     /**
  126.      * @ORM\Column(type="integer", nullable=true)
  127.      */
  128.     private $cropWiseReportIdDownload;
  129.     /**
  130.      * @ORM\Column(type="integer", nullable=true)
  131.      */
  132.     private $cropWiseReportPointIdDownload;
  133.     /**
  134.      * @ORM\Column(type="integer", nullable=true)
  135.      */
  136.     private $cropWiseReportTemplateId;
  137.   public function __construct()
  138.   {
  139.     if (is_null($this->id)) {
  140.         $this->createdAt = new \DateTime();
  141.         $this->removed false;
  142.         $this->telegramSend false;
  143.     }
  144.     $this->reportValues = new ArrayCollection();
  145.     $this->recommendations = new ArrayCollection();
  146.     $this->telegramSenderLogs = new ArrayCollection();
  147.   }
  148.   public function getId(): ?int
  149.   {
  150.     return $this->id;
  151.   }
  152.   public function getFormKey(): ?string
  153.   {
  154.     return $this->formKey;
  155.   }
  156.   public function setFormKey(string $formKey): self
  157.   {
  158.     $this->formKey $formKey;
  159.     return $this;
  160.   }
  161.   public function getOperation(): ?Operation
  162.   {
  163.     return $this->operation;
  164.   }
  165.   public function setOperation(?Operation $operation): self
  166.   {
  167.     $this->operation $operation;
  168.     return $this;
  169.   }
  170.   public function getMonitoring(): ?Monitoring
  171.   {
  172.     return $this->monitoring;
  173.   }
  174.   public function setMonitoring(?Monitoring $monitoring): self
  175.   {
  176.     $this->monitoring $monitoring;
  177.     return $this;
  178.   }
  179.   public function getTechcard(): ?Techcard
  180.   {
  181.     return $this->techcard;
  182.   }
  183.   public function setTechcard(?Techcard $techcard): self
  184.   {
  185.     $this->techcard $techcard;
  186.     return $this;
  187.   }
  188.   public function getField(): ?Field
  189.   {
  190.     return $this->field;
  191.   }
  192.   public function setField(?Field $field): self
  193.   {
  194.     $this->field $field;
  195.     return $this;
  196.   }
  197.   /**
  198.    * @return Collection|ReportValue[]
  199.    */
  200.   public function getReportValues(): Collection
  201.   {
  202.     return $this->reportValues;
  203.   }
  204.   public function addReportValue(ReportValue $reportValue): self
  205.   {
  206.     if (!$this->reportValues->contains($reportValue)) {
  207.       $this->reportValues[] = $reportValue;
  208.       $reportValue->setReport($this);
  209.     }
  210.     return $this;
  211.   }
  212.   public function removeReportValue(ReportValue $reportValue): self
  213.   {
  214.     if ($this->reportValues->removeElement($reportValue)) {
  215.       // set the owning side to null (unless already changed)
  216.       if ($reportValue->getReport() === $this) {
  217.         $reportValue->setReport(null);
  218.       }
  219.     }
  220.     return $this;
  221.   }
  222.   public function getTask(): ?Task
  223.   {
  224.     return $this->task;
  225.   }
  226.   public function setTask(?Task $task): self
  227.   {
  228.     $this->task $task;
  229.     return $this;
  230.   }
  231.   public function getUser(): ?User
  232.   {
  233.     return $this->user;
  234.   }
  235.   public function setUser(?User $user): self
  236.   {
  237.     $this->user $user;
  238.     return $this;
  239.   }
  240.   public function getType(): ?string
  241.   {
  242.     return $this->type;
  243.   }
  244.   public function setType(string $type): self
  245.   {
  246.     $this->type $type;
  247.     return $this;
  248.   }
  249.   public function getName(): ?string
  250.   {
  251.     if (!empty($this->getOperation())) {
  252.       return $this->getOperation()->getName();
  253.     }
  254.     if (!empty($this->getMonitoring())) {
  255.       return $this->getMonitoring()->getName();
  256.     }
  257.     return null;
  258.   }
  259.   public function getCreatedAt(): ?\DateTimeInterface
  260.   {
  261.     return $this->createdAt;
  262.   }
  263.   public function setCreatedAt(?\DateTimeInterface $createdAt): self
  264.   {
  265.     $this->createdAt $createdAt;
  266.     return $this;
  267.   }
  268.   public function getCoordinat(): ?string
  269.   {
  270.     return str_replace('-'' '$this->coordinat);
  271.   }
  272.   public function setCoordinat(?string $coordinat): self
  273.   {
  274.     $this->coordinat $coordinat;
  275.     return $this;
  276.   }
  277.   public function getCoordinatArray()
  278.   {
  279.     $coordinate str_replace('-'' '$this->coordinat);
  280.     $coordinate preg_replace('@\s+@'' '$coordinate);
  281.     $explode explode(' '$coordinate);
  282.     try {
  283.       list($lat$lng) = $explode;
  284.       return [
  285.         'lng' => $lng,
  286.         'lat' => $lat,
  287.       ];
  288.     } catch (\Exception $e) {
  289.       return [];
  290.     }
  291.   }
  292.   public function getDistance($metr true): int
  293.   {
  294.     return $this->convertDistance($this->distance$metr);
  295.   }
  296.   public function setDistance(?string $distance): self
  297.   {
  298.     $this->distance $distance;
  299.     return $this;
  300.   }
  301.   public function getAccuracy(): ?string
  302.   {
  303.     return $this->accuracy;
  304.   }
  305.   public function setAccuracy(?string $accuracy): self
  306.   {
  307.     $this->accuracy $accuracy;
  308.     return $this;
  309.   }
  310.   public function getComment(): ?string
  311.   {
  312.     return $this->comment;
  313.   }
  314.   public function setComment(?string $comment): self
  315.   {
  316.     $this->comment $comment;
  317.     return $this;
  318.   }
  319.   public function getObjective(): ?Objective
  320.   {
  321.     return $this->objective;
  322.   }
  323.   public function setObjective(?Objective $objective): self
  324.   {
  325.     $this->objective $objective;
  326.     return $this;
  327.   }
  328.   public function getErrorsCount(): ?int
  329.   {
  330.     return $this->errorsCount;
  331.   }
  332.   public function setErrorsCount(?int $errorsCount): self
  333.   {
  334.     $this->errorsCount $errorsCount;
  335.     return $this;
  336.   }
  337.   public function getDistanceMin($metr true)
  338.   {
  339.     $distance = [];
  340.     $values $this->getReportValues();
  341.     if ($values->count() > 0) {
  342.       /** @var ReportValue $value */
  343.       foreach ($values as $value) {
  344.         if (!empty($value->getDistance())) {
  345.           $distance[] = $value->getDistance();
  346.         }
  347.       }
  348.       if (!empty($distance)) {
  349.         sort($distance);
  350.         return $this->convertDistance(end($distance), $metr);
  351.       }
  352.     }
  353.     return $this->convertDistance($this->getDistance(), $metr);
  354.   }
  355.   private function convertDistance($distance$metr)
  356.   {
  357.     if (!empty($distance) && $distance 0) {
  358.       $number ceil($distance);
  359.       if ($number 10000) {
  360.         $metr true;
  361.       }
  362.       if ($metr) {
  363.         return (int)$number;
  364.       } else {
  365.         return (int)($number 1000);
  366.       }
  367.     }
  368.     return (int)$distance;
  369.   }
  370.   /**
  371.    * @return Collection<int, Recommendation>
  372.    */
  373.   public function getRecommendations(): Collection
  374.   {
  375.     return $this->recommendations;
  376.   }
  377.   public function addRecommendation(Recommendation $recommendation): self
  378.   {
  379.     if (!$this->recommendations->contains($recommendation)) {
  380.       $this->recommendations[] = $recommendation;
  381.       $recommendation->setReport($this);
  382.     }
  383.     return $this;
  384.   }
  385.   public function removeRecommendation(Recommendation $recommendation): self
  386.   {
  387.     if ($this->recommendations->removeElement($recommendation)) {
  388.       // set the owning side to null (unless already changed)
  389.       if ($recommendation->getReport() === $this) {
  390.         $recommendation->setReport(null);
  391.       }
  392.     }
  393.     return $this;
  394.   }
  395.   public function getCropWiseStatusLoad(): ?string
  396.   {
  397.     return $this->cropWiseStatusLoad;
  398.   }
  399.   public function setCropWiseStatusLoad(?string $cropWiseStatusLoad): self
  400.   {
  401.     $this->cropWiseStatusLoad $cropWiseStatusLoad;
  402.     return $this;
  403.   }
  404.   public function getCropWiseReportId(): ?int
  405.   {
  406.     return $this->cropWiseReportId;
  407.   }
  408.   public function setCropWiseReportId(?int $cropWiseReportId): self
  409.   {
  410.     $this->cropWiseReportId $cropWiseReportId;
  411.     return $this;
  412.   }
  413.   public function getCropWiseReportPointId(): ?int
  414.   {
  415.     return $this->cropWiseReportPointId;
  416.   }
  417.   public function setCropWiseReportPointId(?int $cropWiseReportPointId): self
  418.   {
  419.     $this->cropWiseReportPointId $cropWiseReportPointId;
  420.     return $this;
  421.   }
  422.     /**
  423.      * @return mixed
  424.      */
  425.     public function getTelegramSend()
  426.     {
  427.         return $this->telegramSend;
  428.     }
  429.     /**
  430.      * @param bool $telegramSend
  431.      */
  432.     public function setTelegramSendbool $telegramSend): void
  433.     {
  434.         $this->telegramSend $telegramSend;
  435.     }
  436.     public function isRemoved(): ?bool
  437.     {
  438.         return $this->removed;
  439.     }
  440.     public function setRemoved(bool $removed): self
  441.     {
  442.         if(!is_null($removed)) {
  443.             $this->removed $removed;
  444.         }
  445.         return $this;
  446.     }
  447.     /**
  448.      * @return Collection<int, TelegramSenderLog>
  449.      */
  450.     public function getTelegramSenderLogs(): Collection
  451.     {
  452.         return $this->telegramSenderLogs;
  453.     }
  454.     public function addTelegramSenderLog(TelegramSenderLog $telegramSenderLog): self
  455.     {
  456.         if (!$this->telegramSenderLogs->contains($telegramSenderLog)) {
  457.             $this->telegramSenderLogs[] = $telegramSenderLog;
  458.             $telegramSenderLog->setReport($this);
  459.         }
  460.         return $this;
  461.     }
  462.     public function removeTelegramSenderLog(TelegramSenderLog $telegramSenderLog): self
  463.     {
  464.         if ($this->telegramSenderLogs->removeElement($telegramSenderLog)) {
  465.             // set the owning side to null (unless already changed)
  466.             if ($telegramSenderLog->getReport() === $this) {
  467.                 $telegramSenderLog->setReport(null);
  468.             }
  469.         }
  470.         return $this;
  471.     }
  472.     public function getToken()
  473.     {
  474.        return $this->getField()->getClient()->getCompany()->getCropWiseToken();
  475.     }
  476.     /**
  477.      * @return mixed
  478.      */
  479.     public function getCropWiseStatusDownload()
  480.     {
  481.         return $this->cropWiseStatusDownload;
  482.     }
  483.     /**
  484.      * @param mixed $cropWiseStatusDownload
  485.      */
  486.     public function setCropWiseStatusDownload($cropWiseStatusDownload): void
  487.     {
  488.         $this->cropWiseStatusDownload $cropWiseStatusDownload;
  489.     }
  490.     /**
  491.      * @return mixed
  492.      */
  493.     public function getCropWiseReportIdDownload()
  494.     {
  495.         return $this->cropWiseReportIdDownload;
  496.     }
  497.     /**
  498.      * @param mixed $cropWiseReportIdDownload
  499.      */
  500.     public function setCropWiseReportIdDownload($cropWiseReportIdDownload): void
  501.     {
  502.         $this->cropWiseReportIdDownload $cropWiseReportIdDownload;
  503.     }
  504.     /**
  505.      * @return mixed
  506.      */
  507.     public function getCropWiseReportPointIdDownload()
  508.     {
  509.         return $this->cropWiseReportPointIdDownload;
  510.     }
  511.     /**
  512.      * @param mixed $cropWiseReportPointIdDownload
  513.      */
  514.     public function setCropWiseReportPointIdDownload($cropWiseReportPointIdDownload): void
  515.     {
  516.         $this->cropWiseReportPointIdDownload $cropWiseReportPointIdDownload;
  517.     }
  518.     /**
  519.      * @return mixed
  520.      */
  521.     public function getCropWiseReportTemplateId()
  522.     {
  523.         return $this->cropWiseReportTemplateId;
  524.     }
  525.     /**
  526.      * @param mixed $cropWiseReportTemplateId
  527.      */
  528.     public function setCropWiseReportTemplateId($cropWiseReportTemplateId): void
  529.     {
  530.         $this->cropWiseReportTemplateId $cropWiseReportTemplateId;
  531.     }
  532. }