l11n, unit/app and simplification fixes

This commit is contained in:
Dennis Eichhorn 2023-01-07 19:00:32 +01:00
parent d7b3c36ebf
commit 09f3ba7c68
20 changed files with 386 additions and 519 deletions

View File

@ -5,5 +5,19 @@
"name": "ClientManagement",
"virtualPath": "/Modules",
"user": 1
},
{
"type": "type",
"name": "client_profile_image",
"l11n": [
{
"title": "Profile image",
"lang": "en"
},
{
"title": "Profilbild",
"lang": "de"
}
]
}
]

View File

@ -54,6 +54,14 @@
"default": null,
"foreignTable": "address",
"foreignKey": "address_id"
},
"clientmgmt_client_unit": {
"name": "clientmgmt_client_unit",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "organization_unit",
"foreignKey": "organization_unit_id"
}
}
},
@ -96,6 +104,12 @@
"clientmgmt_attr_type_name": {
"name": "clientmgmt_attr_type_name",
"type": "VARCHAR(255)",
"null": false,
"unique": true
},
"clientmgmt_attr_type_datatype": {
"name": "clientmgmt_attr_type_datatype",
"type": "INT(11)",
"null": false
},
"clientmgmt_attr_type_fields": {
@ -168,11 +182,6 @@
"type": "TINYINT(1)",
"null": false
},
"clientmgmt_attr_value_type": {
"name": "clientmgmt_attr_value_type",
"type": "INT(11)",
"null": false
},
"clientmgmt_attr_value_valueStr": {
"name": "clientmgmt_attr_value_valueStr",
"type": "VARCHAR(255)",
@ -196,22 +205,37 @@
"type": "DATETIME",
"null": true,
"default": null
}
}
},
"clientmgmt_attr_value_l11n": {
"name": "clientmgmt_attr_value_l11n",
"fields": {
"clientmgmt_attr_value_l11n_id": {
"name": "clientmgmt_attr_value_l11n_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"clientmgmt_attr_value_lang": {
"name": "clientmgmt_attr_value_lang",
"clientmgmt_attr_value_l11n_title": {
"name": "clientmgmt_attr_value_l11n_title",
"type": "VARCHAR(255)",
"null": false
},
"clientmgmt_attr_value_l11n_value": {
"name": "clientmgmt_attr_value_l11n_value",
"type": "INT(11)",
"null": false,
"foreignTable": "clientmgmt_attr_value",
"foreignKey": "clientmgmt_attr_value_id"
},
"clientmgmt_attr_value_l11n_lang": {
"name": "clientmgmt_attr_value_l11n_lang",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"null": false,
"foreignTable": "language",
"foreignKey": "language_639_1"
},
"clientmgmt_attr_value_country": {
"name": "clientmgmt_attr_value_country",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"foreignTable": "country",
"foreignKey": "country_code2"
}
}
},

View File

@ -16,12 +16,11 @@ namespace Modules\ClientManagement\Controller;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\Address;
use Modules\ClientManagement\Models\AttributeValueType;
use Modules\ClientManagement\Models\Client;
use Modules\ClientManagement\Models\ClientAttribute;
use Modules\ClientManagement\Models\ClientAttributeMapper;
use Modules\ClientManagement\Models\ClientAttributeType;
use Modules\ClientManagement\Models\ClientAttributeTypeL11n;
use phpOMS\Localization\BaseStringL11n;
use Modules\ClientManagement\Models\ClientAttributeTypeL11nMapper;
use Modules\ClientManagement\Models\ClientAttributeTypeMapper;
use Modules\ClientManagement\Models\ClientAttributeValue;
@ -105,6 +104,8 @@ final class ApiController extends Controller
$addr->state = (string) ($request->getData('state') ?? '');
$client->mainAddress = $addr;
$client->unit = $request->getData('unit', 'int');
return $client;
}
@ -265,18 +266,18 @@ final class ApiController extends Controller
*
* @param RequestAbstract $request Request
*
* @return ClientAttributeTypeL11n
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createClientAttributeTypeL11nFromRequest(RequestAbstract $request) : ClientAttributeTypeL11n
private function createClientAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new ClientAttributeTypeL11n();
$attrL11n->type = (int) ($request->getData('type') ?? 0);
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
$attrL11n->title = (string) ($request->getData('title') ?? '');
$attrL11n->content = (string) ($request->getData('title') ?? '');
return $attrL11n;
}
@ -341,10 +342,13 @@ final class ApiController extends Controller
*/
private function createClientAttributeTypeFromRequest(RequestAbstract $request) : ClientAttributeType
{
$attrType = new ClientAttributeType();
$attrType = new ClientAttributeType($request->getData('name') ?? '');
$attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN);
$attrType->fields = (int) ($request->getData('fields') ?? 0);
$attrType->custom = (bool) ($request->getData('custom') ?? false);
$attrType->datatype = (int) ($request->getData('datatype') ?? 0);
$attrType->setFields((int) ($request->getData('fields') ?? 0));
$attrType->custom = (bool) ($request->getData('custom') ?? false);
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
$attrType->validationPattern = (string) ($request->getData('validation_pattern') ?? '');
return $attrType;
}
@ -361,7 +365,9 @@ final class ApiController extends Controller
private function validateClientAttributeTypeCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))) {
if (($val['title'] = empty($request->getData('title')))
|| ($val['name'] = empty($request->getData('name')))
) {
return $val;
}
@ -396,7 +402,7 @@ final class ApiController extends Controller
if ($attrValue->isDefault) {
$this->createModelRelation(
$request->header->account,
(int) $request->getData('attributetype'),
(int) $request->getData('type'),
$attrValue->getId(),
ClientAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
);
@ -416,28 +422,16 @@ final class ApiController extends Controller
*/
private function createClientAttributeValueFromRequest(RequestAbstract $request) : ClientAttributeValue
{
$type = ClientAttributeTypeMapper::get()
->where('id', (int) ($request->getData('type') ?? 0))
->execute();
$attrValue = new ClientAttributeValue();
$type = (int) ($request->getData('type') ?? 0);
if ($type === AttributeValueType::_INT) {
$attrValue->valueInt = $request->hasData('value') ? (int) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_STRING) {
$attrValue->valueStr = $request->hasData('value') ? (string) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_FLOAT) {
$attrValue->valueDec = $request->hasData('value') ? (float) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_DATETIME) {
$attrValue->valueDat = $request->hasData('value') ? new \DateTime((string) ($request->getData('value') ?? '')) : null;
}
$attrValue->type = $type;
$attrValue->isDefault = (bool) ($request->getData('default') ?? false);
$attrValue->setValue($request->getData('value'), $type->datatype);
if ($request->hasData('language')) {
$attrValue->setLanguage((string) ($request->getData('language') ?? $request->getLanguage()));
}
if ($request->hasData('country')) {
$attrValue->setCountry((string) ($request->getData('country') ?? $request->header->l11n->getCountry()));
if ($request->getData('title') !== null) {
$attrValue->setL11n($request->getData('title'), $request->getData('language') ?? ISO639x1Enum::_EN);
}
return $attrValue;
@ -464,6 +458,75 @@ final class ApiController extends Controller
return [];
}
/**
* Api method to create client attribute l11n
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiClientAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateClientAttributeValueL11nCreate($request))) {
$response->set('attr_value_l11n_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrL11n = $this->createClientAttributeValueL11nFromRequest($request);
$this->createModel($request->header->account, $attrL11n, ClientAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type localization', 'Attribute type localization successfully created', $attrL11n);
}
/**
* Method to create Client attribute l11n from request.
*
* @param RequestAbstract $request Request
*
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createClientAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
$attrL11n->content = (string) ($request->getData('title') ?? '');
return $attrL11n;
}
/**
* Validate Client attribute l11n create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateClientAttributeValueL11nCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['value'] = empty($request->getData('value')))
) {
return $val;
}
return [];
}
/**
* Api method to create client files
*

View File

@ -60,9 +60,12 @@ final class BackendController extends Controller
$client = ClientMapper::getAll()
->with('profile')
->with('profile/account')
->with('profile/image')
->with('files')
->with('files/type')
->with('mainAddress')
->where('files/type/name', 'client_profile_image')
->limit(25)
->limit(1, 'files/type')
->execute();
$view->addData('client', $client);

View File

@ -84,6 +84,14 @@ class Client
public ?Address $defaultInvoiceAddress = null;
/**
* Unit
*
* @var null|int
* @since 1.0.0
*/
public ?int $unit = null;
/**
* Constructor.
*
@ -380,6 +388,26 @@ class Client
return new NullMedia();
}
/**
* Get all media files by type name
*
* @param string $type Media type
*
* @return Media
*
* @since 1.0.0
*/
public function getFileByTypeName(string $type) : Media
{
foreach ($this->files as $file) {
if ($file->type->name === $type) {
return $file;
}
}
return new NullMedia();
}
/**
* {@inheritdoc}
*/

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Localization\BaseStringL11n;
/**
* Client Attribute Type class.
@ -63,12 +64,20 @@ class ClientAttributeType implements \JsonSerializable
public bool $isRequired = false;
/**
* Datatype of the attribute
*
* @var int
* @since 1.0.0
*/
public int $datatype = AttributeValueType::_STRING;
/**
* Localization
*
* @var string | ClientAttributeTypeL11n
* @var string | BaseStringL11n
*/
protected string | ClientAttributeTypeL11n $l11n;
protected string | BaseStringL11n $l11n;
/**
* Possible default attribute values
@ -86,7 +95,7 @@ class ClientAttributeType implements \JsonSerializable
*/
public function __construct(string $name = '')
{
$this->setL11n($name);
$this->name = $name;
}
/**
@ -104,22 +113,22 @@ class ClientAttributeType implements \JsonSerializable
/**
* Set l11n
*
* @param string|ClientAttributeTypeL11n $l11n Tag article l11n
* @param string|BaseStringL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | ClientAttributeTypeL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof ClientAttributeTypeL11n) {
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof ClientAttributeTypeL11n) {
$this->l11n->title = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
} else {
$this->l11n = new ClientAttributeTypeL11n();
$this->l11n->title = $l11n;
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
}
}
@ -131,7 +140,33 @@ class ClientAttributeType implements \JsonSerializable
*/
public function getL11n() : string
{
return $this->l11n instanceof ClientAttributeTypeL11n ? $this->l11n->title : $this->l11n;
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* Set fields
*
* @param int $fields Fields
*
* @return void
*
* @since 1.0.0
*/
public function setFields(int $fields) : void
{
$this->fields = $fields;
}
/**
* Get default values
*
* @return array
*
* @sicne 1.0.0
*/
public function getDefaults() : array
{
return $this->defaults;
}
/**

View File

@ -1,135 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\ClientManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\Models;
use phpOMS\Localization\ISO639x1Enum;
/**
* Client class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class ClientAttributeTypeL11n implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Client ID.
*
* @var int|ClientAttributeType
* @since 1.0.0
*/
public int | ClientAttributeType $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 int|ClientAttributeType $type Attribute type
* @param string $title Localized title
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(int | ClientAttributeType $type = 0, string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type;
$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\ClientManagement\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Client mapper class.
@ -34,8 +35,8 @@ final class ClientAttributeTypeL11nMapper extends DataMapperFactory
*/
public const COLUMNS = [
'clientmgmt_attr_type_l11n_id' => ['name' => 'clientmgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_type_l11n_title' => ['name' => 'clientmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'clientmgmt_attr_type_l11n_type' => ['name' => 'clientmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
'clientmgmt_attr_type_l11n_title' => ['name' => 'clientmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'clientmgmt_attr_type_l11n_type' => ['name' => 'clientmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
'clientmgmt_attr_type_l11n_lang' => ['name' => 'clientmgmt_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
@ -54,4 +55,12 @@ final class ClientAttributeTypeL11nMapper extends DataMapperFactory
* @since 1.0.0
*/
public const PRIMARYFIELD ='clientmgmt_attr_type_l11n_id';
/**
* Model to use by the mapper.
*
* @var string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;
}

View File

@ -35,6 +35,7 @@ final class ClientAttributeTypeMapper extends DataMapperFactory
public const COLUMNS = [
'clientmgmt_attr_type_id' => ['name' => 'clientmgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_type_name' => ['name' => 'clientmgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'clientmgmt_attr_type_datatype' => ['name' => 'clientmgmt_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'],
'clientmgmt_attr_type_fields' => ['name' => 'clientmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
'clientmgmt_attr_type_custom' => ['name' => 'clientmgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'],
'clientmgmt_attr_type_pattern' => ['name' => 'clientmgmt_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'],

View File

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Localization\BaseStringL11n;
/**
* Client attribute value class.
@ -37,14 +37,6 @@ class ClientAttributeValue implements \JsonSerializable
*/
protected int $id = 0;
/**
* Type of the attribute
*
* @var int
* @since 1.0.0
*/
public int $type = 0;
/**
* Int value
*
@ -86,37 +78,11 @@ class ClientAttributeValue implements \JsonSerializable
public bool $isDefault = false;
/**
* Language
* Localization
*
* @var string
* @since 1.0.0
* @var null|BaseStringL11n
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Country
*
* @var string
* @since 1.0.0
*/
protected string $country = ISO3166TwoEnum::_USA;
/**
* Constructor.
*
* @param int $type Type
* @param mixed $value Value
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(int $type = 0, mixed $value = null, string $language = ISO639x1Enum::_EN)
{
$this->type = $type;
$this->language = $language;
$this->setValue($value);
}
private ?BaseStringL11n $l11n = null;
/**
* Get id
@ -131,24 +97,61 @@ class ClientAttributeValue implements \JsonSerializable
}
/**
* Set value
* Set l11n
*
* @param int|string|float|\DateTimeInterface $value Value
* @param string|BaseStringL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setValue(mixed $value) : void
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if (\is_string($value)) {
$this->valueStr = $value;
} elseif (\is_int($value)) {
$this->valueInt = $value;
} elseif (\is_float($value)) {
$this->valueDec = $value;
} elseif ($value instanceof \DateTimeInterface) {
$this->valueDat = $value;
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->ref = $this->id;
$this->l11n->setLanguage($lang);
}
}
/**
* Get localization
*
* @return null|string
*
* @since 1.0.0
*/
public function getL11n() : ?string
{
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* Set value
*
* @param int|string|float|\DateTimeInterface $value Value
* @param int $type Datatype
*
* @return void
*
* @since 1.0.0
*/
public function setValue(mixed $value, int $datatype) : void
{
if ($datatype === AttributeValueType::_STRING) {
$this->valueStr = (string) $value;
} elseif ($datatype === AttributeValueType::_INT) {
$this->valueInt = (int) $value;
} elseif ($datatype === AttributeValueType::_FLOAT) {
$this->valueDec = (float) $value;
} elseif ($datatype === AttributeValueType::_DATETIME) {
$this->valueDat = new \DateTime($value);
}
}
@ -174,58 +177,6 @@ class ClientAttributeValue implements \JsonSerializable
return null;
}
/**
* Set language
*
* @param string $language Language
*
* @return void
*
* @since 1.0.0
*/
public function setLanguage(string $language) : void
{
$this->language = $language;
}
/**
* Get language
*
* @return string
*
* @since 1.0.0
*/
public function getLanguage() : string
{
return $this->language;
}
/**
* Set country
*
* @param string $country Country
*
* @return void
*
* @since 1.0.0
*/
public function setCountry(string $country) : void
{
$this->country = $country;
}
/**
* Get country
*
* @return string
*
* @since 1.0.0
*/
public function getCountry() : string
{
return $this->country;
}
/**
* {@inheritdoc}
*/
@ -233,14 +184,11 @@ class ClientAttributeValue implements \JsonSerializable
{
return [
'id' => $this->id,
'type' => $this->type,
'valueInt' => $this->valueInt,
'valueStr' => $this->valueStr,
'valueDec' => $this->valueDec,
'valueDat' => $this->valueDat,
'isDefault' => $this->isDefault,
'language' => $this->language,
'country' => $this->country,
];
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\ClientManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Client mapper class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class ClientAttributeValueL11nMapper extends DataMapperFactory
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
public const COLUMNS = [
'clientmgmt_attr_value_l11n_id' => ['name' => 'clientmgmt_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_value_l11n_title' => ['name' => 'clientmgmt_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'clientmgmt_attr_value_l11n_value' => ['name' => 'clientmgmt_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'],
'clientmgmt_attr_value_l11n_lang' => ['name' => 'clientmgmt_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'clientmgmt_attr_value_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='clientmgmt_attr_value_l11n_id';
/**
* Model to use by the mapper.
*
* @var string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;
}

View File

@ -35,13 +35,25 @@ final class ClientAttributeValueMapper extends DataMapperFactory
public const COLUMNS = [
'clientmgmt_attr_value_id' => ['name' => 'clientmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_value_default' => ['name' => 'clientmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'clientmgmt_attr_value_type' => ['name' => 'clientmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'],
'clientmgmt_attr_value_valueStr' => ['name' => 'clientmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
'clientmgmt_attr_value_valueInt' => ['name' => 'clientmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'clientmgmt_attr_value_valueDec' => ['name' => 'clientmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'clientmgmt_attr_value_valueDat' => ['name' => 'clientmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'clientmgmt_attr_value_lang' => ['name' => 'clientmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
'clientmgmt_attr_value_country' => ['name' => 'clientmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'],
];
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [
'l11n' => [
'mapper' => ClientAttributeValueL11nMapper::class,
'table' => 'clientmgmt_attr_value_l11n',
'self' => 'clientmgmt_attr_value_l11n_value',
'external' => null,
],
];
/**

View File

@ -47,6 +47,7 @@ final class ClientMapper extends DataMapperFactory
'clientmgmt_client_created_at' => ['name' => 'clientmgmt_client_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'clientmgmt_client_profile' => ['name' => 'clientmgmt_client_profile', 'type' => 'int', 'internal' => 'profile'],
'clientmgmt_client_address' => ['name' => 'clientmgmt_client_address', 'type' => 'int', 'internal' => 'mainAddress'],
'clientmgmt_client_unit' => ['name' => 'clientmgmt_client_unit', 'type' => 'int', 'internal' => 'unit'],
];
/**

View File

@ -1,46 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\ClientManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\Models;
/**
* Null model
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullClientAttributeTypeL11n extends ClientAttributeTypeL11n
{
/**
* 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

@ -104,7 +104,7 @@ echo $this->getData('nav')->render(); ?>
<tbody>
<?php $count = 0; foreach ($clients as $key => $value) : ++$count;
$url = UriFactory::build('{/lang}/{/app}/sales/client/profile?{?}&id=' . $value->getId());
$image = $value->getFileByType(0);
$image = $value->getFileByTypeName('client_profile_image');
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><img alt="<?= $this->getHtml('IMG_alt_client'); ?>" width="30" loading="lazy" class="item-image"

View File

@ -71,7 +71,6 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('default', '1');
$request->setData('attributetype', '1');
$request->setData('type', AttributeValueType::_INT);
$request->setData('value', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -90,8 +89,8 @@ trait ApiControllerAttributeTrait
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('type', AttributeValueType::_STRING);
$request->setData('value', '1');
$request->setData('attributetype', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -109,8 +108,8 @@ trait ApiControllerAttributeTrait
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('type', AttributeValueType::_FLOAT);
$request->setData('value', '1.1');
$request->setData('attributetype', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -128,8 +127,8 @@ trait ApiControllerAttributeTrait
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('type', AttributeValueType::_DATETIME);
$request->setData('value', '2020-08-02');
$request->setData('attributetype', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);

View File

@ -1,87 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\ClientAttributeTypeL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* @internal
*/
final class ClientAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
{
private ClientAttributeTypeL11n $l11n;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->l11n = new ClientAttributeTypeL11n();
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeTypeL11n
* @group module
*/
public function testDefault() : void
{
self::assertEquals(0, $this->l11n->getId());
self::assertEquals('', $this->l11n->title);
self::assertEquals(0, $this->l11n->type);
self::assertEquals(ISO639x1Enum::_EN, $this->l11n->getLanguage());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeTypeL11n
* @group module
*/
public function testNameInputOutput() : void
{
$this->l11n->title = 'TestName';
self::assertEquals('TestName', $this->l11n->title);
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeTypeL11n
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeTypeL11n
* @group module
*/
public function testSerialize() : void
{
$this->l11n->title = 'Title';
$this->l11n->type = 2;
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(
[
'id' => 0,
'title' => 'Title',
'type' => 2,
'language' => ISO639x1Enum::_DE,
],
$this->l11n->jsonSerialize()
);
}
}

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\ClientAttributeType;
use Modules\ClientManagement\Models\ClientAttributeTypeL11n;
use phpOMS\Localization\BaseStringL11n;
/**
* @internal
@ -51,7 +51,7 @@ final class ClientAttributeTypeTest extends \PHPUnit\Framework\TestCase
$this->type->setL11n('Test');
self::assertEquals('Test', $this->type->getL11n());
$this->type->setL11n(new ClientAttributeTypeL11n(0, 'NewTest'));
$this->type->setL11n(new BaseStringL11n('NewTest'));
self::assertEquals('NewTest', $this->type->getL11n());
}

View File

@ -15,8 +15,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\ClientAttributeValue;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
use Modules\ClientManagement\Models\AttributeValueType;
/**
* @internal
@ -43,33 +42,13 @@ final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
self::assertNull($this->value->getValue());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->value->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->value->getLanguage());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testCountryInputOutput() : void
{
$this->value->setCountry(ISO3166TwoEnum::_DEU);
self::assertEquals(ISO3166TwoEnum::_DEU, $this->value->getCountry());
}
/**
* @covers Modules\ClientManagement\Models\ClientAttributeValue
* @group module
*/
public function testValueIntInputOutput() : void
{
$this->value->setValue(1);
$this->value->setValue(1, AttributeValueType::_INT);
self::assertEquals(1, $this->value->getValue());
}
@ -79,7 +58,7 @@ final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
*/
public function testValueFloatInputOutput() : void
{
$this->value->setValue(1.1);
$this->value->setValue(1.1, AttributeValueType::_FLOAT);
self::assertEquals(1.1, $this->value->getValue());
}
@ -89,7 +68,7 @@ final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
*/
public function testValueStringInputOutput() : void
{
$this->value->setValue('test');
$this->value->setValue('test', AttributeValueType::_STRING);
self::assertEquals('test', $this->value->getValue());
}
@ -99,7 +78,8 @@ final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
*/
public function testValueDateInputOutput() : void
{
$this->value->setValue($dat = new \DateTime('now'));
$dat = new \DateTime('now');
$this->value->setValue('now', AttributeValueType::_DATETIME);
self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d'));
}
@ -109,23 +89,17 @@ final class ClientAttributeValueTest extends \PHPUnit\Framework\TestCase
*/
public function testSerialize() : void
{
$this->value->type = 1;
$this->value->setValue('test');
$this->value->setValue('test', AttributeValueType::_STRING);
$this->value->isDefault = true;
$this->value->setLanguage(ISO639x1Enum::_DE);
$this->value->setCountry(ISO3166TwoEnum::_DEU);
self::assertEquals(
[
'id' => 0,
'type' => 1,
'valueInt' => null,
'valueStr' => 'test',
'valueDec' => null,
'valueDat' => null,
'isDefault' => true,
'language' => ISO639x1Enum::_DE,
'country' => ISO3166TwoEnum::_DEU,
],
$this->value->jsonSerialize()
);

View File

@ -1,42 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ClientManagement\tests\Models;
use Modules\ClientManagement\Models\NullClientAttributeTypeL11n;
/**
* @internal
*/
final class NullClientAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeTypeL11n
* @group framework
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeTypeL11n', new NullClientAttributeTypeL11n());
}
/**
* @covers Modules\ClientManagement\Models\NullClientAttributeTypeL11n
* @group framework
*/
public function testId() : void
{
$null = new NullClientAttributeTypeL11n(2);
self::assertEquals(2, $null->getId());
}
}