Switch to BaseStringL11nType

This commit is contained in:
Dennis Eichhorn 2023-05-30 02:04:53 +02:00
parent a4f335dcd8
commit ed9fc61cab
7 changed files with 21 additions and 353 deletions

View File

@ -23,16 +23,16 @@ use Modules\BusinessExpenses\Models\ExpenseElementTypeL11nMapper;
use Modules\BusinessExpenses\Models\ExpenseElementTypeMapper;
use Modules\BusinessExpenses\Models\ExpenseMapper;
use Modules\BusinessExpenses\Models\ExpenseStatus;
use Modules\BusinessExpenses\Models\ExpenseType;
use Modules\BusinessExpenses\Models\ExpenseTypeL11nMapper;
use Modules\BusinessExpenses\Models\ExpenseTypeMapper;
use Modules\BusinessExpenses\Models\NullExpenseElementType;
use Modules\BusinessExpenses\Models\NullExpenseType;
use Modules\Media\Models\CollectionMapper;
use Modules\Media\Models\MediaMapper;
use Modules\Media\Models\PathSettings;
use Modules\SupplierManagement\Models\NullSupplier;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\NullBaseStringL11nType;
use phpOMS\Localization\BaseStringL11nType;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
@ -73,7 +73,7 @@ final class ApiController extends Controller
return;
}
/** @var ExpenseType $type */
/** @var BaseStringL11nType $type */
$type = $this->createExpenseTypeFromRequest($request);
$this->createModel($request->header->account, $type, ExpenseTypeMapper::class, 'expense_type', $request->getOrigin());
@ -92,14 +92,14 @@ final class ApiController extends Controller
*
* @param RequestAbstract $request Request
*
* @return ExpenseType Returns the created type from the request
* @return BaseStringL11nType Returns the created type from the request
*
* @since 1.0.0
*/
public function createExpenseTypeFromRequest(RequestAbstract $request) : ExpenseType
public function createExpenseTypeFromRequest(RequestAbstract $request) : BaseStringL11nType
{
$type = new ExpenseType();
$type->name = $request->getDataString('name') ?? '';
$type = new BaseStringL11nType();
$type->title = $request->getDataString('name') ?? '';
$type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
return $type;
@ -217,7 +217,7 @@ final class ApiController extends Controller
return;
}
/** @var ExpenseType $type */
/** @var BaseStringL11nType $type */
$type = $this->createExpenseElementTypeFromRequest($request);
$this->createModel($request->header->account, $type, ExpenseElementTypeMapper::class, 'expense_element_type', $request->getOrigin());
@ -236,13 +236,13 @@ final class ApiController extends Controller
*
* @param RequestAbstract $request Request
*
* @return ExpenseType Returns the created type from the request
* @return BaseStringL11nType Returns the created type from the request
*
* @since 1.0.0
*/
public function createExpenseElementTypeFromRequest(RequestAbstract $request) : ExpenseType
public function createExpenseElementTypeFromRequest(RequestAbstract $request) : BaseStringL11nType
{
$type = new ExpenseType();
$type = new BaseStringL11nType();
$type->name = $request->getDataString('name') ?? '';
$type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
@ -379,7 +379,7 @@ final class ApiController extends Controller
{
$expense = new Expense();
$expense->from = new NullAccount((int) $request->header->account);
$expense->type = new NullExpenseType((int) $request->getDataInt('type'));
$expense->type = new NullBaseStringL11nType((int) $request->getDataInt('type'));
$expense->status = (int) ($request->getDataInt('status') ?? ExpenseStatus::DRAFT);
$expense->description = $request->getDataString('description') ?? '';
@ -467,7 +467,7 @@ final class ApiController extends Controller
$element = new ExpenseElement();
$element->expense = (int) $request->getData('expense');
$element->description = $request->getDataString('description') ?? '';
$element->type = new NullExpenseElementType((int) $request->getData('type'));
$element->type = new NullBaseStringL11nType((int) $request->getData('type'));
// @todo: fill from media if available

View File

@ -1,121 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\BusinessExpenses\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\BusinessExpenses\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* Expense Type class.
*
* @package Modules\BusinessExpenses\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class ExpenseElementType implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
public int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
public string $name = '';
/**
* Localization
*
* @var BaseStringL11n
*/
public string | BaseStringL11n $l11n = '';
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->name = $name;
}
/**
* Set l11n
*
* @param string|BaseStringL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
}
}
/**
* @return string
*
* @since 1.0.0
*/
public function getL11n() : string
{
if (!isset($this->l11n)) {
return '';
}
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\BusinessExpenses\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11nType;
/**
* Item mapper class.
@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
* @link https://jingga.app
* @since 1.0.0
*
* @template T of ExpenseType
* @template T of BaseStringL11nType
* @extends DataMapperFactory<T>
*/
final class ExpenseElementTypeMapper extends DataMapperFactory
@ -37,7 +38,7 @@ final class ExpenseElementTypeMapper extends DataMapperFactory
*/
public const COLUMNS = [
'bizexpenses_expense_element_type_id' => ['name' => 'bizexpenses_expense_element_type_id', 'type' => 'int', 'internal' => 'id'],
'bizexpenses_expense_element_type_name' => ['name' => 'bizexpenses_expense_element_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'bizexpenses_expense_element_type_name' => ['name' => 'bizexpenses_expense_element_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
];
/**
@ -62,7 +63,7 @@ final class ExpenseElementTypeMapper extends DataMapperFactory
* @var class-string<T>
* @since 1.0.0
*/
public const MODEL = ExpenseElementType::class;
public const MODEL = BaseStringL11nType::class;
/**
* Primary table.

View File

@ -1,121 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\BusinessExpenses\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\BusinessExpenses\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* Expense Type class.
*
* @package Modules\BusinessExpenses\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class ExpenseType implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
public int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
public string $name = '';
/**
* Localization
*
* @var BaseStringL11n
*/
public string | BaseStringL11n $l11n = '';
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->name = $name;
}
/**
* Set l11n
*
* @param string|BaseStringL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
}
}
/**
* @return string
*
* @since 1.0.0
*/
public function getL11n() : string
{
if (!isset($this->l11n)) {
return '';
}
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\BusinessExpenses\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11nType;
/**
* Item mapper class.
@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
* @link https://jingga.app
* @since 1.0.0
*
* @template T of ExpenseType
* @template T of BaseStringL11nType
* @extends DataMapperFactory<T>
*/
final class ExpenseTypeMapper extends DataMapperFactory
@ -37,7 +38,7 @@ final class ExpenseTypeMapper extends DataMapperFactory
*/
public const COLUMNS = [
'bizexpenses_expense_type_id' => ['name' => 'bizexpenses_expense_type_id', 'type' => 'int', 'internal' => 'id'],
'bizexpenses_expense_type_name' => ['name' => 'bizexpenses_expense_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'bizexpenses_expense_type_name' => ['name' => 'bizexpenses_expense_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
];
/**
@ -62,7 +63,7 @@ final class ExpenseTypeMapper extends DataMapperFactory
* @var class-string<T>
* @since 1.0.0
*/
public const MODEL = ExpenseType::class;
public const MODEL = BaseStringL11nType::class;
/**
* Primary table.

View File

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

View File

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