diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json new file mode 100644 index 0000000..06aad95 --- /dev/null +++ b/Admin/Install/Media.install.json @@ -0,0 +1,9 @@ +[ + { + "type": "collection", + "create_directory": true, + "name": "Knowledgebase", + "virtualPath": "/Modules", + "user": 1 + } +] \ No newline at end of file diff --git a/Admin/Install/Media.php b/Admin/Install/Media.php new file mode 100644 index 0000000..b8c70f9 --- /dev/null +++ b/Admin/Install/Media.php @@ -0,0 +1,43 @@ + __DIR__ . '/Media.install.json']); + } +} diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 566a48c..713c8df 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -135,6 +135,32 @@ } } }, + "wiki_article": { + "name": "wiki_article", + "fields": { + "wiki_article_id": { + "name": "wiki_article_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "wiki_article_src": { + "name": "wiki_article_src", + "type": "INT", + "null": false, + "foreignTable": "wiki_article", + "foreignKey": "wiki_article_id" + }, + "wiki_article_dst": { + "name": "wiki_article_dst", + "type": "INT", + "null": false, + "foreignTable": "media", + "foreignKey": "media_id" + } + } + }, "wiki_tag": { "name": "wiki_tag", "fields": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c6be863..e902964 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -110,6 +110,20 @@ final class ApiController extends Controller } } + if (!empty($uploadedFiles = $request->getFiles() ?? [])) { + $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( + [''], + $uploadedFiles, + $request->header->account, + __DIR__ . '/../../../Modules/Media/Files/Modules/Knowledgebase', + '/Modules/Knowledgebase', + ); + + foreach ($uploaded as $media) { + $doc->addMedia($media); + } + } + return $doc; } diff --git a/Docs/Dev/img/er.png b/Docs/Dev/img/er.png new file mode 100644 index 0000000..01d0941 Binary files /dev/null and b/Docs/Dev/img/er.png differ diff --git a/Models/WikiDoc.php b/Models/WikiDoc.php index 8d3d1ca..a23d114 100755 --- a/Models/WikiDoc.php +++ b/Models/WikiDoc.php @@ -100,6 +100,14 @@ class WikiDoc implements \JsonSerializable */ private array $tags = []; + /** + * Media files + * + * @var array + * @since 1.0.0 + */ + protected array $media = []; + /** * Get id. * @@ -190,6 +198,32 @@ class WikiDoc implements \JsonSerializable $this->tags[] = $tag; } + /** + * Get all media + * + * @return Media[] + * + * @since 1.0.0 + */ + public function getMedia() : array + { + return $this->media; + } + + /** + * Add media + * + * @param Media $media Media to add + * + * @return void + * + * @since 1.0.0 + */ + public function addMedia(Media $media) : void + { + $this->media[] = $media; + } + /** * {@inheritdoc} */ diff --git a/Models/WikiDocMapper.php b/Models/WikiDocMapper.php index c766a9c..ce256d0 100755 --- a/Models/WikiDocMapper.php +++ b/Models/WikiDocMapper.php @@ -18,6 +18,7 @@ use Modules\Tag\Models\TagMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\RelationType; +use Modules\Media\Models\MediaMapper; /** * Mapper class. @@ -59,6 +60,12 @@ final class WikiDocMapper extends DataMapperAbstract 'self' => 'wiki_tag_dst', 'external' => 'wiki_tag_src', ], + 'media' => [ + 'mapper' => MediaMapper::class, + 'table' => 'wiki_article_media', + 'external' => 'wiki_article_media_dst', + 'self' => 'wiki_article_media_src', + ], ]; /** diff --git a/Theme/Backend/wiki-doc-single.tpl.php b/Theme/Backend/wiki-doc-single.tpl.php index 1bc73a5..7cb4780 100755 --- a/Theme/Backend/wiki-doc-single.tpl.php +++ b/Theme/Backend/wiki-doc-single.tpl.php @@ -48,6 +48,10 @@ echo $this->getData('nav')->render(); icon !== null ? '' : ''; ?>printHtml($tag->getL11n()); ?> + + getMedia(); foreach ($files as $file) : ?> + printHtml($file->name); ?> +
diff --git a/info.json b/info.json index 292e0d7..a342ee5 100755 --- a/info.json +++ b/info.json @@ -23,7 +23,8 @@ "Tag": "1.0.0" }, "providing": { - "Navigation": "*" + "Navigation": "*", + "Media": "*" }, "load": [ {