Improved tag module and media virtual paths

This commit is contained in:
Dennis Eichhorn 2019-05-22 07:47:03 +02:00
parent a058470e57
commit d4f3bbca02
3 changed files with 85 additions and 1 deletions

View File

@ -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,
];
}

View File

@ -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',
],
];
/**

View File

@ -20,7 +20,8 @@
"Admin": "1.0.0",
"Calendar": "1.0.0",
"Media": "1.0.0",
"Editor": "1.0.0"
"Editor": "1.0.0",
"Tag": "1.0.0"
},
"providing": {
"Navigation": "*"