mirror of
https://github.com/Karaka-Management/oms-Tag.git
synced 2026-01-11 07:38:41 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
e3a2997f45
commit
472b645305
|
|
@ -57,6 +57,6 @@ final class Installer extends InstallerAbstract
|
|||
private static function installDefaultColors() : void
|
||||
{
|
||||
$setting = new Setting();
|
||||
SettingMapper::create($setting->with(0, '1007500001', '#ff000000;#ff00ff00;#ffffffff', '(#[a-fA-F0-9]{8};)*(#[a-fA-F0-9]{8})', null, 'Tag'));
|
||||
SettingMapper::create()->execute($setting->with(0, '1007500001', '#ff000000;#ff00ff00;#ffffffff', '(#[a-fA-F0-9]{8};)*(#[a-fA-F0-9]{8})', null, 'Tag'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ final class ApiController extends Controller
|
|||
public function apiTagUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
/** @var Tag $old */
|
||||
$old = clone TagMapper::get((int) $request->getData('id'));
|
||||
$old = clone TagMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$new = $this->updateTagFromRequest($request);
|
||||
$this->updateModel($request->header->account, $old, $new, TagMapper::class, 'tag', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully updated', $new);
|
||||
|
|
@ -92,7 +92,7 @@ final class ApiController extends Controller
|
|||
private function updateTagFromRequest(RequestAbstract $request) : Tag
|
||||
{
|
||||
/** @var Tag $tag */
|
||||
$tag = TagMapper::get((int) $request->getData('id'));
|
||||
$tag = TagMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$tag->setL11n((string) ($request->getData('title') ?? $tag->getL11n()));
|
||||
$tag->color = \str_pad($request->getData('color') ?? $tag->color, 9, 'ff', \STR_PAD_RIGHT);
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ final class ApiController extends Controller
|
|||
public function apiTagGet(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
/** @var Tag $tag */
|
||||
$tag = TagMapper::get((int) $request->getData('id'));
|
||||
$tag = TagMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully returned', $tag);
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ final class ApiController extends Controller
|
|||
public function apiTagDelete(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
/** @var Tag $tag */
|
||||
$tag = TagMapper::get((int) $request->getData('id'));
|
||||
$tag = TagMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$this->deleteModel($request->header->account, $tag, TagMapper::class, 'tag', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully deleted', $tag);
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ final class ApiController extends Controller
|
|||
$response->set(
|
||||
$request->uri->__toString(),
|
||||
\array_values(
|
||||
TagMapper::find((string) ($request->getData('search') ?? ''), 3)
|
||||
TagMapper::getAll()->with('title')->where('title/language', $request->getLanguage())->where('title/title', '%' . ($request->getData('search') ?? '') . '%', 'LIKE')->execute()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,18 +75,15 @@ final class BackendController extends Controller
|
|||
|
||||
if ($request->getData('ptype') === 'p') {
|
||||
$view->setData('tags',
|
||||
TagMapper::with('language', $response->getLanguage())
|
||||
::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25)
|
||||
TagMapper::getAll()->with('title')->where('id', (int) ($request->getData('id') ?? 0), '<')->where('title/language', $request->getLanguage())->limit(25)->execute()
|
||||
);
|
||||
} elseif ($request->getData('ptype') === 'n') {
|
||||
$view->setData('tags',
|
||||
TagMapper::with('language', $response->getLanguage())
|
||||
::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25)
|
||||
TagMapper::getAll()->with('title')->where('id', (int) ($request->getData('id') ?? 0), '>')->where('title/language', $request->getLanguage())->limit(25)->execute()
|
||||
);
|
||||
} else {
|
||||
$view->setData('tags',
|
||||
TagMapper::with('language', $response->getLanguage())
|
||||
::getAfterPivot(0, null, 25)
|
||||
TagMapper::getAll()->with('title')->where('id', 0, '>')->where('title/language', $request->getLanguage())->limit(25)->execute()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -108,13 +105,13 @@ final class BackendController extends Controller
|
|||
public function viewTagSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request, $response);
|
||||
$tag = TagMapper::with('language', $response->getLanguage())::get((int) $request->getData('id'));
|
||||
$tag = TagMapper::get()->with('title')->where('id', (int) $request->getData('id'))->where('title/language', $response->getLanguage())->execute();
|
||||
|
||||
$view->setTemplate('/Modules/Tag/Theme/Backend/tag-single');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
|
||||
$view->addData('tag', $tag);
|
||||
|
||||
$l11n = TagL11nMapper::with('tag', $tag->getId())::getAll();
|
||||
$l11n = TagL11nMapper::getAll()->where('tag', $tag->getId())->execute();
|
||||
$view->addData('l11n', $l11n);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Tag\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Tag mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class TagL11nMapper extends DataMapperAbstract
|
||||
final class TagL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class TagL11nMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
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'],
|
||||
|
|
@ -45,7 +45,7 @@ final class TagL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'tag_l11n';
|
||||
public const TABLE = 'tag_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -53,5 +53,5 @@ final class TagL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'tag_l11n_id';
|
||||
public const PRIMARYFIELD ='tag_l11n_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Tag\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Tag mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class TagMapper extends DataMapperAbstract
|
||||
final class TagMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'],
|
||||
'tag_icon' => ['name' => 'tag_icon', 'type' => 'string', 'internal' => 'icon'],
|
||||
|
|
@ -46,13 +46,12 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'title' => [
|
||||
'mapper' => TagL11nMapper::class,
|
||||
'table' => 'tag_l11n',
|
||||
'self' => 'tag_l11n_tag',
|
||||
'column' => 'title',
|
||||
'conditional' => true,
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
|
|
@ -64,7 +63,7 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
/*
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'owner' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'tag_owner',
|
||||
|
|
@ -78,7 +77,7 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Tag::class;
|
||||
public const MODEL = Tag::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -86,7 +85,7 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'tag';
|
||||
public const TABLE = 'tag';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -94,5 +93,5 @@ final class TagMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'tag_id';
|
||||
public const PRIMARYFIELD ='tag_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$CONFIG = [
|
||||
|
|
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
|
|||
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
||||
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
$this->module->apiTagFind($request, $response);
|
||||
|
||||
// @todo: I would actually expect ApiTagEN to be returned since the server language is english.
|
||||
self::assertEquals('ApiTagDE', $response->get('')[0]->getL11n());
|
||||
self::assertEquals('ApiTagEN', $response->get('')[0]->getL11n());
|
||||
self::assertEquals(self::$tagId, $response->get('')[0]->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ final class TagL11nMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$tag->color = '#ffffffff';
|
||||
$tag->setType(TagType::SINGLE);
|
||||
|
||||
$id = TagMapper::create($tag);
|
||||
$id = TagMapper::create()->execute($tag);
|
||||
self::assertGreaterThan(0, $tag->getId());
|
||||
self::assertEquals($id, $tag->getId());
|
||||
|
||||
|
|
@ -45,11 +45,11 @@ final class TagL11nMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$l11n->setLanguage(ISO639x1Enum::_EN);
|
||||
$l11n->tag = $id;
|
||||
|
||||
$id = TagL11nMapper::create($l11n);
|
||||
$id = TagL11nMapper::create()->execute($l11n);
|
||||
self::assertGreaterThan(0, $l11n->getId());
|
||||
self::assertEquals($id, $l11n->getId());
|
||||
|
||||
$l11nR = TagL11nMapper::get($l11n->getId());
|
||||
$l11nR = TagL11nMapper::get()->where('id', $l11n->getId())->execute();
|
||||
self::assertEquals($l11n->title, $l11nR->title);
|
||||
self::assertEquals($l11n->getLanguage(), $l11nR->getLanguage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ namespace Modules\Tag\tests\Models;
|
|||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
use Modules\Tag\Models\TagType;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
|
@ -34,11 +35,11 @@ final class TagMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$tag->color = '#ff0000ff';
|
||||
$tag->setType(TagType::SINGLE);
|
||||
|
||||
$id = TagMapper::create($tag);
|
||||
$id = TagMapper::create()->execute($tag);
|
||||
self::assertGreaterThan(0, $tag->getId());
|
||||
self::assertEquals($id, $tag->getId());
|
||||
|
||||
$tagR = TagMapper::get($tag->getId());
|
||||
$tagR = TagMapper::get()->with('title')->where('id', $tag->getId())->where('title/language', ISO639x1Enum::_EN)->execute();
|
||||
self::assertEquals($tag->getL11n(), $tagR->getL11n());
|
||||
self::assertEquals($tag->color, $tagR->color);
|
||||
self::assertEquals($tag->getType(), $tagR->getType());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user