diff --git a/Admin/Installer.php b/Admin/Installer.php index 4db581f..c24f099 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -153,7 +153,7 @@ final class Installer extends InstallerAbstract $id = $type->id; $isFirst = true; - foreach ($data['l11n'] as $l11n) { + foreach ($data['l11n'] as $lang => $l11n) { if ($isFirst) { $isFirst = false; continue; @@ -163,8 +163,8 @@ final class Installer extends InstallerAbstract $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; - $request->setData('title', $l11n['title'] ?? ''); - $request->setData('lang', $l11n['lang'] ?? null); + $request->setData('title', $l11n); + $request->setData('lang', $lang); $request->setData('type', $id); $module->apiEditorDocTypeL11nCreate($request, $response); diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7c5da52..6e23685 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -21,7 +21,6 @@ use Modules\Editor\Models\EditorDoc; use Modules\Editor\Models\EditorDocHistory; use Modules\Editor\Models\EditorDocHistoryMapper; use Modules\Editor\Models\EditorDocMapper; -use Modules\Editor\Models\EditorDocType; use Modules\Editor\Models\EditorDocTypeL11nMapper; use Modules\Editor\Models\EditorDocTypeMapper; use Modules\Media\Models\CollectionMapper; @@ -32,6 +31,8 @@ use Modules\Media\Models\Reference; use Modules\Media\Models\ReferenceMapper; use Modules\Tag\Models\NullTag; use phpOMS\Localization\BaseStringL11n; +use phpOMS\Localization\BaseStringL11nType; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; @@ -105,21 +106,15 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return EditorDocType + * @return BaseStringL11nType * * @since 1.0.0 */ - private function createDocTypeFromRequest(RequestAbstract $request) : EditorDocType + private function createDocTypeFromRequest(RequestAbstract $request) : BaseStringL11nType { - $type = new EditorDocType(); - $type->name = $request->getDataString('name') ?? ''; - - if ($request->hasData('title')) { - $type->setL11n( - $request->getDataString('title') ?? '', - $request->getDataString('lang') ?? $request->header->l11n->language - ); - } + $type = new BaseStringL11nType(); + $type->title = $request->getDataString('name') ?? ''; + $type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); return $type; } @@ -184,14 +179,14 @@ final class ApiController extends Controller */ private function createEditorDocTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $l11nEditorDocType = new BaseStringL11n(); - $l11nEditorDocType->ref = $request->getDataInt('type') ?? 0; - $l11nEditorDocType->content = $request->getDataString('title') ?? ''; - $l11nEditorDocType->setLanguage( + $typeL11n = new BaseStringL11n(); + $typeL11n->ref = $request->getDataInt('type') ?? 0; + $typeL11n->setLanguage( $request->getDataString('language') ?? $request->header->l11n->language ); + $typeL11n->content = $request->getDataString('title') ?? ''; - return $l11nEditorDocType; + return $typeL11n; } /** diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index b2d79a6..ec17961 100755 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -18,6 +18,7 @@ use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; use Modules\Media\Models\Media; use Modules\Tag\Models\Tag; +use phpOMS\Localization\BaseStringL11nType; /** * News article class. @@ -75,7 +76,7 @@ class EditorDoc implements \JsonSerializable * @var null|EditorDocType * @since 1.0.0 */ - public ?EditorDocType $type = null; + public ?BaseStringL11nType $type = null; /** * Doc path for organizing. diff --git a/Models/EditorDocType.php b/Models/EditorDocType.php deleted file mode 100755 index 7626cf8..0000000 --- a/Models/EditorDocType.php +++ /dev/null @@ -1,120 +0,0 @@ -setL11n($name); - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; - } - - /** - * Set title - * - * @param string|BaseStringL11n $title EditorDoc article title - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void - { - if ($title instanceof BaseStringL11n) { - $this->title = $title; - } elseif ($this->title instanceof BaseStringL11n) { - $this->title->content = $title; - } else { - $this->title = new BaseStringL11n(); - $this->title->content = $title; - $this->title->setLanguage($lang); - } - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'title' => $this->title, - 'name' => $this->name, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/EditorDocTypeMapper.php b/Models/EditorDocTypeMapper.php index 36d5b44..cd0d816 100755 --- a/Models/EditorDocTypeMapper.php +++ b/Models/EditorDocTypeMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Editor\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11nType; /** * Editor type mapper class. @@ -23,6 +24,9 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 + * + * @template T of BaseStringL11nType + * @extends DataMapperFactory */ final class EditorDocTypeMapper extends DataMapperFactory { @@ -34,7 +38,7 @@ final class EditorDocTypeMapper extends DataMapperFactory */ public const COLUMNS = [ 'editor_doc_type_id' => ['name' => 'editor_doc_type_id', 'type' => 'int', 'internal' => 'id'], - 'editor_doc_type_name' => ['name' => 'editor_doc_type_name', 'type' => 'string', 'internal' => 'name'], + 'editor_doc_type_name' => ['name' => 'editor_doc_type_name', 'type' => 'string', 'internal' => 'title'], ]; /** @@ -44,12 +48,11 @@ final class EditorDocTypeMapper extends DataMapperFactory * @since 1.0.0 */ public const HAS_MANY = [ - 'title' => [ + 'l11n' => [ 'mapper' => EditorDocTypeL11nMapper::class, 'table' => 'editor_doc_type_l11n', 'self' => 'editor_doc_type_l11n_type', - 'column' => 'title', - 'conditional' => true, + 'column' => 'content', 'external' => null, ], ]; @@ -60,7 +63,7 @@ final class EditorDocTypeMapper extends DataMapperFactory * @var class-string * @since 1.0.0 */ - public const MODEL = EditorDocType::class; + public const MODEL = BaseStringL11nType::class; /** * Primary table. diff --git a/Models/NullEditorDocType.php b/Models/NullEditorDocType.php deleted file mode 100755 index 23d9756..0000000 --- a/Models/NullEditorDocType.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index b5d36a8..4d624b6 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -302,7 +302,7 @@ if (\defined('RESET') && RESET === '1') { $db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']); $db->exec('CREATE DATABASE IF NOT EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']); $db = null; - } catch (\Throwable $t) { + } catch (\Throwable $_) { echo "\nCouldn't connect to MYSQL DB\n"; } } @@ -317,7 +317,7 @@ if (\defined('RESET') && RESET === '1') { $db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['postgresql']['admin']['database']); $db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['postgresql']['admin']['database']); $db = null; - } catch (\Throwable $t) { + } catch (\Throwable $_) { echo "\nCouldn't connect to POSTGRESQL DB\n"; } } @@ -332,7 +332,7 @@ if (\defined('RESET') && RESET === '1') { $db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['mssql']['admin']['database']); $db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['mssql']['admin']['database']); $db = null; - } catch (\Throwable $t) { + } catch (\Throwable $_) { echo "\nCouldn't connect to MSSQL DB\n"; } }