basic tags drafted

This commit is contained in:
Dennis Eichhorn 2020-03-01 18:24:42 +01:00
parent b071eaac0d
commit 5b9ef62204
5 changed files with 54 additions and 13 deletions

View File

@ -102,5 +102,31 @@
"foreignKey": "wiki_app_id"
}
}
},
"wiki_tag": {
"name": "wiki_tag",
"fields": {
"wiki_tag_id": {
"name": "wiki_tag_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"wiki_tag_dst": {
"name": "wiki_tag_dst",
"type": "INT",
"null": false,
"foreignTable": "wiki_article",
"foreignKey": "wiki_article_id"
},
"wiki_tag_src": {
"name": "wiki_tag_src",
"type": "INT",
"null": false,
"foreignTable": "tag",
"foreignKey": "tag_id"
}
}
}
}

View File

@ -19,6 +19,7 @@ use Modules\Knowledgebase\Models\WikiCategoryMapper;
use Modules\Knowledgebase\Models\WikiDoc;
use Modules\Knowledgebase\Models\WikiDocMapper;
use Modules\Knowledgebase\Models\WikiStatus;
use Modules\Tag\Models\Tag;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
@ -84,8 +85,17 @@ final class ApiController extends Controller
$doc->setLanguage((string) ($request->getData('language') ?? $request->getHeader()->getL11n()->getLanguage()));
$doc->setStatus((int) ($request->getData('status') ?? WikiStatus::INACTIVE));
if ($request->getData('tags') !== null) {
$doc->addTag((int) $request->getData('tags'));
if (!empty($tags = $request->getDataJson('tags'))) {
foreach ($tags as $tag) {
if (!\is_numeric($tag['id'])) {
$tagObj = new Tag();
$tagObj->setTitle($tag['id']);
$tagObj->setColor($tag['color']);
$doc->addTag($tagObj);
} else {
$doc->addTag((int) $tag['id']);
}
}
}
return $doc;

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Knowledgebase\Models;
use Modules\Tag\Models\TagMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
@ -45,18 +46,17 @@ final class WikiDocMapper extends DataMapperAbstract
/**
* Has many relation.
*
* @var array<string, array<string, null|string>>
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string}>
* @since 1.0.0
*/
/*
protected static array $hasMany = [
'badges' => [
'mapper' => BadgeMapper::class,
'table' => 'wiki_article_badge',
'self' => 'wiki_article_badge_badge',
'external' => 'wiki_article_badge_article',
'tags' => [
'mapper' => TagMapper::class,
'table' => 'wiki_tag',
'self' => 'wiki_tag_src',
'external' => 'wiki_tag_dst',
],
];*/
];
/**
* Has owns one relation.

View File

@ -39,7 +39,9 @@ echo $this->getData('nav')->render(); ?>
</div>
<div class="portlet-foot">
<div class="overflowfix">
<span class="tag">Test Tag</span>
<?php $tags = $doc->getTags(); foreach ($tags as $tag) : ?>
<span class="tag" style="background: <?= $this->printHtml($tag->getColor()); ?>"><?= $this->printHtml($tag->getTitle()); ?></span>
<?php endforeach; ?>
<a href="<?= $url; ?>" class="button floatRight">More</a>
</div>
</div>

View File

@ -21,6 +21,7 @@ use Modules\Knowledgebase\Models\NullWikiDoc;
*/
$categories = $this->getData('categories') ?? [];
$doc = $this->getData('document') ?? new NullWikiDoc();
$tags = $doc->getTags();
/**
* @var \phpOMS\Views\View $this
@ -31,12 +32,14 @@ echo $this->getData('nav')->render();
<div class="row">
<div class="col-xs-12 col-md-8 col-lg-9">
<div class="portlet">
<div class="portlet-head"><a href="<?= $url; ?>"><?= $this->printHtml($doc->getName()); ?></a></div>
<div class="portlet-head"><?= $this->printHtml($doc->getName()); ?></div>
<div class="portlet-body">
<article><?= $doc->getDoc(); ?></article>
</div>
<div class="portlet-foot">
<span class="tag">FiBu v7.124.52334</span>
<?php foreach ($tags as $tag) : ?>
<span class="tag" style="background: <?= $this->printHtml($tag->getColor()); ?>"><?= $this->printHtml($tag->getTitle()); ?></span>
<?php endforeach; ?>
</div>
</div>
</div>