start = new \DateTime('now'); $this->end = (new \DateTime('now'))->modify('+1 month'); $this->calendar = new Calendar(); $this->costs = new Money(); $this->budget = new Money(); $this->earnings = new Money(); $this->createdAt = new \DateTimeImmutable('now'); $this->createdBy = new NullAccount(); $this->name = $name; } /** * Get id. * * @return int Model id * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Get media files. * * @return array * * @since 1.0.0 */ public function getMedia() : array { return $this->media; } /** * Add media file. * * @param mixed $media Media * * @return void * * @since 1.0.0 */ public function addMedia($media) : void { $this->media[] = $media; } /** * Get progress type. * * @return int * * @since 1.0.0 */ public function getProgressType() : int { return $this->progressType; } /** * Set progress type. * * @param int $type Progress type * * @return void * * @since 1.0.0 */ public function setProgressType(int $type) : void { $this->progressType = $type; } /** * Add task. * * @param Task $task Task * * @return void * * @since 1.0.0 */ public function addTask(Task $task) : void { $this->tasks[] = $task; } /** * Remove task * * @param int $id id to remove * * @return bool * * @since 1.0.0 */ public function removeTask(int $id) : bool { if (isset($this->tasks[$id])) { unset($this->tasks[$id]); return true; } return false; } /** * Get task by id. * * @param int $id Task id * * @return Task * * @since 1.0.0 */ public function getTask(int $id) : Task { return $this->tasks[$id] ?? new NullTask(); } /** * Get tasks. * * @return array * * @since 1.0.0 */ public function getTasks() : array { return $this->tasks; } /** * Count tasks. * * @return int * * @since 1.0.0 */ public function countTasks() : int { return \count($this->tasks); } /** * Set type * * @param int $type Type * * @return void * * @since 1.0.0 */ public function setType(int $type) : void { if (!EventType::isValidValue($type)) { throw new InvalidEnumValue($type); } $this->type = $type; } /** * Get type * * @return int * * @since 1.0.0 */ public function getType() : int { return $this->type; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'type' => $this->type, 'start' => $this->start, 'end' => $this->end, 'name' => $this->name, 'description' => $this->description, 'calendar' => $this->calendar, 'costs' => $this->costs, 'budget' => $this->budget, 'earnings' => $this->earnings, 'tasks' => $this->tasks, 'media' => $this->media, 'progress' => $this->progress, 'progressType' => $this->progressType, 'createdAt' => $this->createdAt, ]; } /** * {@inheritdoc} */ public function jsonSerialize() { return $this->toArray(); } }