From 5ab9ad8fd16f6c234e3f522fb6b0a2582439fe9f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 4 Apr 2021 17:10:52 +0200 Subject: [PATCH] many fixes and expands and module expansions --- Admin/Install/Media.install.json | 9 ++++ Admin/Install/Media.php | 43 +++++++++++++++++ Admin/Install/db.json | 26 ++++++++++ Controller/ApiController.php | 47 +++++++++++++++++++ Controller/BackendController.php | 1 + Models/EditorDoc.php | 35 ++++++++++++++ Models/EditorDocMapper.php | 7 +++ .../Components/Editor/inline-editor.tpl.php | 2 +- Theme/Backend/editor-list.tpl.php | 30 ++++++++++++ Theme/Backend/editor-single.tpl.php | 10 ++++ info.json | 1 + 11 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 Admin/Install/Media.install.json create mode 100644 Admin/Install/Media.php diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json new file mode 100644 index 0000000..c29dd98 --- /dev/null +++ b/Admin/Install/Media.install.json @@ -0,0 +1,9 @@ +[ + { + "type": "collection", + "create_directory": true, + "name": "Editor", + "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..3394d5b --- /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 4c7b51b..ca64b9f 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -73,5 +73,31 @@ "foreignKey": "tag_id" } } + }, + "editor_doc_media": { + "name": "editor_doc_media", + "fields": { + "editor_doc_media_id": { + "name": "editor_doc_media_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "editor_doc_media_src": { + "name": "editor_doc_media_src", + "type": "INT", + "null": false, + "foreignTable": "editor_doc", + "foreignKey": "editor_doc_id" + }, + "editor_doc_media_dst": { + "name": "editor_doc_media_dst", + "type": "INT", + "null": false, + "foreignTable": "media", + "foreignKey": "media_id" + } + } } } \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 6421175..03a8caf 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -25,6 +25,7 @@ use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; use phpOMS\Utils\Parser\Markdown\Markdown; +use Modules\Media\Models\PathSettings; /** * Calendar controller class. @@ -204,4 +205,50 @@ final class ApiController extends Controller $this->deleteModel($request->header->account, $doc, EditorDocMapper::class, 'doc', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully deleted', $doc); } + + /** + * Api method to create files + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiFileCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + $uploadedFiles = $request->getFiles() ?? []; + + if (empty($uploadedFiles)) { + $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Editor', 'Invalid file', $uploadedFiles); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( + $request->getData('name') ?? '', + $uploadedFiles, + $request->header->account, + __DIR__ . '/../../../Modules/Media/Files/Modules/Editor/' . ($request->getData('doc') ?? '0'), + '/Modules/Editor/' . ($request->getData('doc') ?? '0'), + $request->getData('type') ?? '', + '', + '', + PathSettings::FILE_PATH + ); + + $this->createModelRelation( + $request->header->account, + (int) $request->getData('doc'), + \reset($uploaded)->getId(), + EditorDocMapper::class, 'media', '', $request->getOrigin() + ); + + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'File', 'File successfully updated', $uploaded); + } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 42b3e25..9c2045c 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -109,6 +109,7 @@ final class BackendController extends Controller $view->addData('collections', $collection); $view->addData('path', $path); $view->addData('docs', $docs); + $view->addData('account', $this->app->accountManager->get($request->header->account)); return $view; } diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index 3223107..35253de 100755 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Editor\Models; use Modules\Admin\Models\Account; +use Modules\Media\Models\Media; use Modules\Admin\Models\NullAccount; use Modules\Tag\Models\Tag; use phpOMS\Contract\ArrayableInterface; @@ -101,6 +102,14 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface */ private array $tags = []; + /** + * Media files + * + * @var Media[] + * @since 1.0.0 + */ + protected array $media = []; + /** * Constructor. * @@ -176,6 +185,32 @@ class EditorDoc implements \JsonSerializable, ArrayableInterface $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/EditorDocMapper.php b/Models/EditorDocMapper.php index 98fe511..1b86168 100755 --- a/Models/EditorDocMapper.php +++ b/Models/EditorDocMapper.php @@ -18,6 +18,7 @@ use Modules\Admin\Models\AccountMapper; use Modules\Tag\Models\TagMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\RelationType; +use Modules\Media\Models\MediaMapper; /** * Editor doc mapper class. @@ -72,6 +73,12 @@ final class EditorDocMapper extends DataMapperAbstract 'self' => 'editor_doc_tag_dst', 'external' => 'editor_doc_tag_src', ], + 'media' => [ + 'mapper' => MediaMapper::class, + 'table' => 'editor_doc_media', + 'external' => 'editor_doc_media_dst', + 'self' => 'editor_doc_media_src', + ], ]; /** diff --git a/Theme/Backend/Components/Editor/inline-editor.tpl.php b/Theme/Backend/Components/Editor/inline-editor.tpl.php index 9a1fbeb..b8662cb 100755 --- a/Theme/Backend/Components/Editor/inline-editor.tpl.php +++ b/Theme/Backend/Components/Editor/inline-editor.tpl.php @@ -13,7 +13,7 @@ name="renderName(); ?>" form="renderForm(); ?>" data-tpl-text="renderTplText(); ?>" - data-tpl-value="renderTplValue(); ?>">renderPlain()); ?> + data-tpl-value="renderTplValue(); ?>">renderPlain()); ?> diff --git a/Theme/Backend/editor-list.tpl.php b/Theme/Backend/editor-list.tpl.php index f37ce98..eb2ff50 100755 --- a/Theme/Backend/editor-list.tpl.php +++ b/Theme/Backend/editor-list.tpl.php @@ -23,6 +23,9 @@ $docs = $this->getData('docs'); /** @var \Modules\Media\Models\Collection[] */ $collections = $this->getData('collections'); $mediaPath = \urldecode($this->getData('path') ?? '/'); +$account = $this->getData('account'); + +$accountDir = $account->getId() . ' ' . $account->login; $previous = empty($docs) ? '{/prefix}editor/list' : '{/prefix}editor/list?{?}&id=' . \reset($docs)->getId() . '&ptype=p'; $next = empty($docs) ? '{/prefix}editor/list' : '{/prefix}editor/list?{?}&id=' . \end($docs)->getId() . '&ptype=n'; @@ -34,17 +37,23 @@ echo $this->getData('nav')->render(); ?>
    +
  • /
  • getData('nav')->render(); ?> + + + + + +
    getHtml('Title'); ?>
    + + .. + + + + $value) : ++$count; $url = UriFactory::build('{/prefix}editor/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name); ?>
    printHtml($value->name); ?> printHtml($value->createdBy->name1); ?> @@ -113,6 +139,10 @@ echo $this->getData('nav')->render(); ?> $value) : ++$count; $url = UriFactory::build('{/prefix}editor/single?{?}&id=' . $value->getId()); ?>
    printHtml($value->title); ?> printHtml($value->createdBy->name1); ?> diff --git a/Theme/Backend/editor-single.tpl.php b/Theme/Backend/editor-single.tpl.php index 105b1b8..a17a7e6 100755 --- a/Theme/Backend/editor-single.tpl.php +++ b/Theme/Backend/editor-single.tpl.php @@ -17,6 +17,7 @@ use phpOMS\Uri\UriFactory; /** @var \Modules\Editor\Models\EditorDoc $doc */ $doc = $this->getData('doc'); +$files = $doc->getMedia(); /** @var bool $editable */ $editable = $this->getData('editable'); @@ -50,6 +51,15 @@ echo $this->getData('nav')->render(); ?> + +
    +
      + +
    • printHtml($file->name); ?> + +
    +
    + diff --git a/info.json b/info.json index 32ac2e8..31cbd05 100755 --- a/info.json +++ b/info.json @@ -18,6 +18,7 @@ "directory": "Editor", "dependencies": { "Admin": "1.0.0", + "Media": "1.0.0", "Tools": "1.0.0", "Tag": "1.0.0" },