diff --git a/Controller/ApiController.php b/Controller/ApiController.php index dd4577b..c9656b1 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Tag\Controller; use Modules\Tag\Models\Tag; -use Modules\Tag\Models\TagL11n; +use phpOMS\Localization\BaseStringL11n; use Modules\Tag\Models\TagL11nMapper; use Modules\Tag\Models\TagMapper; use phpOMS\Message\Http\RequestStatusCode; @@ -201,18 +201,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return TagL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createTagL11nFromRequest(RequestAbstract $request) : TagL11n + private function createTagL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $tagL11n = new TagL11n(); - $tagL11n->tag = (int) ($request->getData('tag') ?? 0); + $tagL11n = new BaseStringL11n(); + $tagL11n->ref = (int) ($request->getData('tag') ?? 0); $tagL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $tagL11n->title = (string) ($request->getData('title') ?? ''); + $tagL11n->content = (string) ($request->getData('title') ?? ''); return $tagL11n; } @@ -277,7 +277,7 @@ final class ApiController extends Controller $tags = TagMapper::getAll() ->with('title') ->where('title/language', $request->getLanguage()) - ->where('title/title', '%' . ($request->getData('search') ?? '') . '%', 'LIKE') + ->where('title/content', '%' . ($request->getData('search') ?? '') . '%', 'LIKE') ->execute(); $response->header->set('Content-Type', MimeType::M_JSON, true); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 10fd107..4dc91b2 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -113,7 +113,7 @@ final class BackendController extends Controller $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response)); $view->addData('tag', $tag); - /** @var \Modules\Tag\Models\TagL11n[] $l11n */ + /** @var \phpOMS\Localization\BaseStringL11n[] $l11n */ $l11n = TagL11nMapper::getAll()->where('tag', $tag->getId())->execute(); $view->addData('l11n', $l11n); diff --git a/Models/NullTagL11n.php b/Models/NullTagL11n.php deleted file mode 100755 index 639e16b..0000000 --- a/Models/NullTagL11n.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Tag.php b/Models/Tag.php index f4ada61..3b7a109 100755 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -16,6 +16,7 @@ namespace Modules\Tag\Models; use Modules\Admin\Models\Account; use phpOMS\Localization\ISO639x1Enum; +use phpOMS\Localization\BaseStringL11n; /** * Tag class. @@ -38,10 +39,10 @@ class Tag implements \JsonSerializable /** * Title. * - * @var string|TagL11n + * @var string|BaseStringL11n * @since 1.0.0 */ - protected string | TagL11n $title = ''; + protected string | BaseStringL11n $title = ''; /** * Color RGBA. @@ -120,28 +121,28 @@ class Tag implements \JsonSerializable */ public function getL11n() : string { - return $this->title instanceof TagL11n ? $this->title->title : $this->title; + return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; } /** * Set title * - * @param string|TagL11n $title Tag article title - * @param string $lang Language + * @param string|BaseStringL11n $title Tag article title + * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setL11n(string | TagL11n $title, string $lang = ISO639x1Enum::_EN) : void + public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void { - if ($title instanceof TagL11n) { + if ($title instanceof BaseStringL11n) { $this->title = $title; - } elseif (isset($this->title) && $this->title instanceof TagL11n) { - $this->title->title = $title; + } elseif (isset($this->title) && $this->title instanceof BaseStringL11n) { + $this->title->content = $title; } else { - $this->title = new TagL11n(); - $this->title->title = $title; + $this->title = new BaseStringL11n(); + $this->title->content = $title; $this->title->setLanguage($lang); } } diff --git a/Models/TagL11n.php b/Models/TagL11n.php deleted file mode 100755 index 1e82ef5..0000000 --- a/Models/TagL11n.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, - 'tag' => $this->tag, - 'language' => $this->language, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TagL11nMapper.php b/Models/TagL11nMapper.php index 14cebf3..32bbc1b 100755 --- a/Models/TagL11nMapper.php +++ b/Models/TagL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Tag\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Tag mapper class. @@ -34,8 +35,8 @@ final class TagL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'tag_l11n_id' => ['name' => 'tag_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'tag_l11n_title' => ['name' => 'tag_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'tag_l11n_tag' => ['name' => 'tag_l11n_tag', 'type' => 'int', 'internal' => 'tag'], + 'tag_l11n_title' => ['name' => 'tag_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'tag_l11n_tag' => ['name' => 'tag_l11n_tag', 'type' => 'int', 'internal' => 'ref'], 'tag_l11n_language' => ['name' => 'tag_l11n_language', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class TagL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='tag_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/TagMapper.php b/Models/TagMapper.php index 08778f4..2d6e535 100755 --- a/Models/TagMapper.php +++ b/Models/TagMapper.php @@ -51,7 +51,7 @@ final class TagMapper extends DataMapperFactory 'mapper' => TagL11nMapper::class, 'table' => 'tag_l11n', 'self' => 'tag_l11n_tag', - 'column' => 'title', + 'column' => 'content', 'external' => null, ], ]; diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 458ad0b..04b44b1 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -143,7 +143,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $this->module->apiTagL11nCreate($request, $response); - self::assertEquals('ApiTagDE', $response->get('')['response']->title); + self::assertEquals('ApiTagDE', $response->get('')['response']->content); self::assertGreaterThan(0, $response->get('')['response']->getId()); } diff --git a/tests/Models/NullTagL11nTest.php b/tests/Models/NullTagL11nTest.php deleted file mode 100755 index 5bfba87..0000000 --- a/tests/Models/NullTagL11nTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/TagL11nMapperTest.php b/tests/Models/TagL11nMapperTest.php index b67df53..1b66940 100755 --- a/tests/Models/TagL11nMapperTest.php +++ b/tests/Models/TagL11nMapperTest.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Tag\tests\Models; use Modules\Tag\Models\Tag; -use Modules\Tag\Models\TagL11n; +use phpOMS\Localization\BaseStringL11n; use Modules\Tag\Models\TagL11nMapper; use Modules\Tag\Models\TagMapper; use Modules\Tag\Models\TagType; @@ -40,17 +40,17 @@ final class TagL11nMapperTest extends \PHPUnit\Framework\TestCase self::assertGreaterThan(0, $tag->getId()); self::assertEquals($id, $tag->getId()); - $l11n = new TagL11n(); - $l11n->title = 'TestTitle'; + $l11n = new BaseStringL11n(); + $l11n->content = 'TestTitle'; $l11n->setLanguage(ISO639x1Enum::_EN); - $l11n->tag = $id; + $l11n->ref = $id; $id = TagL11nMapper::create()->execute($l11n); self::assertGreaterThan(0, $l11n->getId()); self::assertEquals($id, $l11n->getId()); $l11nR = TagL11nMapper::get()->where('id', $l11n->getId())->execute(); - self::assertEquals($l11n->title, $l11nR->title); + self::assertEquals($l11n->content, $l11nR->content); self::assertEquals($l11n->getLanguage(), $l11nR->getLanguage()); } } diff --git a/tests/Models/TagL11nTest.php b/tests/Models/TagL11nTest.php deleted file mode 100755 index 575596e..0000000 --- a/tests/Models/TagL11nTest.php +++ /dev/null @@ -1,97 +0,0 @@ -l11n = new TagL11n(); - } - - /** - * @covers Modules\Tag\Models\TagL11n - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->l11n->getId()); - self::assertEquals(0, $this->l11n->tag); - self::assertEquals('', $this->l11n->title); - self::assertEquals(ISO639x1Enum::_EN, $this->l11n->getLanguage()); - } - - /** - * @covers Modules\Tag\Models\TagL11n - * @group module - */ - public function testTagInputOutput() : void - { - $this->l11n->tag = 2; - self::assertEquals(2, $this->l11n->tag); - } - - /** - * @covers Modules\Tag\Models\TagL11n - * @group module - */ - public function testLanguageInputOutput() : void - { - $this->l11n->setLanguage(ISO639x1Enum::_DE); - self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage()); - } - - /** - * @covers Modules\Tag\Models\TagL11n - * @group module - */ - public function testTitleInputOutput() : void - { - $this->l11n->title = 'Title'; - self::assertEquals('Title', $this->l11n->title); - } - - /** - * @covers Modules\Tag\Models\TagL11n - * @group module - */ - public function testSerialize() : void - { - $this->l11n->title = 'Title'; - $this->l11n->tag = 2; - $this->l11n->setLanguage(ISO639x1Enum::_DE); - - self::assertEquals( - [ - 'id' => 0, - 'title' => 'Title', - 'tag' => 2, - 'language' => ISO639x1Enum::_DE, - ], - $this->l11n->jsonSerialize() - ); - } -} diff --git a/tests/Models/TagTest.php b/tests/Models/TagTest.php index 2841454..5ca2676 100755 --- a/tests/Models/TagTest.php +++ b/tests/Models/TagTest.php @@ -16,7 +16,7 @@ namespace Modules\Tag\tests\Models; use Modules\Admin\Models\NullAccount; use Modules\Tag\Models\Tag; -use Modules\Tag\Models\TagL11n; +use phpOMS\Localization\BaseStringL11n; use Modules\Tag\Models\TagType; /** @@ -56,7 +56,7 @@ final class TagTest extends \PHPUnit\Framework\TestCase $this->tag->setL11n('Test'); self::assertEquals('Test', $this->tag->getL11n()); - $this->tag->setL11n(new TagL11n('Test2')); + $this->tag->setL11n(new BaseStringL11n('Test2')); self::assertEquals('Test2', $this->tag->getL11n()); $this->tag->setL11n('Test3'); @@ -99,7 +99,7 @@ final class TagTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->tag->setL11n($t = new TagL11n('Test')); + $this->tag->setL11n($t = new BaseStringL11n('Test')); $this->tag->owner = new NullAccount(2); $this->tag->color = 'ffffffff'; $this->tag->setType(TagType::SHARED);