phpstan, phpcs, phpunit fixes

This commit is contained in:
Dennis Eichhorn 2023-01-27 22:12:09 +01:00
parent bb52554a61
commit 4b66fd835d
21 changed files with 704 additions and 113 deletions

View File

@ -65,6 +65,66 @@
}
}
},
"clientmgmt_client_l11n_type": {
"name": "clientmgmt_client_l11n_type",
"fields": {
"clientmgmt_client_l11n_type_id": {
"name": "clientmgmt_client_l11n_type_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"clientmgmt_client_l11n_type_title": {
"name": "clientmgmt_client_l11n_type_title",
"type": "VARCHAR(50)",
"null": false
},
"clientmgmt_client_l11n_type_required": {
"name": "clientmgmt_client_l11n_type_required",
"type": "TINYINT(1)",
"null": false
}
}
},
"clientmgmt_client_l11n": {
"name": "clientmgmt_client_l11n",
"fields": {
"clientmgmt_client_l11n_id": {
"name": "clientmgmt_client_l11n_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"clientmgmt_client_l11n_description": {
"name": "clientmgmt_client_l11n_description",
"type": "TEXT",
"null": false
},
"clientmgmt_client_l11n_client": {
"name": "clientmgmt_client_l11n_client",
"type": "INT(11)",
"null": false,
"foreignTable": "clientmgmt_client",
"foreignKey": "clientmgmt_client_id"
},
"clientmgmt_client_l11n_typeref": {
"name": "clientmgmt_client_l11n_typeref",
"type": "INT(11)",
"null": false,
"foreignTable": "clientmgmt_client_l11n_type",
"foreignKey": "clientmgmt_client_l11n_type_id"
},
"clientmgmt_client_l11n_lang": {
"name": "clientmgmt_client_l11n_lang",
"type": "VARCHAR(2)",
"null": false,
"foreignTable": "language",
"foreignKey": "language_639_1"
}
}
},
"clientmgmt_client_contactelement": {
"name": "clientmgmt_client_contactelement",
"fields": {

View File

@ -176,9 +176,9 @@ final class Installer extends InstallerAbstract
/**
* Create default attribute values for types
*
* @param ApplicationAbstract $app Application
* @param ApplicationAbstract $app Application
* @param array $clientAttrType Attribute types
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
*
* @return array<string, array>
*

View File

@ -23,10 +23,17 @@ use Modules\ClientManagement\Models\ClientAttributeType;
use Modules\ClientManagement\Models\ClientAttributeTypeL11nMapper;
use Modules\ClientManagement\Models\ClientAttributeTypeMapper;
use Modules\ClientManagement\Models\ClientAttributeValue;
use Modules\ClientManagement\Models\ClientAttributeValueL11nMapper;
use Modules\ClientManagement\Models\ClientAttributeValueMapper;
use Modules\ClientManagement\Models\ClientL11n;
use Modules\ClientManagement\Models\ClientL11nMapper;
use Modules\ClientManagement\Models\ClientL11nType;
use Modules\ClientManagement\Models\ClientL11nTypeMapper;
use Modules\ClientManagement\Models\ClientMapper;
use Modules\ClientManagement\Models\NullClientAttributeType;
use Modules\ClientManagement\Models\NullClientAttributeValue;
use Modules\ClientManagement\Models\NullClientL11nType;
use Modules\Media\Models\MediaMapper;
use Modules\Media\Models\PathSettings;
use Modules\Profile\Models\ContactElementMapper;
use Modules\Profile\Models\Profile;
@ -131,7 +138,7 @@ final class ApiController extends Controller
}
/**
* Routing end-point for application behaviour.
* Api method to create client l11n
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -143,27 +150,126 @@ final class ApiController extends Controller
*
* @since 1.0.0
*/
public function apiContactElementCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
public function apiClientL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
$profileModule = $this->app->moduleManager->get('Profile');
if (!empty($val = $profileModule->validateContactElementCreate($request))) {
$response->set('contact_element_create', new FormValidation($val));
if (!empty($val = $this->validateClientL11nCreate($request))) {
$response->set('client_l11n_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$contactElement = $profileModule->createContactElementFromRequest($request);
$clientL11n = $this->createClientL11nFromRequest($request);
$this->createModel($request->header->account, $clientL11n, ClientL11nMapper::class, 'client_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Client localization', 'Client localization successfully created', $clientL11n);
}
$this->createModel($request->header->account, $contactElement, ContactElementMapper::class, 'client-contactElement', $request->getOrigin());
$this->createModelRelation(
$request->header->account,
(int) $request->getData('account'),
$contactElement->getId(),
ClientMapper::class, 'contactElements', '', $request->getOrigin()
);
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Contact Element', 'Contact element successfully created', $contactElement);
/**
* Method to create client l11n from request.
*
* @param RequestAbstract $request Request
*
* @return ClientL11n
*
* @since 1.0.0
*/
private function createClientL11nFromRequest(RequestAbstract $request) : ClientL11n
{
$clientL11n = new ClientL11n();
$clientL11n->client = (int) ($request->getData('client') ?? 0);
$clientL11n->type = new NullClientL11nType((int) ($request->getData('type') ?? 0));
$clientL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
$clientL11n->description = (string) ($request->getData('description') ?? '');
return $clientL11n;
}
/**
* Validate client l11n create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateClientL11nCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['client'] = empty($request->getData('client')))
|| ($val['type'] = empty($request->getData('type')))
|| ($val['description'] = empty($request->getData('description')))
) {
return $val;
}
return [];
}
/**
* Api method to create client l11n type
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiClientL11nTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateClientL11nTypeCreate($request))) {
$response->set('client_l11n_type_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$clientL11nType = $this->createClientL11nTypeFromRequest($request);
$this->createModel($request->header->account, $clientL11nType, ClientL11nTypeMapper::class, 'client_l11n_type', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Client localization type', 'Client localization type successfully created', $clientL11nType);
}
/**
* Method to create client l11n type from request.
*
* @param RequestAbstract $request Request
*
* @return ClientL11nType
*
* @since 1.0.0
*/
private function createClientL11nTypeFromRequest(RequestAbstract $request) : ClientL11nType
{
$clientL11nType = new ClientL11nType();
$clientL11nType->title = (string) ($request->getData('title') ?? '');
$clientL11nType->isRequired = (bool) ($request->getData('is_required') ?? false);
return $clientL11nType;
}
/**
* Validate client l11n type create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateClientL11nTypeCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))) {
return $val;
}
return [];
}
/**
@ -272,8 +378,8 @@ final class ApiController extends Controller
*/
private function createClientAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
@ -342,13 +448,13 @@ final class ApiController extends Controller
*/
private function createClientAttributeTypeFromRequest(RequestAbstract $request) : ClientAttributeType
{
$attrType = new ClientAttributeType($request->getData('name') ?? '');
$attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN);
$attrType->datatype = (int) ($request->getData('datatype') ?? 0);
$attrType->setFields((int) ($request->getData('fields') ?? 0));
$attrType = new ClientAttributeType($request->getData('name') ?? '');
$attrType->datatype = (int) ($request->getData('datatype') ?? 0);
$attrType->custom = (bool) ($request->getData('custom') ?? false);
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
$attrType->validationPattern = (string) ($request->getData('validation_pattern') ?? '');
$attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN);
$attrType->setFields((int) ($request->getData('fields') ?? 0));
return $attrType;
}
@ -422,6 +528,7 @@ final class ApiController extends Controller
*/
private function createClientAttributeValueFromRequest(RequestAbstract $request) : ClientAttributeValue
{
/** @var ClientAttributeType $type */
$type = ClientAttributeTypeMapper::get()
->where('id', (int) ($request->getData('type') ?? 0))
->execute();
@ -496,8 +603,8 @@ final class ApiController extends Controller
*/
private function createClientAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
@ -552,16 +659,29 @@ final class ApiController extends Controller
}
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
$request->getDataList('names'),
$request->getDataList('filenames'),
$uploadedFiles,
$request->header->account,
__DIR__ . '/../../../Modules/Media/Files/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
'/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
$request->getData('type', 'int'),
names: $request->getDataList('names'),
fileNames: $request->getDataList('filenames'),
files: $uploadedFiles,
account: $request->header->account,
basePath: __DIR__ . '/../../../Modules/Media/Files/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
virtualPath: '/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
pathSettings: PathSettings::FILE_PATH
);
if ($request->hasData('type')) {
foreach ($uploaded as $file) {
$this->createModelRelation(
$request->header->account,
$file->getId(),
$request->getData('type', 'int'),
MediaMapper::class,
'types',
'',
$request->getOrigin()
);
}
}
$this->createModelRelation(
$request->header->account,
(int) $request->getData('client'),

View File

@ -66,6 +66,12 @@ class Client
*/
private array $notes = [];
/**
* Files.
*
* @var Media[]
* @since 1.0.0
*/
private array $files = [];
private array $contactElements = [];
@ -194,18 +200,6 @@ class Client
return $this->notes;
}
/**
* Get media.
*
* @return array
*
* @since 1.0.0
*/
public function getFiles() : array
{
return $this->files;
}
/**
* Add media.
*
@ -348,28 +342,19 @@ class Client
}
/**
* Get all media files by type
*
* @param null|int $type Media type
* Get files
*
* @return Media[]
*
* @since 1.0.0
*/
public function getFilesByType(int $type = null) : array
public function getFiles() : array
{
$files = [];
foreach ($this->files as $file) {
if ($file->type === $type) {
$files[] = $file;
}
}
return $files;
return $this->files;
}
/**
* Get all media files by type
* Get media file by type
*
* @param int $type Media type
*
@ -380,7 +365,7 @@ class Client
public function getFileByType(int $type) : Media
{
foreach ($this->files as $file) {
if ($file->type === $type) {
if ($file->hasMediaTypeId($type)) {
return $file;
}
}
@ -400,7 +385,7 @@ class Client
public function getFileByTypeName(string $type) : Media
{
foreach ($this->files as $file) {
if ($file->type->name === $type) {
if ($file->hasMediaTypeName($type)) {
return $file;
}
}

View File

@ -42,7 +42,7 @@ final class ClientAttributeMapper extends DataMapperFactory
/**
* Has one relation.
*
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
public const OWNS_ONE = [

View File

@ -125,7 +125,8 @@ class ClientAttributeType implements \JsonSerializable
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
@ -140,6 +141,10 @@ class ClientAttributeType implements \JsonSerializable
*/
public function getL11n() : string
{
if (!isset($this->l11n)) {
return '';
}
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}

View File

@ -59,7 +59,7 @@ final class ClientAttributeTypeL11nMapper extends DataMapperFactory
/**
* Model to use by the mapper.
*
* @var string
* @var class-string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;

View File

@ -45,7 +45,7 @@ final class ClientAttributeTypeMapper extends DataMapperFactory
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [

View File

@ -135,7 +135,8 @@ class ClientAttributeValue implements \JsonSerializable
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
@ -159,8 +160,8 @@ class ClientAttributeValue implements \JsonSerializable
/**
* Set value
*
* @param int|string|float|\DateTimeInterface $value Value
* @param int $type Datatype
* @param int|string|float $value Value
* @param int $datatype Datatype
*
* @return void
*
@ -178,7 +179,7 @@ class ClientAttributeValue implements \JsonSerializable
} elseif ($datatype === AttributeValueType::_FLOAT) {
$this->valueDec = (float) $value;
} elseif ($datatype === AttributeValueType::_DATETIME) {
$this->valueDat = new \DateTime($value);
$this->valueDat = new \DateTime((string) $value);
}
}

View File

@ -59,7 +59,7 @@ final class ClientAttributeValueL11nMapper extends DataMapperFactory
/**
* Model to use by the mapper.
*
* @var string
* @var class-string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;

View File

@ -47,7 +47,7 @@ final class ClientAttributeValueMapper extends DataMapperFactory
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [

143
Models/ClientL11n.php Executable file
View File

@ -0,0 +1,143 @@
<?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;
/**
* Localization of the client class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class ClientL11n implements \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Client ID.
*
* @var int
* @since 1.0.0
*/
public int $client = 0;
/**
* Client ID.
*
* @var ClientL11nType
* @since 1.0.0
*/
public ClientL11nType $type;
/**
* Language.
*
* @var string
* @since 1.0.0
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
public string $description = '';
/**
* Constructor.
*
* @param ClientL11nType $type Client localization type
* @param string $description Description/content
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(ClientL11nType $type = null, string $description = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type ?? new ClientL11nType();
$this->description = $description;
$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,
'description' => $this->description,
'client' => $this->client,
'language' => $this->language,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

71
Models/ClientL11nMapper.php Executable file
View File

@ -0,0 +1,71 @@
<?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;
/**
* Client mapper class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class ClientL11nMapper 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_client_l11n_id' => ['name' => 'clientmgmt_client_l11n_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_client_l11n_description' => ['name' => 'clientmgmt_client_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
'clientmgmt_client_l11n_client' => ['name' => 'clientmgmt_client_l11n_client', 'type' => 'int', 'internal' => 'client'],
'clientmgmt_client_l11n_lang' => ['name' => 'clientmgmt_client_l11n_lang', 'type' => 'string', 'internal' => 'language'],
'clientmgmt_client_l11n_typeref' => ['name' => 'clientmgmt_client_l11n_typeref', 'type' => 'int', 'internal' => 'type'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
public const OWNS_ONE = [
'type' => [
'mapper' => ClientL11nTypeMapper::class,
'external' => 'clientmgmt_client_l11n_typeref',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'clientmgmt_client_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='clientmgmt_client_l11n_id';
}

93
Models/ClientL11nType.php Executable file
View File

@ -0,0 +1,93 @@
<?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;
/**
* Client class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class ClientL11nType implements \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Identifier for the l11n type.
*
* @var string
* @since 1.0.0
*/
public string $title = '';
/**
* Is the l11n type required for an item?
*
* @var bool
* @since 1.0.0
*/
public bool $isRequired = false;
/**
* Constructor.
*
* @param string $title Title
*
* @since 1.0.0
*/
public function __construct(string $title = '')
{
$this->title = $title;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

56
Models/ClientL11nTypeMapper.php Executable file
View File

@ -0,0 +1,56 @@
<?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;
/**
* Client mapper class.
*
* @package Modules\ClientManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class ClientL11nTypeMapper 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_client_l11n_type_id' => ['name' => 'clientmgmt_client_l11n_type_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_client_l11n_type_title' => ['name' => 'clientmgmt_client_l11n_type_title', 'type' => 'string', 'internal' => 'title'],
'clientmgmt_client_l11n_type_required' => ['name' => 'clientmgmt_client_l11n_type_required', 'type' => 'bool', 'internal' => 'isRequired'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'clientmgmt_client_l11n_type';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='clientmgmt_client_l11n_type_id';
}

View File

@ -77,7 +77,7 @@ final class ClientMapper extends DataMapperFactory
/**
* Has one relation.
*
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
public const OWNS_ONE = [
@ -94,7 +94,7 @@ final class ClientMapper extends DataMapperFactory
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [

47
Models/NullClientL11n.php Executable file
View File

@ -0,0 +1,47 @@
<?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 NullClientL11n extends ClientL11n
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

46
Models/NullClientL11nType.php Executable file
View File

@ -0,0 +1,46 @@
<?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 NullClientL11nType extends ClientL11nType
{
/**
* 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

@ -34,6 +34,7 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('title', 'EN:1');
$request->setData('name', 'test_name');
$request->setData('language', ISO639x1Enum::_EN);
$this->module->apiClientAttributeTypeCreate($request, $response);
@ -69,7 +70,7 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('default', '1');
$request->setData('attributetype', '1');
$request->setData('type', '1');
$request->setData('value', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -89,7 +90,7 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('value', '1');
$request->setData('attributetype', '1');
$request->setData('type', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -108,7 +109,7 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('value', '1.1');
$request->setData('attributetype', '1');
$request->setData('type', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);
@ -127,7 +128,7 @@ trait ApiControllerAttributeTrait
$request->header->account = 1;
$request->setData('value', '2020-08-02');
$request->setData('attributetype', '1');
$request->setData('type', '1');
$request->setData('language', ISO639x1Enum::_DE);
$request->setData('country', ISO3166TwoEnum::_DEU);

View File

@ -59,41 +59,6 @@ trait ApiControllerClientTrait
self::assertGreaterThan(0, $response->get('')['response']->getId());
}
/**
* @covers Modules\ClientManagement\Controller\ApiController
* @group module
*/
public function testApiClientContactElementCreate() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('account', '1'); // client id in this case
$request->setData('type', ContactType::EMAIL);
$request->setData('content', 'email@email.com');
$this->module->apiContactElementCreate($request, $response);
self::assertGreaterThan(0, $response->get('')['response']->getId());
}
/**
* @covers Modules\ClientManagement\Controller\ApiController
* @group module
*/
public function testApiClientContactElementCreateInvalidData() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('invalid', '1');
$this->module->apiContactElementCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
/**
* @covers Modules\ClientManagement\Controller\ApiController
* @group module
@ -124,7 +89,7 @@ trait ApiControllerClientTrait
$request->header->account = 1;
$request->setData('name', '123456 backend');
$request->setData('client', 1);
$request->setData('type', 'backend_image');
$request->setData('type', '1');
TestUtils::setMember($request, 'files', [
'file1' => [

View File

@ -51,7 +51,6 @@ final class ClientTest extends \PHPUnit\Framework\TestCase
self::assertEquals([], $this->client->getFiles());
self::assertEquals([], $this->client->getAddresses());
self::assertEquals([], $this->client->getContactElements());
self::assertEquals([], $this->client->getFilesByType(0));
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->client->createdAt->format('Y-m-d'));
self::assertInstanceOf('\Modules\Profile\Models\Profile', $this->client->profile);
self::assertInstanceOf('\Modules\Admin\Models\Address', $this->client->mainAddress);
@ -86,7 +85,6 @@ final class ClientTest extends \PHPUnit\Framework\TestCase
{
$this->client->addFile($temp = new Media());
self::assertCount(1, $this->client->getFiles());
self::assertEquals([$temp], $this->client->getFilesByType());
}
/**