<?php
namespace App\Entity\Report;
use App\Entity\Agro\Operation;
use App\Entity\Field;
use App\Entity\Monitoring\Monitoring;
use App\Entity\Recommendation;
use App\Entity\Task\Objective;
use App\Entity\Techcard\Techcard;
use App\Entity\TelegramSenderLog;
use App\Entity\User;
use App\Repository\Report\ReportRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ReportRepository::class)
*/
class Report
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $formKey;
/**
* @ORM\ManyToOne(targetEntity=Operation::class)
*/
private $operation;
/**
* @ORM\ManyToOne(targetEntity=Monitoring::class)
*/
private $monitoring;
/**
* @ORM\ManyToOne(targetEntity=Techcard::class)
* @ORM\JoinColumn(nullable=true)
*/
private $techcard;
/**
* @ORM\ManyToOne(targetEntity=Field::class, inversedBy="reports")
* @ORM\JoinColumn(nullable=false)
*/
private $field;
/**
* @ORM\OneToMany(targetEntity=ReportValue::class, mappedBy="report", cascade={"persist","remove"})
*/
private $reportValues;
/**
* @ORM\ManyToOne(targetEntity=Task::class, inversedBy="reports")
*/
private $task;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="string", length=2)
*/
private $type;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $coordinat;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $distance;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $accuracy;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $comment;
/**
* @ORM\ManyToOne(targetEntity=Objective::class, inversedBy="reports")
*/
private $objective;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $errorsCount;
/**
* @ORM\OneToMany(targetEntity=Recommendation::class, mappedBy="report",cascade={"persist","remove"})
*/
private $recommendations;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cropWiseStatusLoad;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseReportId;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseReportPointId;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $telegramSend;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $removed;
/**
* @ORM\OneToMany(targetEntity=TelegramSenderLog::class, mappedBy="report")
*/
private $telegramSenderLogs;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cropWiseStatusDownload;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseReportIdDownload;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseReportPointIdDownload;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $cropWiseReportTemplateId;
public function __construct()
{
if (is_null($this->id)) {
$this->createdAt = new \DateTime();
$this->removed = false;
$this->telegramSend = false;
}
$this->reportValues = new ArrayCollection();
$this->recommendations = new ArrayCollection();
$this->telegramSenderLogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFormKey(): ?string
{
return $this->formKey;
}
public function setFormKey(string $formKey): self
{
$this->formKey = $formKey;
return $this;
}
public function getOperation(): ?Operation
{
return $this->operation;
}
public function setOperation(?Operation $operation): self
{
$this->operation = $operation;
return $this;
}
public function getMonitoring(): ?Monitoring
{
return $this->monitoring;
}
public function setMonitoring(?Monitoring $monitoring): self
{
$this->monitoring = $monitoring;
return $this;
}
public function getTechcard(): ?Techcard
{
return $this->techcard;
}
public function setTechcard(?Techcard $techcard): self
{
$this->techcard = $techcard;
return $this;
}
public function getField(): ?Field
{
return $this->field;
}
public function setField(?Field $field): self
{
$this->field = $field;
return $this;
}
/**
* @return Collection|ReportValue[]
*/
public function getReportValues(): Collection
{
return $this->reportValues;
}
public function addReportValue(ReportValue $reportValue): self
{
if (!$this->reportValues->contains($reportValue)) {
$this->reportValues[] = $reportValue;
$reportValue->setReport($this);
}
return $this;
}
public function removeReportValue(ReportValue $reportValue): self
{
if ($this->reportValues->removeElement($reportValue)) {
// set the owning side to null (unless already changed)
if ($reportValue->getReport() === $this) {
$reportValue->setReport(null);
}
}
return $this;
}
public function getTask(): ?Task
{
return $this->task;
}
public function setTask(?Task $task): self
{
$this->task = $task;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getName(): ?string
{
if (!empty($this->getOperation())) {
return $this->getOperation()->getName();
}
if (!empty($this->getMonitoring())) {
return $this->getMonitoring()->getName();
}
return null;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCoordinat(): ?string
{
return str_replace('-', ' ', $this->coordinat);
}
public function setCoordinat(?string $coordinat): self
{
$this->coordinat = $coordinat;
return $this;
}
public function getCoordinatArray()
{
$coordinate = str_replace('-', ' ', $this->coordinat);
$coordinate = preg_replace('@\s+@', ' ', $coordinate);
$explode = explode(' ', $coordinate);
try {
list($lat, $lng) = $explode;
return [
'lng' => $lng,
'lat' => $lat,
];
} catch (\Exception $e) {
return [];
}
}
public function getDistance($metr = true): int
{
return $this->convertDistance($this->distance, $metr);
}
public function setDistance(?string $distance): self
{
$this->distance = $distance;
return $this;
}
public function getAccuracy(): ?string
{
return $this->accuracy;
}
public function setAccuracy(?string $accuracy): self
{
$this->accuracy = $accuracy;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getObjective(): ?Objective
{
return $this->objective;
}
public function setObjective(?Objective $objective): self
{
$this->objective = $objective;
return $this;
}
public function getErrorsCount(): ?int
{
return $this->errorsCount;
}
public function setErrorsCount(?int $errorsCount): self
{
$this->errorsCount = $errorsCount;
return $this;
}
public function getDistanceMin($metr = true)
{
$distance = [];
$values = $this->getReportValues();
if ($values->count() > 0) {
/** @var ReportValue $value */
foreach ($values as $value) {
if (!empty($value->getDistance())) {
$distance[] = $value->getDistance();
}
}
if (!empty($distance)) {
sort($distance);
return $this->convertDistance(end($distance), $metr);
}
}
return $this->convertDistance($this->getDistance(), $metr);
}
private function convertDistance($distance, $metr)
{
if (!empty($distance) && $distance > 0) {
$number = ceil($distance);
if ($number > 10000) {
$metr = true;
}
if ($metr) {
return (int)$number;
} else {
return (int)($number / 1000);
}
}
return (int)$distance;
}
/**
* @return Collection<int, Recommendation>
*/
public function getRecommendations(): Collection
{
return $this->recommendations;
}
public function addRecommendation(Recommendation $recommendation): self
{
if (!$this->recommendations->contains($recommendation)) {
$this->recommendations[] = $recommendation;
$recommendation->setReport($this);
}
return $this;
}
public function removeRecommendation(Recommendation $recommendation): self
{
if ($this->recommendations->removeElement($recommendation)) {
// set the owning side to null (unless already changed)
if ($recommendation->getReport() === $this) {
$recommendation->setReport(null);
}
}
return $this;
}
public function getCropWiseStatusLoad(): ?string
{
return $this->cropWiseStatusLoad;
}
public function setCropWiseStatusLoad(?string $cropWiseStatusLoad): self
{
$this->cropWiseStatusLoad = $cropWiseStatusLoad;
return $this;
}
public function getCropWiseReportId(): ?int
{
return $this->cropWiseReportId;
}
public function setCropWiseReportId(?int $cropWiseReportId): self
{
$this->cropWiseReportId = $cropWiseReportId;
return $this;
}
public function getCropWiseReportPointId(): ?int
{
return $this->cropWiseReportPointId;
}
public function setCropWiseReportPointId(?int $cropWiseReportPointId): self
{
$this->cropWiseReportPointId = $cropWiseReportPointId;
return $this;
}
/**
* @return mixed
*/
public function getTelegramSend()
{
return $this->telegramSend;
}
/**
* @param bool $telegramSend
*/
public function setTelegramSend( bool $telegramSend): void
{
$this->telegramSend = $telegramSend;
}
public function isRemoved(): ?bool
{
return $this->removed;
}
public function setRemoved(bool $removed): self
{
if(!is_null($removed)) {
$this->removed = $removed;
}
return $this;
}
/**
* @return Collection<int, TelegramSenderLog>
*/
public function getTelegramSenderLogs(): Collection
{
return $this->telegramSenderLogs;
}
public function addTelegramSenderLog(TelegramSenderLog $telegramSenderLog): self
{
if (!$this->telegramSenderLogs->contains($telegramSenderLog)) {
$this->telegramSenderLogs[] = $telegramSenderLog;
$telegramSenderLog->setReport($this);
}
return $this;
}
public function removeTelegramSenderLog(TelegramSenderLog $telegramSenderLog): self
{
if ($this->telegramSenderLogs->removeElement($telegramSenderLog)) {
// set the owning side to null (unless already changed)
if ($telegramSenderLog->getReport() === $this) {
$telegramSenderLog->setReport(null);
}
}
return $this;
}
public function getToken()
{
return $this->getField()->getClient()->getCompany()->getCropWiseToken();
}
/**
* @return mixed
*/
public function getCropWiseStatusDownload()
{
return $this->cropWiseStatusDownload;
}
/**
* @param mixed $cropWiseStatusDownload
*/
public function setCropWiseStatusDownload($cropWiseStatusDownload): void
{
$this->cropWiseStatusDownload = $cropWiseStatusDownload;
}
/**
* @return mixed
*/
public function getCropWiseReportIdDownload()
{
return $this->cropWiseReportIdDownload;
}
/**
* @param mixed $cropWiseReportIdDownload
*/
public function setCropWiseReportIdDownload($cropWiseReportIdDownload): void
{
$this->cropWiseReportIdDownload = $cropWiseReportIdDownload;
}
/**
* @return mixed
*/
public function getCropWiseReportPointIdDownload()
{
return $this->cropWiseReportPointIdDownload;
}
/**
* @param mixed $cropWiseReportPointIdDownload
*/
public function setCropWiseReportPointIdDownload($cropWiseReportPointIdDownload): void
{
$this->cropWiseReportPointIdDownload = $cropWiseReportPointIdDownload;
}
/**
* @return mixed
*/
public function getCropWiseReportTemplateId()
{
return $this->cropWiseReportTemplateId;
}
/**
* @param mixed $cropWiseReportTemplateId
*/
public function setCropWiseReportTemplateId($cropWiseReportTemplateId): void
{
$this->cropWiseReportTemplateId = $cropWiseReportTemplateId;
}
}