createdBy = new NullAccount(); $this->createdAt = new \DateTimeImmutable('now'); $this->location = new Location(); $this->schedule = new Schedule(); $this->start = new \DateTime('now'); $this->end = new \DateTime('now'); } /** * @return Account[] * * @since 1.0.0 */ public function getPeople() : array { return $this->people; } /** * @param int $id Account id * * @return Account * * @since 1.0.0 */ public function getPerson(int $id) : Account { return $this->people[$id] ?? new NullAccount(); } /** * @param Account $person Person to add * * @return void * * @since 1.0.0 */ public function addPerson(Account $person) : void { $this->people[$person->id] = $person; } /** * Remove Element from list. * * @param int $id Task element * * @return bool * * @since 1.0.0 */ public function removePerson(int $id) : bool { if (isset($this->people[$id])) { unset($this->people[$id]); return true; } return false; } /** * @return Account * * @since 1.0.0 */ public function getCreatedBy() : Account { return $this->createdBy; } /** * Set creator * * @param Account $createdBy Creator * * @return void * * @since 1.0.0 */ public function setCreatedBy(Account $createdBy) : void { $this->createdBy = $createdBy; if ($this->schedule instanceof Schedule) { $this->schedule->createdBy = $this->createdBy; } } /** * 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; } /** * Remove Tag from list. * * @param int $id Tag * * @return bool * * @since 1.0.0 */ public function removeTag($id) : bool { if (isset($this->tags[$id])) { unset($this->tags[$id]); return true; } return false; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, 'type' => $this->type, 'status' => $this->status, 'schedule' => $this->schedule, 'location' => $this->location, 'calendar' => $this->calendar, 'people' => $this->people, 'tags' => $this->tags, 'createdAt' => $this->createdAt, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }