fix editor tag handling

This commit is contained in:
Dennis Eichhorn 2020-03-22 17:03:29 +01:00
parent ab57792ef5
commit 87c2e62c2b
5 changed files with 88 additions and 3 deletions

View File

@ -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"
}
}
}
}

View File

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

View File

@ -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}
*/

View File

@ -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<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @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.
*

View File

@ -12,17 +12,18 @@
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/**
* @var \phpOMS\Views\View $this
*/
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-8">
<div class="portlet">
<div class="portlet-body">
<form id="fEditor" method="PUT" action="<?= \phpOMS\Uri\UriFactory::build('{/api}editor?{?}&csrf={$CSRF}'); ?>">
<form id="fEditor" method="PUT" action="<?= UriFactory::build('{/api}editor?{?}&csrf={$CSRF}'); ?>">
<div class="ipt-wrap">
<div class="ipt-first"><input name="title" type="text" class="wf-100"></div>
<div class="ipt-second"><input type="submit" value="<?= $this->getHtml('Save') ?>"></div>
@ -45,7 +46,7 @@ echo $this->getData('nav')->render(); ?>
<div class="col-xs-12 col-md-4">
<div class="portlet">
<div class="portlet-body">
<?= $this->getData('tagSelector')->render('iTag', 'tag', false); ?>
<?= $this->getData('tagSelector')->render('iTag', 'tag', 'fEditor', false); ?>
</div>
</div>