* @since 1.0.0 */ private array $media = []; /** * Created at. * * @var \DateTimeImmutable * @since 1.0.0 */ public \DateTimeImmutable $createdAt; /** * Created by. * * @var Account * @since 1.0.0 */ public Account $createdBy; /** * Tasks. * * @var Task[] * @since 1.0.0 */ private $tasks = []; /** * Constructor. * * @param string $name Name of the project * * @since 1.0.0 */ public function __construct(string $name = '') { $this->start = new \DateTime('now'); $this->end = new \DateTime('now'); $this->end->modify('+1 month'); $this->endEstimated = clone $this->end; $this->createdAt = new \DateTimeImmutable('now'); $this->createdBy = new NullAccount(); $this->calendar = new Calendar(); $this->costs = new Money(); $this->budgetCosts = new Money(); $this->budgetEarnings = new Money(); $this->earnings = new Money(); $this->setName($name); } /** * Get id. * * @return int * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Get all media files. * * @return array * * @since 1.0.0 */ public function getMedias() : array { return $this->media; } /** * Add media * * @param int|Media $media Media * * @return void * * @since 1.0.0 */ public function addMedia($media) : void { if ($media instanceof Media && $media->getId() !== 0) { $this->media[$media->getId()] = $media; } else { $this->media[] = $media; } } /** * Remove media * * @param int $id Media id * * @return bool * * @since 1.0.0 */ public function removeMedia(int $id) : bool { if (isset($this->media[$id])) { unset($this->media[$id]); return true; } return false; } /** * Add task * * @param Task $task Task * * @return void * * @since 1.0.0 */ public function addTask(Task $task) : void { if ($task->getId() !== 0) { $this->tasks[$task->getId()] = $task; } else { $this->tasks[] = $task; } } /** * Remove task * * @param int $id Task id * * @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 progress * * @return int * * @since 1.0.0 */ public function getProgress() : int { return $this->progress; } /** * Set progress * * @param int $progress Progress * * @return void * * @since 1.0.0 */ public function setProgress(int $progress) : void { $this->progress = $progress; } /** * 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; } /** * Get task * * @param int $id Task id * * @return Task * * @since 1.0.0 */ public function getTask(int $id) : Task { return $this->tasks[$id] ?? new Task(); } /** * Get media * * @param int $id Media id * * @return int|Media * * @since 1.0.0 */ public function getMedia(int $id) { return $this->media[$id] ?? new NullMedia(); } /** * Get tasks * * @return Task[] * * @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); } /** * Count media * * @return int * * @since 1.0.0 */ public function countMedia() : int { return \count($this->media); } /** * Get start date * * @return \DateTime * * @since 1.0.0 */ public function getStart() : \DateTime { return $this->start; } /** * Set start date * * @param \DateTime $start Start date * * @return void * * @since 1.0.0 */ public function setStart(\DateTime $start) : void { $this->start = $start; } /** * Set end date * * @param \DateTime $end End date * * @return void * * @since 1.0.0 */ public function setEnd(\DateTime $end) : void { $this->end = $end; } /** * Get end date * * @return \DateTime * * @since 1.0.0 */ public function getEnd() : \DateTime { return $this->end; } /** * Set estimated end date * * @param \DateTime $end End date * * @return void * * @since 1.0.0 */ public function setEstimatedEnd(\DateTime $end) : void { $this->end = $end; } /** * Get estimated end date * * @return \DateTime * * @since 1.0.0 */ public function getEstimatedEnd() : \DateTime { return $this->end; } /** * Get name * * @return string * * @since 1.0.0 */ public function getName() : string { return $this->name; } /** * Set name * * @param string $name Project name * * @return void * * @since 1.0.0 */ public function setName(string $name) : void { $this->name = $name; $this->calendar->name = $name; } /** * Get costs * * @return Money * * @sicne 1.0.0 */ public function getCosts() : Money { return $this->costs; } /** * Get budget costs * * @return Money * * @sicne 1.0.0 */ public function getBudgetCosts() : Money { return $this->budgetCosts; } /** * Get budget earnings * * @return Money * * @sicne 1.0.0 */ public function getBudgetEarnings() : Money { return $this->budgetEarnings; } /** * Get earnings * * @return Money * * @sicne 1.0.0 */ public function getEarnings() : Money { return $this->earnings; } /** * Set costs * * @param Money $costs Costs * * @return void * * @since 1.0.0 */ public function setCosts(Money $costs) : void { $this->costs = $costs; } /** * Set budget costs * * @param Money $budget Budget * * @return void * * @since 1.0.0 */ public function setBudgetCosts(Money $budget) : void { $this->budgetCosts = $budget; } /** * Set budget earnings * * @param Money $budget Budget * * @return void * * @since 1.0.0 */ public function setBudgetEarnings(Money $budget) : void { $this->budgetEarnings = $budget; } /** * Set earnings * * @param Money $earnings Earnings * * @return void * * @since 1.0.0 */ public function setEarnings(Money $earnings) : void { $this->earnings = $earnings; } }