src/Entity/Task/Objective.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Task;
  3. use App\Constant\StatusConstant;
  4. use App\Constant\StatusObjectiveConstant;
  5. use App\Entity\Agro\Operation;
  6. use App\Entity\Client;
  7. use App\Entity\Culture;
  8. use App\Entity\Field;
  9. use App\Entity\Report\Report;
  10. use App\Entity\Report\Task;
  11. use App\Entity\Season;
  12. use App\Entity\Techcard\Techcard;
  13. use App\Entity\User;
  14. use App\Model\CacheRemover;
  15. use App\Repository\Task\ObjectiveRepository;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Faker\Provider\DateTime;
  20. /**
  21.  * @ORM\Entity(repositoryClass=ObjectiveRepository::class)
  22.  */
  23. class Objective
  24. {
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=Client::class, inversedBy="objectives")
  33.      */
  34.     private $client;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Season::class, inversedBy="objectives")
  37.      */
  38.     private $season;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=Culture::class, inversedBy="objectives")
  41.      */
  42.     private $culture;
  43.     /**
  44.      * @ORM\Column(type="boolean")
  45.      */
  46.     private $typeProcedure;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $name;
  51.     /**
  52.      * @ORM\Column(type="text", nullable=true)
  53.      */
  54.     private $description;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $priority;
  59.     /**
  60.      * @ORM\Column(type="date", nullable=true)
  61.      */
  62.     private $dateCompletion;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="ownerObjectives")
  65.      */
  66.     private $owner;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="viewerObjectives")
  69.      */
  70.     private $viewer;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity=Techcard::class, inversedBy="objectives")
  73.      */
  74.     private $techcard;
  75.     /**
  76.      * @ORM\ManyToOne(targetEntity=Operation::class, inversedBy="objectives")
  77.      */
  78.     private $operation;
  79.     /**
  80.      * @ORM\Column(type="string", length=255)
  81.      */
  82.     private $status;
  83.     /**
  84.      * @ORM\Column(type="json", nullable=true)
  85.      */
  86.     private $infoFiles = [];
  87.     /**
  88.      * @ORM\ManyToOne(targetEntity=Field::class, inversedBy="objectives")
  89.      */
  90.     private $field;
  91.     /**
  92.      * @ORM\ManyToOne(targetEntity=MonitoringObjective::class, inversedBy="objectives", cascade={"persist", "remove"})
  93.      */
  94.     private $monitoringObjective;
  95.     /**
  96.      * @ORM\OneToOne(targetEntity=Task::class, mappedBy="objective", cascade={"persist", "remove"})
  97.      */
  98.     private $task;
  99.     /**
  100.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="creatorObjectives")
  101.      */
  102.     private $creator;
  103.     /**
  104.      * @ORM\OneToMany(targetEntity=Report::class, mappedBy="objective", cascade={"remove"})
  105.      */
  106.     private $reports;
  107.     /**
  108.      * @ORM\Column(type="datetime", nullable=true)
  109.      */
  110.     private $updateAt;
  111.     /**
  112.      * @ORM\Column(type="string", length=255, nullable=true)
  113.      */
  114.     private $hash;
  115.     public function __construct()
  116.     {
  117.         if($this->id === null){
  118.             $this->name 'Новая задача';
  119.             $this->priority StatusObjectiveConstant::NORMAL;
  120.             $this->typeProcedure false;
  121.             $this->status StatusConstant::NEW;
  122.             $this->setHash();
  123.         }
  124.         $this->updateAt = new \DateTime();
  125.         $this->fields = new ArrayCollection();
  126.         $this->reports = new ArrayCollection();
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getClient(): ?Client
  133.     {
  134.         return $this->client;
  135.     }
  136.     public function setClient(?Client $client): self
  137.     {
  138.         $this->client $client;
  139.         return $this;
  140.     }
  141.     public function getSeason(): ?Season
  142.     {
  143.         return $this->season;
  144.     }
  145.     public function setSeason(?Season $season): self
  146.     {
  147.         $this->season $season;
  148.         return $this;
  149.     }
  150.     public function getCulture(): ?Culture
  151.     {
  152.         return $this->culture;
  153.     }
  154.     public function setCulture(?Culture $culture): self
  155.     {
  156.         $this->culture $culture;
  157.         return $this;
  158.     }
  159.     public function isTypeProcedure(): ?bool
  160.     {
  161.         return $this->typeProcedure;
  162.     }
  163.     public function setTypeProcedure(bool $typeProcedure): self
  164.     {
  165.         $this->typeProcedure $typeProcedure;
  166.         return $this;
  167.     }
  168.     public function getName(?bool $operation true): ?string
  169.     {
  170.         if(!empty($this->getOperation()) && $operation){
  171.             return $this->getOperation()->getName();
  172.         }
  173.         return $this->name;
  174.     }
  175.     public function setName(?string $name): self
  176.     {
  177.         $this->name $name;
  178.         return $this;
  179.     }
  180.     public function getDescription(): ?string
  181.     {
  182.         return $this->description;
  183.     }
  184.     public function setDescription(?string $description): self
  185.     {
  186.         $this->description $description;
  187.         return $this;
  188.     }
  189.     public function getPriority(): ?string
  190.     {
  191.         return $this->priority;
  192.     }
  193.     public function setPriority(?string $priority): self
  194.     {
  195.         $this->priority $priority;
  196.         return $this;
  197.     }
  198.     public function getDateCompletion(): ?\DateTimeInterface
  199.     {
  200.         return $this->dateCompletion;
  201.     }
  202.     public function setDateCompletion(\DateTimeInterface $dateCompletion): self
  203.     {
  204.         $this->dateCompletion $dateCompletion;
  205.         return $this;
  206.     }
  207.     public function getOwner(): ?User
  208.     {
  209.         return $this->owner;
  210.     }
  211.     public function setOwner(?User $owner): self
  212.     {
  213.         $this->owner $owner;
  214.         return $this;
  215.     }
  216.     public function getViewer(): ?User
  217.     {
  218.         return $this->viewer;
  219.     }
  220.     public function setViewer(?User $viewer): self
  221.     {
  222.         $this->viewer $viewer;
  223.         if(!empty($viewer) && empty($this->dateCompletion)){
  224.             $this->dateCompletion = new \DateTime();
  225.         }
  226.         return $this;
  227.     }
  228.     public function getTechcard(): ?Techcard
  229.     {
  230.         return $this->techcard;
  231.     }
  232.     public function setTechcard(?Techcard $techcard): self
  233.     {
  234.         $this->techcard $techcard;
  235.         return $this;
  236.     }
  237.     public function getOperation(): ?Operation
  238.     {
  239.         return $this->operation;
  240.     }
  241.     public function setOperation(?Operation $operation): self
  242.     {
  243.         $this->operation $operation;
  244.         return $this;
  245.     }
  246.     public function getStatus(): ?string
  247.     {
  248.         return $this->status;
  249.     }
  250.     public function setStatus(string $status): self
  251.     {
  252.         $this->status $status;
  253.         if($status == StatusConstant::IN_PROGRESS && empty($this->dateCompletion)){
  254.             $this->dateCompletion = new \DateTime();
  255.         }
  256.         return $this;
  257.     }
  258.     public function getInfoFiles(): ?array
  259.     {
  260.         return $this->infoFiles;
  261.     }
  262.     public function setInfoFiles(?array $infoFiles): self
  263.     {
  264.         $this->infoFiles $infoFiles;
  265.         return $this;
  266.     }
  267.     public function getField(): ?Field
  268.     {
  269.         return $this->field;
  270.     }
  271.     public function setField(?Field $field): self
  272.     {
  273.         $this->field $field;
  274.         return $this;
  275.     }
  276.     public function getMonitoringObjective(): ?MonitoringObjective
  277.     {
  278.         return $this->monitoringObjective;
  279.     }
  280.     public function setMonitoringObjective(?MonitoringObjective $monitoringObjective): self
  281.     {
  282.         $this->monitoringObjective $monitoringObjective;
  283.         return $this;
  284.     }
  285.     public function getTask(): ?Task
  286.     {
  287.         return $this->task;
  288.     }
  289.     public function setTask(?Task $task): self
  290.     {
  291.         // unset the owning side of the relation if necessary
  292.         if ($task === null && $this->task !== null) {
  293.             $this->task->setObjective(null);
  294.         }
  295.         // set the owning side of the relation if necessary
  296.         if ($task !== null && $task->getObjective() !== $this) {
  297.             $task->setObjective($this);
  298.         }
  299.         $this->task $task;
  300.         return $this;
  301.     }
  302.     public function getCreator(): ?User
  303.     {
  304.         return $this->creator;
  305.     }
  306.     public function setCreator(?User $creator): self
  307.     {
  308.         $this->creator $creator;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, Report>
  313.      */
  314.     public function getReports(): Collection
  315.     {
  316.         return $this->reports;
  317.     }
  318.     public function addReport(Report $report): self
  319.     {
  320.         if (!$this->reports->contains($report)) {
  321.             $this->reports[] = $report;
  322.             $report->setObjective($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeReport(Report $report): self
  327.     {
  328.         if ($this->reports->removeElement($report)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($report->getObjective() === $this) {
  331.                 $report->setObjective(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     public function getUpdateAt(): ?\DateTimeInterface
  337.     {
  338.         return $this->updateAt;
  339.     }
  340.     public function setUpdateAt(?\DateTimeInterface $updateAt): self
  341.     {
  342.         $this->updateAt $updateAt;
  343.         return $this;
  344.     }
  345.     public function __clone()
  346.     {
  347.         $this->id null;
  348.         $this->field null;
  349.     }
  350.     public function getHash(): ?string
  351.     {
  352.         return $this->hash;
  353.     }
  354.     public function setHash(): self
  355.     {
  356.         $this->hash md5(date('YmdHis').microtime(true).rand(0,999999));
  357.         return $this;
  358.     }
  359. }