createdBy = new NullAccount(); $this->createdAt = new \DateTimeImmutable('now'); $this->schedule = new Schedule(); $this->start = new \DateTime('now'); $this->due = new \DateTime('now'); $this->due->modify('+1 day'); } /** * Adding new task element. * * @param TaskElement $element Task element * * @return int * * @since 1.0.0 */ public function addElement(TaskElement $element) : int { $this->taskElements[] = $element; \end($this->taskElements); $key = (int) \key($this->taskElements); \reset($this->taskElements); return $key; } /** * Adding new tag. * * @param Tag $tag Tag * * @return int * * @since 1.0.0 */ public function addTag(Tag $tag) : int { $this->tags[] = $tag; \end($this->tags); $key = (int) \key($this->tags); \reset($this->tags); return $key; } /** * Check if user is in to * * @param int $id User id * * @return bool * * @since 1.0.0 */ public function isToAccount(int $id) : bool { foreach ($this->taskElements as $element) { if ($element->isToAccount($id)) { return true; } } return false; } /** * Check if group is in to * * @param int $id Group id * * @return bool * * @since 1.0.0 */ public function isToGroup(int $id) : bool { foreach ($this->taskElements as $element) { if ($element->isToGroup($id)) { return true; } } return false; } /** * Check if user is in cc * * @param int $id User id * * @return bool * * @since 1.0.0 */ public function isCCAccount(int $id) : bool { foreach ($this->taskElements as $element) { if ($element->isCCAccount($id)) { return true; } } return false; } /** * Check if group is in cc * * @param int $id Group id * * @return bool * * @since 1.0.0 */ public function isCCGroup(int $id) : bool { foreach ($this->taskElements as $element) { if ($element->isCCGroup($id)) { return true; } } return false; } /** * Get created by * * @return Account * * @since 1.0.0 */ public function getCreatedBy() : Account { return $this->createdBy; } /** * Set created by * * @param Account $account Created by * * @return void * * @since 1.0.0 */ public function setCreatedBy(Account $account) : void { $this->createdBy = $account; $this->schedule->createdBy = $account; } /** * Remove Element from list. * * @param int $id Task element * * @return bool * * @since 1.0.0 */ public function removeElement($id) : bool { if (isset($this->taskElements[$id])) { unset($this->taskElements[$id]); return true; } return false; } /** * Get task elements. * * @return TaskElement[] * * @since 1.0.0 */ public function getTaskElements() : array { return $this->taskElements; } /** * Get task elements in inverted order. * * @return TaskElement[] * * @since 1.0.0 */ public function invertTaskElements() : array { return \array_reverse($this->taskElements); } /** * Get task elements. * * @param int $id Element id * * @return TaskElement * * @since 1.0.0 */ public function getTaskElement(int $id) : TaskElement { return $this->taskElements[$id] ?? new NullTaskElement(); } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'createdBy' => $this->createdBy, 'createdAt' => $this->createdAt, 'title' => $this->title, 'description' => $this->description, 'descriptionRaw' => $this->descriptionRaw, 'status' => $this->status, 'type' => $this->type, 'priority' => $this->priority, 'due' => $this->due, 'done' => $this->done, 'tags' => $this->tags, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } use \Modules\Media\Models\MediaListTrait; use \Modules\Attribute\Models\AttributeHolderTrait; }