mirror of
https://github.com/Karaka-Management/oms-Tasks.git
synced 2026-01-11 15:38:40 +00:00
Improved tag module and media virtual paths
This commit is contained in:
parent
a058470e57
commit
d4f3bbca02
|
|
@ -15,6 +15,8 @@ declare(strict_types=1);
|
|||
namespace Modules\Tasks\Models;
|
||||
|
||||
use Modules\Calendar\Models\Schedule;
|
||||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
||||
|
||||
/**
|
||||
|
|
@ -140,6 +142,14 @@ class Task implements \JsonSerializable
|
|||
*/
|
||||
protected $taskElements = [];
|
||||
|
||||
/**
|
||||
* Task elements.
|
||||
*
|
||||
* @var Tag[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $tags = [];
|
||||
|
||||
/**
|
||||
* Schedule
|
||||
*
|
||||
|
|
@ -266,6 +276,26 @@ class Task implements \JsonSerializable
|
|||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all media
|
||||
*
|
||||
|
|
@ -647,6 +677,52 @@ class Task implements \JsonSerializable
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task elements.
|
||||
*
|
||||
* @return Tag[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTags() : array
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task elements.
|
||||
*
|
||||
* @param int $id Element id
|
||||
*
|
||||
* @return Tag
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTag(int $id) : Tag
|
||||
{
|
||||
return $this->tags[$id] ?? new NullTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task elements.
|
||||
*
|
||||
|
|
@ -728,6 +804,7 @@ class Task implements \JsonSerializable
|
|||
'due' => $this->due->format('Y-m-d H:i:s'),
|
||||
'done' => (!isset($this->done) ? null : $this->done->format('Y-m-d H:i:s')),
|
||||
'elements' => $this->taskElements,
|
||||
'tags' => $this->tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,12 @@ final class TaskMapper extends DataMapperAbstract
|
|||
'dst' => 'task_media_src',
|
||||
'src' => 'task_media_dst',
|
||||
],
|
||||
'tags' => [
|
||||
'mapper' => MediaMapper::class,
|
||||
'table' => 'task_tag',
|
||||
'dst' => 'task_tag_src',
|
||||
'src' => 'task_tag_dst',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user