tags = new ArrayCollection(); } /** * Get entry id, returns null for new entities which were not persisted. * * @return int|null */ public function getId(): ?int { return $this->id; } /** * Make sure begin and end date have the correct timezone. * This will be called once for each item after being loaded from the database. */ protected function localizeDates() { if ($this->localized) { return; } if (null !== $this->begin) { $this->begin->setTimeZone(new \DateTimeZone($this->timezone)); } if (null !== $this->end) { $this->end->setTimeZone(new \DateTimeZone($this->timezone)); } $this->localized = true; } public function getBegin(): ?\DateTime { $this->localizeDates(); return $this->begin; } /** * @param \DateTime $begin * @return Timesheet */ public function setBegin(\DateTime $begin): Timesheet { $this->begin = $begin; $this->timezone = $begin->getTimezone()->getName(); return $this; } public function getEnd(): ?\DateTime { $this->localizeDates(); return $this->end; } /** * @param \DateTime $end * @return Timesheet */ public function setEnd(?\DateTime $end): Timesheet { $this->end = $end; if (null === $end) { $this->duration = 0; $this->rate = 0.00; } else { $this->timezone = $end->getTimezone()->getName(); } return $this; } /** * @param int $duration * @return Timesheet */ public function setDuration($duration): Timesheet { $this->duration = $duration; return $this; } /** * Do not rely on the results of this method for running records. * * @return int */ public function getDuration() { return $this->duration; } /** * @param User $user * @return Timesheet */ public function setUser(User $user): Timesheet { $this->user = $user; return $this; } public function getUser(): ?User { return $this->user; } /** * @param Activity $activity * @return Timesheet */ public function setActivity($activity): Timesheet { $this->activity = $activity; return $this; } public function getActivity(): ?Activity { return $this->activity; } public function getProject(): ?Project { return $this->project; } /** * @param Project $project * @return Timesheet */ public function setProject(Project $project): Timesheet { $this->project = $project; return $this; } /** * @param string $description * @return Timesheet */ public function setDescription($description): Timesheet { $this->description = $description; return $this; } public function getDescription(): ?string { return $this->description; } /** * @param float $rate * @return Timesheet */ public function setRate($rate): Timesheet { $this->rate = $rate; return $this; } /** * @return float */ public function getRate() { return $this->rate; } /** * @param Tag $tag * @return Timesheet */ public function addTag(Tag $tag): Timesheet { if ($this->tags->contains($tag)) { return $this; } $this->tags->add($tag); $tag->addTimesheet($this); return $this; } /** * @param Tag $tag */ public function removeTag(Tag $tag) { if (!$this->tags->contains($tag)) { return; } $this->tags->removeElement($tag); $tag->removeTimesheet($this); } /** * @return Collection */ public function getTags(): Collection { return $this->tags; } /** * @return string[] */ public function getTagsAsArray() { return array_map( function (Tag $element) { return $element->getName(); }, $this->getTags()->toArray() ); } /** * @return bool */ public function isExported(): bool { return $this->exported; } /** * @param bool $exported * @return Timesheet */ public function setExported(bool $exported): Timesheet { $this->exported = $exported; return $this; } /** * @return string */ public function getTimezone(): string { return $this->timezone; } /** * BE WARNED: this method should NOT be used programmatically, there is very likely no reason for it! * * @deprecated since it was introduced, only meant for the initial migration. Will be removed with 1.0. * @param string $timezone * @return Timesheet */ public function setTimezone(string $timezone): Timesheet { $this->timezone = $timezone; return $this; } }