src/Entity/Task.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TaskRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. #[ORM\Entity(repositoryClassTaskRepository::class)]
  9. class Task
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     #[Groups(['LogService'])]
  15.     private $id;
  16.     #[ORM\Column(type'date')]
  17.     #[Groups(['LogService'])]
  18.     private $week;
  19.     #[ORM\ManyToOne(targetEntityProject::class, inversedBy'tasks')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private $project;
  22.     #[ORM\ManyToOne(targetEntityTaskType::class, inversedBy'tasks')]
  23.     #[ORM\JoinColumn(nullablefalse)]
  24.     private $taskType;
  25.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'tasks')]
  26.     #[ORM\JoinColumn(nullablefalse)]
  27.     private $user;
  28.     #[ORM\OneToMany(targetEntityTimeSpent::class, mappedBy'task'orphanRemovaltruefetch'EXTRA_LAZY')]
  29.     #[ORM\OrderBy(['date' => 'ASC'])]
  30.     private $timeSpents;
  31.     #[ORM\Column(type'datetime'nullabletrue)]
  32.     #[Groups(['LogService'])]
  33.     private $createdAt;
  34.     #[ORM\Column(type'datetime'nullabletrue)]
  35.     #[Groups(['LogService'])]
  36.     private $updatedAt;
  37.     public function __construct()
  38.     {
  39.         $this->timeSpents = new ArrayCollection();
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getWeek(): ?\DateTimeInterface
  46.     {
  47.         return $this->week;
  48.     }
  49.     public function setWeek(\DateTimeInterface $week): self
  50.     {
  51.         $this->week $week;
  52.         return $this;
  53.     }
  54.     public function getProject(): ?Project
  55.     {
  56.         return $this->project;
  57.     }
  58.     public function setProject(?Project $project): self
  59.     {
  60.         $this->project $project;
  61.         return $this;
  62.     }
  63.     public function getTaskType(): ?TaskType
  64.     {
  65.         return $this->taskType;
  66.     }
  67.     public function setTaskType(?TaskType $taskType): self
  68.     {
  69.         $this->taskType $taskType;
  70.         return $this;
  71.     }
  72.     public function getUser(): ?User
  73.     {
  74.         return $this->user;
  75.     }
  76.     public function setUser(?User $user): self
  77.     {
  78.         $this->user $user;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection<int, TimeSpent>
  83.      */
  84.     public function getTimeSpents(): Collection
  85.     {
  86.         return $this->timeSpents;
  87.     }
  88.     public function addTimeSpent(TimeSpent $timeSpent): self
  89.     {
  90.         if (!$this->timeSpents->contains($timeSpent)) {
  91.             $this->timeSpents[] = $timeSpent;
  92.             $timeSpent->setTask($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeTimeSpent(TimeSpent $timeSpent): self
  97.     {
  98.         if ($this->timeSpents->removeElement($timeSpent)) {
  99.             // set the owning side to null (unless already changed)
  100.             if ($timeSpent->getTask() === $this) {
  101.                 $timeSpent->setTask(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106.     public function getTimeSpentHours($date)
  107.     {
  108.         foreach($this->timeSpents as $timeSpent){
  109.             if($timeSpent->getDate()->format('Y-m-d') == $date) return $timeSpent->getHours();
  110.         }
  111.         return 0;
  112.     }
  113.     public function getWeeklyTotalHours(){
  114.         $total 0;
  115.         foreach($this->timeSpents as $timeSpent){
  116.             $total += $timeSpent->getHours();
  117.         }
  118.         return $total;
  119.     }
  120.     public function getCreatedAt(): ?\DateTimeInterface
  121.     {
  122.         return $this->createdAt;
  123.     }
  124.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  125.     {
  126.         $this->createdAt $createdAt;
  127.         return $this;
  128.     }
  129.     public function getUpdatedAt(): ?\DateTimeInterface
  130.     {
  131.         return $this->updatedAt;
  132.     }
  133.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  134.     {
  135.         $this->updatedAt $updatedAt;
  136.         return $this;
  137.     }
  138. }