diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 990232f..6e5a126 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -42,5 +42,31 @@ "null": false } } + }, + "editor_doc_tag": { + "name": "editor_doc_tag", + "fields": { + "editor_doc_tag_id": { + "name": "editor_doc_tag_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "editor_doc_tag_dst": { + "name": "editor_doc_tag_dst", + "type": "INT", + "null": false, + "foreignTable": "editor_doc", + "foreignKey": "editor_doc_id" + }, + "editor_doc_tag_src": { + "name": "editor_doc_tag_src", + "type": "INT", + "null": false, + "foreignTable": "tag", + "foreignKey": "tag_id" + } + } } } \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 70ec032..f735249 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -23,6 +23,7 @@ use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; use phpOMS\Utils\Parser\Markdown\Markdown; +use Modules\Tag\Models\NullTag; /** * Calendar controller class. @@ -106,6 +107,12 @@ final class ApiController extends Controller $doc->setContent(Markdown::parse((string) ($request->getData('plain') ?? ''))); $doc->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); + if (!empty($tags = $request->getDataJson('tag'))) { + foreach ($tags as $tag) { + $doc->addTag(new NullTag((int) $tag)); + } + } + return $doc; } diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index f31f582..6cf7838 100644 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -17,6 +17,7 @@ namespace Modules\Editor\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; use phpOMS\Contract\ArrayableInterface; +use Modules\Tag\Models\Tag; /** * News article class. @@ -84,6 +85,14 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable */ private Account $createdBy; + /** + * Tags. + * + * @var Tag[] + * @since 1.0.0 + */ + private array $tags = []; + /** * Constructor. * @@ -247,6 +256,32 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable $this->path = $path; } + /** + * Get tags + * + * @return array + * + * @since 1.0.0 + */ + public function getTags() : array + { + return $this->tags; + } + + /** + * Add tag + * + * @param Tag $tag Tag + * + * @return void + * + * @since 1.0.0 + */ + public function addTag(Tag $tag) : void + { + $this->tags[] = $tag; + } + /** * {@inheritdoc} */ diff --git a/Models/EditorDocMapper.php b/Models/EditorDocMapper.php index e65708e..6e578d2 100644 --- a/Models/EditorDocMapper.php +++ b/Models/EditorDocMapper.php @@ -16,6 +16,7 @@ namespace Modules\Editor\Models; use Modules\Admin\Models\AccountMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; +use Modules\Tag\Models\TagMapper; /** * Editor doc mapper class. @@ -56,6 +57,21 @@ final class EditorDocMapper extends DataMapperAbstract ], ]; + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'tags' => [ + 'mapper' => TagMapper::class, + 'table' => 'editor_doc_tag', + 'self' => 'editor_doc_tag_src', + 'external' => 'editor_doc_tag_dst', + ], + ]; + /** * Primary table. * diff --git a/Theme/Backend/editor-create.tpl.php b/Theme/Backend/editor-create.tpl.php index 8e4ebe7..75e13dd 100644 --- a/Theme/Backend/editor-create.tpl.php +++ b/Theme/Backend/editor-create.tpl.php @@ -12,17 +12,18 @@ */ declare(strict_types=1); +use phpOMS\Uri\UriFactory; + /** * @var \phpOMS\Views\View $this */ - echo $this->getData('nav')->render(); ?>
-
+
@@ -45,7 +46,7 @@ echo $this->getData('nav')->render(); ?>
- getData('tagSelector')->render('iTag', 'tag', false); ?> + getData('tagSelector')->render('iTag', 'tag', 'fEditor', false); ?>