oms-Tasks/Models/Task.php

399 lines
7.2 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace Modules\Tasks\Models;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
/**
* Task class.
*
* @category Modules
* @package Tasks
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Task
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
private $id = 0;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
private $title = '';
/**
* Creator.
*
* @var int
* @since 1.0.0
*/
private $createdBy = 0;
/**
* Created.
*
* @var \DateTime
* @since 1.0.0
*/
private $createdAt = null;
/**
* Description.
*
* @var string
* @since 1.0.0
*/
private $description = '';
/**
* Type.
*
* @var TaskType
* @since 1.0.0
*/
private $type = TaskType::TASK;
/**
* Status.
*
* @var TaskStatus
* @since 1.0.0
*/
private $status = TaskStatus::OPEN;
/**
* Due.
*
* @var \DateTime
* @since 1.0.0
*/
private $due = null;
/**
* Done.
*
* @var \DateTime
* @since 1.0.0
*/
private $done = null;
/**
* Task elements.
*
* @var TaskElement[]
* @since 1.0.0
*/
private $taskElements = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->due = (new \DateTime('now'))->modify('+1 day');
}
/**
* Adding new task element.
*
* @param TaskElement $element Task element
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function addElement(TaskElement $element) : int
{
$this->taskElements[] = $element;
end($this->taskElements);
$key = key($this->taskElements);
reset($this->taskElements);
return $key;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt ?? new \DateTime();
}
/**
* @param \DateTime $created
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $created)
{
$this->createdAt = $created;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $id)
{
$this->createdBy = $id;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDescription() : string
{
return $this->description;
}
/**
* @param string $description
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDescription(string $description)
{
$this->description = $description;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDone()
{
return $this->done;
}
/**
* @param \DateTime $done
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDone(\DateTime $done)
{
$this->done = $done;;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDue() : \DateTime
{
return $this->due;
}
/**
* @param \DateTime $due
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDue(\DateTime $due)
{
$this->due = $due;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getStatus() : int
{
return $this->status;
}
/**
* @param int $status
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setStatus(int $status)
{
if(!TaskStatus::isValidValue($status)) {
throw new InvalidEnumValue($status);
}
$this->status = $status;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTitle() : string
{
return $this->title;
}
/**
* @param string $title
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* Remove Element from list.
*
* @param int $id Task element
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTaskElements() : array
{
return $this->taskElements;
}
/**
* Get task elements.
*
* @param int $id Element id
*
* @return TaskElement
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTaskElement(int $id) : TaskElement
{
return $this->taskElements[$id] ?? new NullTaskElement();
}
/**
* Get task type.
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : int
{
return $this->type;
}
/**
* Set task type.
*
* @param int $type
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setType(\int $type)
{
if(!TaskType::isValidValue($type)) {
throw new InvalidEnumValue($type);
}
$this->type = $type;
}
}