setDefaults([ 'order' => self::ORDER_DESC, 'orderBy' => 'begin', 'dateRange' => new DateRange() ]); } public function addUser(User $user): self { $this->users[$user->getId()] = $user; return $this; } public function removeUser(User $user): self { if (isset($this->users[$user->getId()])) { unset($this->users[$user->getId()]); } return $this; } /** * @return User[] */ public function getUsers(): array { return array_values($this->users); } /** * Limit the data exclusively to the user (eg. users own timesheets). * * @return User|null */ public function getUser() { return $this->timesheetUser; } /** * Limit the data exclusively to the user (eg. users own timesheets). * * @param User|int|null $user * @return TimesheetQuery */ public function setUser($user = null) { $this->timesheetUser = $user; return $this; } /** * Activity overwrites: setProject() and setCustomer() * * @return Activity|null */ public function getActivity() { return $this->activity; } /** * @param Activity|int|null $activity * @return TimesheetQuery */ public function setActivity($activity = null) { $this->activity = $activity; return $this; } /** * @return int */ public function getState() { return $this->state; } /** * @param int $state * @return TimesheetQuery */ public function setState($state) { $state = (int) $state; if (in_array($state, [self::STATE_ALL, self::STATE_RUNNING, self::STATE_STOPPED], true)) { $this->state = $state; } return $this; } /** * @return int */ public function getExported() { return $this->exported; } /** * @param int $exported * @return TimesheetQuery */ public function setExported($exported) { $exported = (int) $exported; if (in_array($exported, [self::STATE_ALL, self::STATE_EXPORTED, self::STATE_NOT_EXPORTED], true)) { $this->exported = $exported; } return $this; } public function getBegin(): ?\DateTime { return $this->dateRange->getBegin(); } /** * @param \DateTime $begin * @return TimesheetQuery */ public function setBegin($begin) { $this->dateRange->setBegin($begin); return $this; } public function getEnd(): ?\DateTime { return $this->dateRange->getEnd(); } /** * @param \DateTime $end * @return TimesheetQuery */ public function setEnd($end) { $this->dateRange->setEnd($end); return $this; } /** * @return DateRange */ public function getDateRange(): DateRange { return $this->dateRange; } /** * @param DateRange $dateRange * @return TimesheetQuery */ public function setDateRange(DateRange $dateRange) { $this->dateRange = $dateRange; return $this; } /** * @return iterable */ public function getTags($allowUnknown = false) { if (empty($this->tags)) { return []; } $result = []; foreach ($this->tags as $tag) { if (!$allowUnknown && $tag instanceof Tag && null === $tag->getId()) { continue; } $result[] = $tag; } return $result; } /** * @param iterable $tags * @return $this */ public function setTags(iterable $tags) { $this->tags = $tags; return $this; } }