oms-Kanban/Models/KanbanCard.php
2019-10-06 17:50:12 +02:00

308 lines
5.4 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Kanban\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Kanban\Models;
/**
* Task class.
*
* @package Modules\Kanban\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class KanbanCard implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name.
*
* @var string
* @since 1.0.0
*/
private string $name = '';
private int $status = CardStatus::ACTIVE;
private int $type = CardType::TEXT;
/**
* Description.
*
* @var string
* @since 1.0.0
*/
private string $description = '';
private $column = 0;
private $order = 0;
private $ref = 0;
private $createdBy = 0;
private $createdAt = null;
private $comments = [];
private $labels = [];
private $media = [];
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
}
public function getOrder() : int
{
return $this->order;
}
public function setOrder(int $order) : void
{
$this->order = $order;
}
/**
* Get id.
*
* @return int Model id
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
public function setColumn(int $id) : void
{
$this->column = $id;
}
public function getColumn() : int
{
return $this->column;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Set name
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
public function getStatus() : int
{
return $this->status;
}
public function setStatus(int $status) : void
{
$this->status = $status;
}
public function getType() : int
{
return $this->type;
}
public function setType(int $type) : void
{
$this->type = $type;
}
public function getRef() : int
{
return $this->ref;
}
public function setRef(int $ref) : void
{
$this->ref = $ref;
}
/**
* Get description
*
* @return string
*
* @since 1.0.0
*/
public function getDescription() : string
{
return $this->description;
}
/**
* Set description
*
* @param string $description Description
*
* @return void
*
* @since 1.0.0
*/
public function setDescription(string $description) : void
{
$this->description = $description;
}
/**
* Get created by
*
* @return int|\phpOMS\Account\Account
*
* @since 1.0.0
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Set created by
*
* @param mixed $id Created by
*
* @return void
*
* @since 1.0.0
*/
public function setCreatedBy($id) : void
{
$this->createdBy = $id;
}
/**
* Get created at date time
*
* @return \DateTime
*
* @since 1.0.0
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
public function getComments() : array
{
return $this->comments;
}
public function addComment($comment) : void
{
$this->comments[] = $comment;
}
public function removeComment(int $id) : bool
{
if (isset($this->comments[$id])) {
unset($this->comments[$id]);
return true;
}
return false;
}
public function getMedia() : array
{
return $this->media;
}
public function addMedia($media) : void
{
$this->media[] = $media;
}
public function setLabels(array $labels) : void
{
$this->labels = $labels;
}
public function getLabels() : array
{
return $this->labels;
}
public function addLabel($label) : void
{
$this->labels[] = $label;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : array
{
return [
'title' => $this->name,
'description' => $this->description,
'status' => $this->status,
'type' => $this->type,
'column' => $this->name,
'order' => $this->name,
'ref' => $this->name,
'createdBy' => $this->name,
'createdAt' => $this->name,
'labels' => $this->name,
'comments' => $this->name,
'media' => $this->name,
];
}
public static function createFromTask(Task $task) : self
{
$card = new self();
$card->setRef($task->getId());
return $card;
}
/* todo: maybe allow ref to be an object and datamapper creates that object? how does the datamapper know what kind of datamapper to use? Just assume it's called ObjectMapper? bad isn't it?! */
}