diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index d789db6..fc07128 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -10,7 +10,7 @@ "icon": null, "order": 75, "from": "Editor", - "permission": { "permission": 2, "type": null, "element": null }, + "permission": { "permission": 2, "category": null, "element": null }, "parent": 1003301001, "children": [ { @@ -24,7 +24,7 @@ "icon": null, "order": 1, "from": "Editor", - "permission": { "permission": 2, "type": null, "element": null }, + "permission": { "permission": 2, "category": null, "element": null }, "parent": 1005301001, "children": [] }, @@ -39,7 +39,7 @@ "icon": null, "order": 15, "from": "Editor", - "permission": { "permission": 4, "type": null, "element": null }, + "permission": { "permission": 4, "category": null, "element": null }, "parent": 1005301001, "children": [] } diff --git a/Admin/Installer.php b/Admin/Installer.php index 59e9361..788a12f 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -15,12 +15,8 @@ declare(strict_types=1); namespace Modules\Editor\Admin; use Modules\Editor\Models\EditorDocType; -use Modules\Editor\Models\EditorDocTypeL11n; -use Modules\Editor\Models\EditorDocTypeL11nMapper; -use Modules\Editor\Models\EditorDocTypeMapper; use phpOMS\Application\ApplicationAbstract; use phpOMS\Config\SettingsInterface; -use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Module\InstallerAbstract; @@ -105,12 +101,12 @@ final class Installer extends InstallerAbstract protected string $appName = 'Api'; }; - $apiApp->dbPool = $app->dbPool; - $apiApp->orgId = $app->orgId; + $apiApp->dbPool = $app->dbPool; + $apiApp->orgId = $app->orgId; $apiApp->accountManager = $app->accountManager; - $apiApp->appSettings = $app->appSettings; - $apiApp->moduleManager = $app->moduleManager; - $apiApp->eventManager = $app->eventManager; + $apiApp->appSettings = $app->appSettings; + $apiApp->moduleManager = $app->moduleManager; + $apiApp->eventManager = $app->eventManager; foreach ($editorData as $editor) { switch ($editor['type']) { @@ -128,7 +124,7 @@ final class Installer extends InstallerAbstract * Create type. * * @param ApplicationAbstract $app Application - * @param array $data Type info + * @param array $data Type info * * @return EditorDocType * @@ -148,7 +144,7 @@ final class Installer extends InstallerAbstract $module->apiEditorDocTypeCreate($request, $response); $type = $response->get('')['response']; - $id = $type->getId(); + $id = $type->getId(); foreach ($data['l11n'] as $l11n) { $response = new HttpResponse(); diff --git a/Controller/ApiController.php b/Controller/ApiController.php index b57a0aa..b44f42c 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -102,7 +102,7 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return EditorDoc + * @return EditorDocType * * @since 1.0.0 */ @@ -178,12 +178,12 @@ final class ApiController extends Controller */ private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : EditorDocTypeL11n { - $l11nEditorDocType = new EditorDocTypeL11n(); - $l11nEditorDocType->type = (int) ($request->getData('type') ?? 0); + $l11nEditorDocType = new EditorDocTypeL11n(); + $l11nEditorDocType->type = (int) ($request->getData('type') ?? 0); + $l11nEditorDocType->title = (string) ($request->getData('title') ?? ''); $l11nEditorDocType->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $l11nEditorDocType->title = (string) ($request->getData('title') ?? ''); return $l11nEditorDocType; } @@ -248,9 +248,19 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Document', 'Document successfully created', $doc); } + /** + * Create media files for editor document + * + * @param EditorDoc $doc Editor document + * @param RequestAbstract $request Request incl. media do upload + * + * @return void + * + * @since 1.0.0 + */ private function createDocMedia(EditorDoc $doc, RequestAbstract $request) : void { - $path = $this->createEditorDir($doc); + $path = $this->createEditorDir($doc); $account = AccountMapper::get()->where('id', $request->header->account)->execute(); if (!empty($uploadedFiles = $request->getFiles() ?? [])) { @@ -269,9 +279,9 @@ final class ApiController extends Controller MediaMapper::create()->execute($media); EditorDocMapper::writer()->createRelationTable('media', [$media->getId()], $doc->getId()); - $ref = new Reference(); - $ref->name = $media->name; - $ref->source = new NullMedia($media->getId()); + $ref = new Reference(); + $ref->name = $media->name; + $ref->source = new NullMedia($media->getId()); $ref->createdBy = new NullAccount($request->header->account); $ref->setVirtualPath($accountPath = '/Accounts/' . $account->getId() . ' ' . $account->login . '/Editor/' . $doc->createdAt->format('Y') . '/' . $doc->createdAt->format('m') . '/' . $doc->getId()); @@ -279,7 +289,6 @@ final class ApiController extends Controller if ($collection === null) { $collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection( - '/Modules/Media/Files', $accountPath, $request->header->account, __DIR__ . '/../../../Modules/Media/Files/Accounts/' . $account->getId() . '/Editor/' . $doc->createdAt->format('Y') . '/' . $doc->createdAt->format('m') . '/' . $doc->getId() @@ -296,8 +305,8 @@ final class ApiController extends Controller foreach ($mediaFiles as $media) { EditorDocMapper::writer()->createRelationTable('media', [(int) $media], $doc->getId()); - $ref = new Reference(); - $ref->source = new NullMedia((int) $media); + $ref = new Reference(); + $ref->source = new NullMedia((int) $media); $ref->createdBy = new NullAccount($request->header->account); $ref->setVirtualPath($path); @@ -305,7 +314,6 @@ final class ApiController extends Controller if ($collection === null) { $collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection( - '/Modules/Media/Files', $path, $request->header->account, __DIR__ . '/../../../Modules/Media/Files' . $path @@ -317,6 +325,15 @@ final class ApiController extends Controller } } + /** + * Create media directory path + * + * @param EditorDoc $doc Doc + * + * @return string + * + * @since 1.0.0 + */ private function createEditorDir(EditorDoc $doc) : string { return '/Modules/Editor/' @@ -337,14 +354,14 @@ final class ApiController extends Controller */ private function createDocFromRequest(RequestAbstract $request) : EditorDoc { - $doc = new EditorDoc(); - $doc->title = (string) ($request->getData('title') ?? ''); - $doc->plain = (string) ($request->getData('plain') ?? ''); - $doc->content = Markdown::parse((string) ($request->getData('plain') ?? '')); - $doc->isVersioned = (bool) ($request->getData('versioned') ?? false); + $doc = new EditorDoc(); + $doc->title = (string) ($request->getData('title') ?? ''); + $doc->plain = (string) ($request->getData('plain') ?? ''); + $doc->content = Markdown::parse((string) ($request->getData('plain') ?? '')); + $doc->isVersioned = (bool) ($request->getData('versioned') ?? false); + $doc->createdBy = new NullAccount($request->header->account); + $doc->version = (string) ($request->getData('version') ?? ''); $doc->setVirtualPath((string) ($request->getData('virtualpath') ?? '/')); - $doc->createdBy = new NullAccount($request->header->account); - $doc->version = (string) ($request->getData('version') ?? ''); if (!empty($tags = $request->getDataJson('tags'))) { foreach ($tags as $tag) { @@ -366,6 +383,15 @@ final class ApiController extends Controller return $doc; } + /** + * Create an editor history version + * + * @param EditorDoc $doc Editor document + * + * @return EditorDocHistory + * + * @since 1.0.0 + */ private function createHistory(EditorDoc $doc) : EditorDocHistory { $history = EditorDocHistory::createFromDoc($doc); @@ -417,12 +443,12 @@ final class ApiController extends Controller private function updateEditorFromRequest(RequestAbstract $request) : EditorDoc { /** @var \Modules\Editor\Models\EditorDoc $doc */ - $doc = EditorDocMapper::get()->where('id', (int) $request->getData('id'))->execute(); - $doc->isVersioned = (bool) ($request->getData('versioned') ?? $doc->isVersioned); - $doc->title = (string) ($request->getData('title') ?? $doc->title); - $doc->plain = (string) ($request->getData('plain') ?? $doc->plain); - $doc->content = Markdown::parse((string) ($request->getData('plain') ?? $doc->plain)); - $doc->version = (string) ($request->getData('version') ?? $doc->version); + $doc = EditorDocMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $doc->isVersioned = (bool) ($request->getData('versioned') ?? $doc->isVersioned); + $doc->title = (string) ($request->getData('title') ?? $doc->title); + $doc->plain = (string) ($request->getData('plain') ?? $doc->plain); + $doc->content = Markdown::parse((string) ($request->getData('plain') ?? $doc->plain)); + $doc->version = (string) ($request->getData('version') ?? $doc->version); return $doc; } diff --git a/Models/EditorDocHistory.php b/Models/EditorDocHistory.php index 4d7341a..bed41bf 100644 --- a/Models/EditorDocHistory.php +++ b/Models/EditorDocHistory.php @@ -104,15 +104,24 @@ class EditorDocHistory implements \JsonSerializable $this->createdAt = new \DateTimeImmutable('now'); } + /** + * Create history form model + * + * @param EditorDoc $doc Document + * + * @return self + * + * @since 1.0.0 + */ public static function createFromDoc(EditorDoc $doc) : self { - $hist = new self(); - $hist->doc = $doc->getId(); + $hist = new self(); + $hist->doc = $doc->getId(); $hist->createdBy = $doc->createdBy; - $hist->title = $doc->title; - $hist->plain = $doc->plain; - $hist->content = $doc->content; - $hist->version = $doc->version; + $hist->title = $doc->title; + $hist->plain = $doc->plain; + $hist->content = $doc->content; + $hist->version = $doc->version; return $hist; }