src/Entity/Report/TaskList.php line 17

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\Season;
  7. use App\Repository\Report\TaskListRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12.  * @ORM\Entity(repositoryClass=TaskListRepository::class)
  13.  */
  14. class TaskList
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=Field::class, inversedBy="taskLists")
  24.      */
  25.     private $field;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Season::class, inversedBy="taskLists")
  28.      */
  29.     private $season;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=Task::class, mappedBy="taskList",cascade={"persist","remove"})
  32.      */
  33.     private $tasks;
  34.     public function __construct()
  35.     {
  36.         $this->tasks = new ArrayCollection();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getField(): ?Field
  43.     {
  44.         return $this->field;
  45.     }
  46.     public function setField(?Field $field): self
  47.     {
  48.         $this->field $field;
  49.         return $this;
  50.     }
  51.     public function getSeason(): ?Season
  52.     {
  53.         return $this->season;
  54.     }
  55.     public function setSeason(?Season $season): self
  56.     {
  57.         $this->season $season;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @return Collection|Task[]
  62.      */
  63.     public function getTasks(): Collection
  64.     {
  65.         return $this->tasks;
  66.     }
  67.     public function addTask(Task $task): self
  68.     {
  69.         if (!$this->tasks->contains($task)) {
  70.             $this->tasks[] = $task;
  71.             $task->setTaskList($this);
  72.         }
  73.         return $this;
  74.     }
  75.     public function removeTask(Task $task): self
  76.     {
  77.         if ($this->tasks->removeElement($task)) {
  78.             // set the owning side to null (unless already changed)
  79.             if ($task->getTaskList() === $this) {
  80.                 $task->setTaskList(null);
  81.                 $task->removeAllReports();
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeAllTask(): self
  87.     {
  88.         foreach ($this->getTasks() as $task)
  89.         {
  90.             $this->removeTask($task);
  91.         }
  92.         return $this;
  93.     }
  94.     public function getTaskMonitoring()
  95.     {
  96.         return $this->tasks->filter(function ($task){
  97.             if(!empty($task->getMonitoring())){
  98.                 return $task;
  99.             }
  100.             return null;
  101.         });
  102.     }
  103.     public function getTaskOperation()
  104.     {
  105.         return $this->tasks->filter(function ($task){
  106.             if(!empty($task->getOperation())){
  107.                 return $task;
  108.             }
  109.             return null;
  110.         });
  111.     }
  112. }