l11n, unit/app and simplification fixes

This commit is contained in:
Dennis Eichhorn 2023-01-07 19:00:33 +01:00
parent 6d4c958e90
commit 3ee10d69fe
19 changed files with 379 additions and 464 deletions

View File

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

View File

@ -53,6 +53,14 @@
"default": null,
"foreignTable": "address",
"foreignKey": "address_id"
},
"suppliermgmt_supplier_unit": {
"name": "suppliermgmt_supplier_unit",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "organization_unit",
"foreignKey": "organization_unit_id"
}
}
},
@ -95,6 +103,12 @@
"suppliermgmt_attr_type_name": {
"name": "suppliermgmt_attr_type_name",
"type": "VARCHAR(255)",
"null": false,
"unique": true
},
"suppliermgmt_attr_type_datatype": {
"name": "suppliermgmt_attr_type_datatype",
"type": "INT(11)",
"null": false
},
"suppliermgmt_attr_type_fields": {
@ -167,11 +181,6 @@
"type": "TINYINT(1)",
"null": false
},
"suppliermgmt_attr_value_type": {
"name": "suppliermgmt_attr_value_type",
"type": "INT(11)",
"null": false
},
"suppliermgmt_attr_value_valueStr": {
"name": "suppliermgmt_attr_value_valueStr",
"type": "VARCHAR(255)",
@ -195,22 +204,37 @@
"type": "DATETIME",
"null": true,
"default": null
}
}
},
"suppliermgmt_attr_value_l11n": {
"name": "suppliermgmt_attr_value_l11n",
"fields": {
"suppliermgmt_attr_value_l11n_id": {
"name": "suppliermgmt_attr_value_l11n_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"suppliermgmt_attr_value_lang": {
"name": "suppliermgmt_attr_value_lang",
"suppliermgmt_attr_value_l11n_title": {
"name": "suppliermgmt_attr_value_l11n_title",
"type": "VARCHAR(255)",
"null": false
},
"suppliermgmt_attr_value_l11n_value": {
"name": "suppliermgmt_attr_value_l11n_value",
"type": "INT(11)",
"null": false,
"foreignTable": "suppliermgmt_attr_value",
"foreignKey": "suppliermgmt_attr_value_id"
},
"suppliermgmt_attr_value_l11n_lang": {
"name": "suppliermgmt_attr_value_l11n_lang",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"null": false,
"foreignTable": "language",
"foreignKey": "language_639_1"
},
"suppliermgmt_attr_value_country": {
"name": "suppliermgmt_attr_value_country",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"foreignTable": "country",
"foreignKey": "country_code2"
}
}
},

View File

@ -19,14 +19,13 @@ use Modules\Admin\Models\Address;
use Modules\Media\Models\PathSettings;
use Modules\Profile\Models\ContactElementMapper;
use Modules\Profile\Models\Profile;
use Modules\SupplierManagement\Models\AttributeValueType;
use Modules\SupplierManagement\Models\NullSupplierAttributeType;
use Modules\SupplierManagement\Models\NullSupplierAttributeValue;
use Modules\SupplierManagement\Models\Supplier;
use Modules\SupplierManagement\Models\SupplierAttribute;
use Modules\SupplierManagement\Models\SupplierAttributeMapper;
use Modules\SupplierManagement\Models\SupplierAttributeType;
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n;
use phpOMS\Localization\BaseStringL11n;
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper;
use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper;
use Modules\SupplierManagement\Models\SupplierAttributeValue;
@ -105,6 +104,8 @@ final class ApiController extends Controller
$addr->setCountry((string) ($request->getData('country') ?? ''));
$supplier->mainAddress = $addr;
$supplier->unit = $request->getData('unit', 'int');
return $supplier;
}
@ -265,18 +266,18 @@ final class ApiController extends Controller
*
* @param RequestAbstract $request Request
*
* @return SupplierAttributeTypeL11n
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createSupplierAttributeTypeL11nFromRequest(RequestAbstract $request) : SupplierAttributeTypeL11n
private function createSupplierAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new SupplierAttributeTypeL11n();
$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 createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType
{
$attrType = new SupplierAttributeType();
$attrType = new SupplierAttributeType($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;
}
@ -362,6 +366,7 @@ final class ApiController extends Controller
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['name'] = empty($request->getData('name')))
) {
return $val;
}
@ -397,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(),
SupplierAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
);
@ -417,28 +422,16 @@ final class ApiController extends Controller
*/
private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : SupplierAttributeValue
{
$type = SupplierAttributeTypeMapper::get()
->where('id', (int) ($request->getData('type') ?? 0))
->execute();
$attrValue = new SupplierAttributeValue();
$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;
@ -465,6 +458,75 @@ final class ApiController extends Controller
return [];
}
/**
* Api method to create item attribute l11n
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiSupplierAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateSupplierAttributeValueL11nCreate($request))) {
$response->set('attr_value_l11n_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrL11n = $this->createSupplierAttributeValueL11nFromRequest($request);
$this->createModel($request->header->account, $attrL11n, SupplierAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type localization', 'Attribute type localization successfully created', $attrL11n);
}
/**
* Method to create Supplier attribute l11n from request.
*
* @param RequestAbstract $request Request
*
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createSupplierAttributeValueL11nFromRequest(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 Supplier attribute l11n create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateSupplierAttributeValueL11nCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['value'] = empty($request->getData('value')))
) {
return $val;
}
return [];
}
/**
* Api method to create supplier files
*

View File

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

@ -82,6 +82,14 @@ class Supplier
private array $partners = [];
/**
* Unit
*
* @var null|int
* @since 1.0.0
*/
public ?int $unit = null;
/**
* Constructor.
*
@ -378,6 +386,26 @@ class Supplier
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\SupplierManagement\Models;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Localization\BaseStringL11n;
/**
* Supplier Attribute Type class.
@ -62,12 +63,20 @@ class SupplierAttributeType implements \JsonSerializable
public bool $isRequired = false;
/**
* Datatype of the attribute
*
* @var int
* @since 1.0.0
*/
public int $datatype = AttributeValueType::_STRING;
/**
* Localization
*
* @var string | SupplierAttributeTypeL11n
* @var string | BaseStringL11n
*/
protected string | SupplierAttributeTypeL11n $l11n;
protected string | BaseStringL11n $l11n;
/**
* Possible default attribute values
@ -85,7 +94,7 @@ class SupplierAttributeType implements \JsonSerializable
*/
public function __construct(string $name = '')
{
$this->setL11n($name);
$this->name = $name;
}
/**
@ -103,22 +112,22 @@ class SupplierAttributeType implements \JsonSerializable
/**
* Set l11n
*
* @param string|SupplierAttributeTypeL11n $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 | SupplierAttributeTypeL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof SupplierAttributeTypeL11n) {
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof SupplierAttributeTypeL11n) {
$this->l11n->title = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
} else {
$this->l11n = new SupplierAttributeTypeL11n();
$this->l11n->title = $l11n;
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
}
}
@ -130,7 +139,33 @@ class SupplierAttributeType implements \JsonSerializable
*/
public function getL11n() : string
{
return $this->l11n instanceof SupplierAttributeTypeL11n ? $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\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
use phpOMS\Localization\ISO639x1Enum;
/**
* Supplier class.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class SupplierAttributeTypeL11n implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Supplier ID.
*
* @var int|SupplierAttributeType
* @since 1.0.0
*/
public int | SupplierAttributeType $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|SupplierAttributeType $type Attribute type
* @param string $title Localized title
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(int | SupplierAttributeType $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\SupplierManagement\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Supplier mapper class.
@ -34,8 +35,8 @@ final class SupplierAttributeTypeL11nMapper extends DataMapperFactory
*/
public const COLUMNS = [
'suppliermgmt_attr_type_l11n_id' => ['name' => 'suppliermgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'suppliermgmt_attr_type_l11n_title' => ['name' => 'suppliermgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'suppliermgmt_attr_type_l11n_type' => ['name' => 'suppliermgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
'suppliermgmt_attr_type_l11n_title' => ['name' => 'suppliermgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'suppliermgmt_attr_type_l11n_type' => ['name' => 'suppliermgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
'suppliermgmt_attr_type_l11n_lang' => ['name' => 'suppliermgmt_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
@ -54,4 +55,12 @@ final class SupplierAttributeTypeL11nMapper extends DataMapperFactory
* @since 1.0.0
*/
public const PRIMARYFIELD ='suppliermgmt_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 SupplierAttributeTypeMapper extends DataMapperFactory
public const COLUMNS = [
'suppliermgmt_attr_type_id' => ['name' => 'suppliermgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'],
'suppliermgmt_attr_type_name' => ['name' => 'suppliermgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'suppliermgmt_attr_type_datatype' => ['name' => 'suppliermgmt_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'],
'suppliermgmt_attr_type_fields' => ['name' => 'suppliermgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
'suppliermgmt_attr_type_custom' => ['name' => 'suppliermgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'],
'suppliermgmt_attr_type_pattern' => ['name' => 'suppliermgmt_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'],

View File

@ -37,14 +37,6 @@ class SupplierAttributeValue 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 SupplierAttributeValue 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, $value = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type;
$this->language = $language;
$this->setValue($value);
}
private ?BaseStringL11n $l11n = null;
/**
* Get id
@ -131,24 +97,61 @@ class SupplierAttributeValue 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($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);
}
}
@ -233,14 +236,11 @@ class SupplierAttributeValue 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\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Supplier mapper class.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class SupplierAttributeValueL11nMapper 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 = [
'suppliermgmt_attr_value_l11n_id' => ['name' => 'suppliermgmt_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'],
'suppliermgmt_attr_value_l11n_title' => ['name' => 'suppliermgmt_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'suppliermgmt_attr_value_l11n_value' => ['name' => 'suppliermgmt_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'],
'suppliermgmt_attr_value_l11n_lang' => ['name' => 'suppliermgmt_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'suppliermgmt_attr_value_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='suppliermgmt_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 SupplierAttributeValueMapper extends DataMapperFactory
public const COLUMNS = [
'suppliermgmt_attr_value_id' => ['name' => 'suppliermgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'suppliermgmt_attr_value_default' => ['name' => 'suppliermgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'suppliermgmt_attr_value_type' => ['name' => 'suppliermgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'],
'suppliermgmt_attr_value_valueStr' => ['name' => 'suppliermgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
'suppliermgmt_attr_value_valueInt' => ['name' => 'suppliermgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'suppliermgmt_attr_value_valueDec' => ['name' => 'suppliermgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'suppliermgmt_attr_value_valueDat' => ['name' => 'suppliermgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'suppliermgmt_attr_value_lang' => ['name' => 'suppliermgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
'suppliermgmt_attr_value_country' => ['name' => 'suppliermgmt_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' => SupplierAttributeValueL11nMapper::class,
'table' => 'suppliermgmt_attr_value_l11n',
'self' => 'suppliermgmt_attr_value_l11n_value',
'external' => null,
],
];
/**

View File

@ -47,6 +47,7 @@ final class SupplierMapper extends DataMapperFactory
'suppliermgmt_supplier_created_at' => ['name' => 'suppliermgmt_supplier_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'suppliermgmt_supplier_profile' => ['name' => 'suppliermgmt_supplier_profile', 'type' => 'int', 'internal' => 'profile'],
'suppliermgmt_supplier_address' => ['name' => 'suppliermgmt_supplier_address', 'type' => 'int', 'internal' => 'mainAddress'],
'suppliermgmt_supplier_unit' => ['name' => 'suppliermgmt_supplier_unit', 'type' => 'int', 'internal' => 'unit'],
];
/**

View File

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

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,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\SupplierManagement\tests\Models;
use Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n;
/**
* @internal
*/
final class NullSupplierAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n
* @group framework
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeTypeL11n', new NullSupplierAttributeTypeL11n());
}
/**
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n
* @group framework
*/
public function testId() : void
{
$null = new NullSupplierAttributeTypeL11n(2);
self::assertEquals(2, $null->getId());
}
}

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\SupplierManagement\tests\Models;
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* @internal
*/
final class SupplierAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
{
private SupplierAttributeTypeL11n $l11n;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->l11n = new SupplierAttributeTypeL11n();
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n
* @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\SupplierManagement\Models\SupplierAttributeTypeL11n
* @group module
*/
public function testNameInputOutput() : void
{
$this->l11n->title = 'TestName';
self::assertEquals('TestName', $this->l11n->title);
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->l11n->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage());
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n
* @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\SupplierManagement\tests\Models;
use Modules\SupplierManagement\Models\SupplierAttributeType;
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n;
use phpOMS\Localization\BaseStringL11n;
/**
* @internal
@ -51,7 +51,7 @@ final class SupplierAttributeTypeTest extends \PHPUnit\Framework\TestCase
$this->type->setL11n('Test');
self::assertEquals('Test', $this->type->getL11n());
$this->type->setL11n(new SupplierAttributeTypeL11n(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\SupplierManagement\tests\Models;
use Modules\SupplierManagement\Models\SupplierAttributeValue;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
use Modules\SupplierManagement\Models\AttributeValueType;
/**
* @internal
@ -43,33 +42,13 @@ final class SupplierAttributeValueTest extends \PHPUnit\Framework\TestCase
self::assertNull($this->value->getValue());
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeValue
* @group module
*/
public function testLanguageInputOutput() : void
{
$this->value->setLanguage(ISO639x1Enum::_DE);
self::assertEquals(ISO639x1Enum::_DE, $this->value->getLanguage());
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeValue
* @group module
*/
public function testCountryInputOutput() : void
{
$this->value->setCountry(ISO3166TwoEnum::_DEU);
self::assertEquals(ISO3166TwoEnum::_DEU, $this->value->getCountry());
}
/**
* @covers Modules\SupplierManagement\Models\SupplierAttributeValue
* @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 SupplierAttributeValueTest 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 SupplierAttributeValueTest 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 SupplierAttributeValueTest 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 SupplierAttributeValueTest 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()
);