l11n, unit/app and simplification fixes

This commit is contained in:
Dennis Eichhorn 2023-01-07 19:00:32 +01:00
parent fe0637a623
commit 7a68ee6e09
6 changed files with 27 additions and 197 deletions

View File

@ -21,7 +21,7 @@ use Modules\Editor\Models\EditorDocHistory;
use Modules\Editor\Models\EditorDocHistoryMapper; use Modules\Editor\Models\EditorDocHistoryMapper;
use Modules\Editor\Models\EditorDocMapper; use Modules\Editor\Models\EditorDocMapper;
use Modules\Editor\Models\EditorDocType; use Modules\Editor\Models\EditorDocType;
use Modules\Editor\Models\EditorDocTypeL11n; use phpOMS\Localization\BaseStringL11n;
use Modules\Editor\Models\EditorDocTypeL11nMapper; use Modules\Editor\Models\EditorDocTypeL11nMapper;
use Modules\Editor\Models\EditorDocTypeMapper; use Modules\Editor\Models\EditorDocTypeMapper;
use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\CollectionMapper;
@ -172,15 +172,15 @@ final class ApiController extends Controller
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return EditorDocTypeL11n * @return BaseStringL11n
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : EditorDocTypeL11n private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{ {
$l11nEditorDocType = new EditorDocTypeL11n(); $l11nEditorDocType = new BaseStringL11n();
$l11nEditorDocType->type = (int) ($request->getData('type') ?? 0); $l11nEditorDocType->ref = (int) ($request->getData('type') ?? 0);
$l11nEditorDocType->title = (string) ($request->getData('title') ?? ''); $l11nEditorDocType->content = (string) ($request->getData('title') ?? '');
$l11nEditorDocType->setLanguage((string) ( $l11nEditorDocType->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage() $request->getData('language') ?? $request->getLanguage()
)); ));

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Editor\Models; namespace Modules\Editor\Models;
use phpOMS\Localization\ISO639x1Enum; use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Localization\BaseStringL11n;
/** /**
* EditorDoc type class. * EditorDoc type class.
@ -47,7 +48,7 @@ class EditorDocType implements \JsonSerializable
/** /**
* Title. * Title.
* *
* @var string|EditorDocTypeL11n * @var string|BaseStringL11n
* @since 1.0.0 * @since 1.0.0
*/ */
protected $title = ''; protected $title = '';
@ -83,28 +84,28 @@ class EditorDocType implements \JsonSerializable
*/ */
public function getL11n() : string 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 * Set title
* *
* @param string|EditorDocTypeL11n $title EditorDoc article title * @param string|BaseStringL11n $title EditorDoc article title
* @param string $lang Language * @param string $lang Language
* *
* @return void * @return void
* *
* @since 1.0.0 * @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; $this->title = $title;
} elseif ($this->title instanceof EditorDocTypeL11n) { } elseif ($this->title instanceof BaseStringL11n) {
$this->title->title = $title; $this->title->content = $title;
} else { } else {
$this->title = new EditorDocTypeL11n(); $this->title = new BaseStringL11n();
$this->title->title = $title; $this->title->content = $title;
$this->title->setLanguage($lang); $this->title->setLanguage($lang);
} }
} }

View File

@ -1,132 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
use phpOMS\Localization\ISO639x1Enum;
/**
* Editor type l11n class.
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class EditorDocTypeL11n implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Type ID.
*
* @var int
* @since 1.0.0
*/
public int $type = 0;
/**
* Language.
*
* @var string
* @since 1.0.0
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
public string $title = '';
/**
* Constructor.
*
* @param string $title Title
*
* @since 1.0.0
*/
public function __construct(string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->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();
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Editor\Models; namespace Modules\Editor\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/** /**
* Editor type l11n mapper class. * Editor type l11n mapper class.
@ -34,8 +35,8 @@ final class EditorDocTypeL11nMapper extends DataMapperFactory
*/ */
public const COLUMNS = [ public const COLUMNS = [
'editor_doc_type_l11n_id' => ['name' => 'editor_doc_type_l11n_id', 'type' => 'int', 'internal' => 'id'], '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_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' => 'type'], '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'], '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 * @since 1.0.0
*/ */
public const PRIMARYFIELD ='editor_doc_type_l11n_id'; 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;
} }

View File

@ -1,47 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Editor\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Editor\Models;
/**
* Null model
*
* @package Modules\Editor\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullEditorDocTypeL11n extends EditorDocTypeL11n
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -18,7 +18,6 @@
"directory": "Editor", "directory": "Editor",
"dependencies": { "dependencies": {
"Admin": "1.0.0", "Admin": "1.0.0",
"Media": "1.0.0",
"Tools": "1.0.0", "Tools": "1.0.0",
"Tag": "1.0.0" "Tag": "1.0.0"
}, },