From 7a68ee6e090c44b56da0fe204141face48aab3ad Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 7 Jan 2023 19:00:32 +0100 Subject: [PATCH] l11n, unit/app and simplification fixes --- Controller/ApiController.php | 12 +-- Models/EditorDocType.php | 19 +++-- Models/EditorDocTypeL11n.php | 132 ----------------------------- Models/EditorDocTypeL11nMapper.php | 13 ++- Models/NullEditorDocTypeL11n.php | 47 ---------- info.json | 1 - 6 files changed, 27 insertions(+), 197 deletions(-) delete mode 100755 Models/EditorDocTypeL11n.php delete mode 100755 Models/NullEditorDocTypeL11n.php diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7b1ce9a..0cd0013 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -21,7 +21,7 @@ use Modules\Editor\Models\EditorDocHistory; use Modules\Editor\Models\EditorDocHistoryMapper; use Modules\Editor\Models\EditorDocMapper; use Modules\Editor\Models\EditorDocType; -use Modules\Editor\Models\EditorDocTypeL11n; +use phpOMS\Localization\BaseStringL11n; use Modules\Editor\Models\EditorDocTypeL11nMapper; use Modules\Editor\Models\EditorDocTypeMapper; use Modules\Media\Models\CollectionMapper; @@ -172,15 +172,15 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return EditorDocTypeL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : EditorDocTypeL11n + private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $l11nEditorDocType = new EditorDocTypeL11n(); - $l11nEditorDocType->type = (int) ($request->getData('type') ?? 0); - $l11nEditorDocType->title = (string) ($request->getData('title') ?? ''); + $l11nEditorDocType = new BaseStringL11n(); + $l11nEditorDocType->ref = (int) ($request->getData('type') ?? 0); + $l11nEditorDocType->content = (string) ($request->getData('title') ?? ''); $l11nEditorDocType->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); diff --git a/Models/EditorDocType.php b/Models/EditorDocType.php index dd075ee..b6225b3 100755 --- a/Models/EditorDocType.php +++ b/Models/EditorDocType.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Editor\Models; use phpOMS\Localization\ISO639x1Enum; +use phpOMS\Localization\BaseStringL11n; /** * EditorDoc type class. @@ -47,7 +48,7 @@ class EditorDocType implements \JsonSerializable /** * Title. * - * @var string|EditorDocTypeL11n + * @var string|BaseStringL11n * @since 1.0.0 */ protected $title = ''; @@ -83,28 +84,28 @@ class EditorDocType implements \JsonSerializable */ public function getL11n() : string { - return $this->title instanceof EditorDocTypeL11n ? $this->title->title : $this->title; + return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; } /** * Set title * - * @param string|EditorDocTypeL11n $title EditorDoc article title + * @param string|BaseStringL11n $title EditorDoc article title * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setL11n(string | EditorDocTypeL11n $title, string $lang = ISO639x1Enum::_EN) : void + public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void { - if ($title instanceof EditorDocTypeL11n) { + if ($title instanceof BaseStringL11n) { $this->title = $title; - } elseif ($this->title instanceof EditorDocTypeL11n) { - $this->title->title = $title; + } elseif ($this->title instanceof BaseStringL11n) { + $this->title->content = $title; } else { - $this->title = new EditorDocTypeL11n(); - $this->title->title = $title; + $this->title = new BaseStringL11n(); + $this->title->content = $title; $this->title->setLanguage($lang); } } diff --git a/Models/EditorDocTypeL11n.php b/Models/EditorDocTypeL11n.php deleted file mode 100755 index b59d695..0000000 --- a/Models/EditorDocTypeL11n.php +++ /dev/null @@ -1,132 +0,0 @@ -title = $title; - $this->language = $language; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * Get language - * - * @return string - * - * @since 1.0.0 - */ - public function getLanguage() : string - { - return $this->language; - } - - /** - * Set language - * - * @param string $language Language - * - * @return void - * - * @since 1.0.0 - */ - public function setLanguage(string $language) : void - { - $this->language = $language; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'title' => $this->title, - 'type' => $this->type, - 'language' => $this->language, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/EditorDocTypeL11nMapper.php b/Models/EditorDocTypeL11nMapper.php index dbe08c4..201ba9c 100755 --- a/Models/EditorDocTypeL11nMapper.php +++ b/Models/EditorDocTypeL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Editor\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Editor type l11n mapper class. @@ -34,8 +35,8 @@ final class EditorDocTypeL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'editor_doc_type_l11n_id' => ['name' => 'editor_doc_type_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'editor_doc_type_l11n_title' => ['name' => 'editor_doc_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'editor_doc_type_l11n_type' => ['name' => 'editor_doc_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + 'editor_doc_type_l11n_title' => ['name' => 'editor_doc_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'editor_doc_type_l11n_type' => ['name' => 'editor_doc_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], 'editor_doc_type_l11n_language' => ['name' => 'editor_doc_type_l11n_language', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class EditorDocTypeL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='editor_doc_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/NullEditorDocTypeL11n.php b/Models/NullEditorDocTypeL11n.php deleted file mode 100755 index d66f09e..0000000 --- a/Models/NullEditorDocTypeL11n.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/info.json b/info.json index 9a9d36a..98e6b34 100755 --- a/info.json +++ b/info.json @@ -18,7 +18,6 @@ "directory": "Editor", "dependencies": { "Admin": "1.0.0", - "Media": "1.0.0", "Tools": "1.0.0", "Tag": "1.0.0" },