improve value localizations

This commit is contained in:
Dennis Eichhorn 2022-12-22 14:19:06 +01:00
parent 16b5a38105
commit d505406976
5 changed files with 451 additions and 32 deletions

View File

@ -209,21 +209,41 @@
"null": true,
"default": null
},
"itemmgmt_attr_value_lang": {
"name": "itemmgmt_attr_value_lang",
"itemmgmt_attr_value_unit": {
"name": "itemmgmt_attr_value_unit",
"type": "VARCHAR(255)",
"null": false
},
}
},
"itemmgmt_attr_value_l11n": {
"name": "itemmgmt_attr_value_l11n",
"fields": {
"itemmgmt_attr_value_l11n_id": {
"name": "itemmgmt_attr_value_l11n_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"itemmgmt_attr_value_l11n_title": {
"name": "itemmgmt_attr_value_l11n_title",
"type": "VARCHAR(255)",
"null": false
},
"itemmgmt_attr_value_l11n_type": {
"name": "itemmgmt_attr_value_l11n_value",
"type": "INT(11)",
"null": false,
"foreignTable": "itemmgmt_attr_value",
"foreignKey": "itemmgmt_attr_value_id"
},
"itemmgmt_attr_value_l11n_lang": {
"name": "itemmgmt_attr_value_l11n_lang",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"null": false,
"foreignTable": "language",
"foreignKey": "language_639_1"
},
"itemmgmt_attr_value_country": {
"name": "itemmgmt_attr_value_country",
"type": "VARCHAR(2)",
"null": true,
"default": null,
"foreignTable": "country",
"foreignKey": "country_code2"
}
}
},
@ -287,6 +307,171 @@
}
}
},
"itemmgmt_item_sales_price": {
"name": "itemmgmt_item_sales_price",
"fields": {
"itemmgmt_item_sales_price_id": {
"name": "itemmgmt_item_sales_price_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"itemmgmt_item_sales_price_name": {
"name": "itemmgmt_item_sales_price_name",
"type": "VARCHAR(255)",
"null": false
},
"itemmgmt_item_sales_price_price": {
"name": "itemmgmt_item_sales_price_price",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_status": {
"name": "itemmgmt_item_sales_price_status",
"type": "TINYINT(1)",
"null": false
},
"itemmgmt_item_sales_price_minquantity": {
"name": "itemmgmt_item_sales_price_minquantity",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_relativediscount": {
"name": "itemmgmt_item_sales_price_relativediscount",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_absolutediscount": {
"name": "itemmgmt_item_sales_price_absolutediscount",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_relativeunitdiscount": {
"name": "itemmgmt_item_sales_price_relativeunitdiscount",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_absoluteunitdiscount": {
"name": "itemmgmt_item_sales_price_absoluteunitdiscount",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_region": {
"name": "itemmgmt_item_sales_price_region",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_country": {
"name": "itemmgmt_item_sales_price_country",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_start": {
"name": "itemmgmt_item_sales_price_start",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_end": {
"name": "itemmgmt_item_sales_price_end",
"type": "INT(11)",
"null": false
},
"itemmgmt_item_sales_price_promocode": {
"name": "itemmgmt_item_sales_price_end",
"type": "INT(11)",
"null": false
}
}
},
"itemmgmt_item_sales_price_relation": {
"name": "itemmgmt_item_sales_price_relation",
"fields": {
"itemmgmt_item_note_id": {
"name": "itemmgmt_item_sales_price_relation_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"itemmgmt_item_sales_price_relation_item": {
"name": "itemmgmt_item_sales_price_relation_item",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "itemmgmt_item",
"foreignKey": "itemmgmt_item_id"
},
"itemmgmt_item_sales_price_relation_itemgroup": {
"name": "itemmgmt_item_sales_price_relation_itemgroup",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "itemmgmt_item",
"foreignKey": "itemmgmt_item_id"
},
"itemmgmt_item_sales_price_relation_client": {
"name": "itemmgmt_item_sales_price_relation_client",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "clientmgmt_client",
"foreignKey": "clientmgmt_client_id"
},
"itemmgmt_item_sales_price_relation_clientgroup": {
"name": "itemmgmt_item_sales_price_relation_clientgroup",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "clientmgmt_client",
"foreignKey": "clientmgmt_client_id"
},
"itemmgmt_item_sales_price_relation_price": {
"name": "itemmgmt_item_sales_price_relation_price",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "itemmgmt_item_sales_price",
"foreignKey": "itemmgmt_item_sales_price_id"
}
}
},
"itemmgmt_item_sales_price_history": {
"name": "itemmgmt_item_sales_price_history",
"fields": {
"itemmgmt_item_sales_price_history_id": {
"name": "itemmgmt_item_sales_price_history_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
}
}
},
"itemmgmt_item_purchase_price": {
"name": "itemmgmt_item_purchase_price",
"fields": {
"itemmgmt_item_purchase_price_id": {
"name": "itemmgmt_item_purchase_price_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
}
}
},
"itemmgmt_item_purchase_price_history": {
"name": "itemmgmt_item_purchase_price_history",
"fields": {
"itemmgmt_item_purchase_price_history_id": {
"name": "itemmgmt_item_purchase_price_history_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
}
}
},
"itemmgmt_item_media": {
"name": "itemmgmt_item_media",
"fields": {

View File

@ -90,36 +90,29 @@ class ItemAttributeValue implements \JsonSerializable
// it should be basically the same ass the itemattributetype which has a itemattributetypel11n element.
/**
* Language
* Localization
*
* @var string
* @since 1.0.0
* @var null|ItemAttributeValueL11n
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Country
*
* @var string
* @since 1.0.0
*/
protected string $country = ISO3166TwoEnum::_USA;
private ?ItemAttributeValueL11n $l11n = null;
/**
* Constructor.
*
* @param int $type Type
* @param mixed $value Value
* @param string $language Language
* @param int $type Type
* @param mixed $value Value
*
* @since 1.0.0
*/
public function __construct(int $type = 0, $value = '', string $language = ISO639x1Enum::_EN)
public function __construct(int $type = 0, mixed $value = '', string $name = '')
{
$this->type = $type;
$this->language = $language;
$this->type = $type;
$this->setValue($value);
if (!empty($name)) {
$this->setL11n($name);
}
}
/**
@ -134,6 +127,40 @@ class ItemAttributeValue implements \JsonSerializable
return $this->id;
}
/**
* Set l11n
*
* @param string|ItemAttributeTypeL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | ItemAttributeValueL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof ItemAttributeValueL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof ItemAttributeValueL11n) {
$this->l11n->title = $l11n;
} else {
$this->l11n = new ItemAttributeValueL11n();
$this->l11n->title = $l11n;
$this->l11n->setLanguage($lang);
}
}
/**
* @return string
*
* @since 1.0.0
*/
public function getL11n() : string
{
return $this->l11n instanceof ItemAttributeTypeL11n ? $this->l11n->title : $this->l11n;
}
/**
* Set value
*

View File

@ -0,0 +1,135 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\ItemManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ItemManagement\Models;
use phpOMS\Localization\ISO639x1Enum;
/**
* Item class.
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class ItemAttributeValueL11n implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Item ID.
*
* @var int
* @since 1.0.0
*/
public int $value;
/**
* 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 $value Attribute value
* @param string $title Localized title
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(int $value = 0, string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->value = $value;
$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,
'value' => $this->value,
'language' => $this->language,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\ItemManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\ItemManagement\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Item mapper class.
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class ItemAttributeValueL11nMapper 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 = [
'itemmgmt_attr_value_l11n_id' => ['name' => 'itemmgmt_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_attr_value_l11n_title' => ['name' => 'itemmgmt_attr_value_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'itemmgmt_attr_value_l11n_value' => ['name' => 'itemmgmt_attr_value_l11n_value', 'type' => 'int', 'internal' => 'value'],
'itemmgmt_attr_value_l11n_lang' => ['name' => 'itemmgmt_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'itemmgmt_attr_value_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='itemmgmt_attr_value_l11n_id';
}

View File

@ -40,10 +40,25 @@ final class ItemAttributeValueMapper extends DataMapperFactory
'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_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' => ItemAttributeValueL11nMapper::class,
'table' => 'itemmgmt_attr_value_l11n',
'self' => 'itemmgmt_attr_value_l11n_type',
'column' => 'title',
'external' => null,
],
];
/**
* Primary table.
*