mirror of
https://github.com/Karaka-Management/oms-Marketing.git
synced 2026-01-11 17:18:40 +00:00
org -> unit change, some new functionality
This commit is contained in:
parent
53b4143e75
commit
b9415c24c5
|
|
@ -33,4 +33,8 @@ abstract class AttributeValueType extends Enum
|
|||
public const _FLOAT = 3;
|
||||
|
||||
public const _DATETIME = 4;
|
||||
|
||||
public const _BOOL = 5;
|
||||
|
||||
public const _FLOAT_INT = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Marketing\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\Marketing\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullPromotionAttributeTypeL11n extends PromotionAttributeTypeL11n
|
||||
{
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Marketing\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Promotion class.
|
||||
*
|
||||
* @package Modules\Marketing\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PromotionAttributeTypeL11n implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Promotion ID.
|
||||
*
|
||||
* @var int|PromotionAttributeType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int | PromotionAttributeType $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|PromotionAttributeType $type Attribute type
|
||||
* @param string $title Localized title
|
||||
* @param string $language Language
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int | PromotionAttributeType $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();
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
|
||||
/**
|
||||
* Promotion mapper class.
|
||||
|
|
@ -34,8 +35,8 @@ final class PromotionAttributeTypeL11nMapper extends DataMapperFactory
|
|||
*/
|
||||
public const COLUMNS = [
|
||||
'marketing_promotion_attr_type_l11n_id' => ['name' => 'marketing_promotion_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_type_l11n_title' => ['name' => 'marketing_promotion_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
'marketing_promotion_attr_type_l11n_type' => ['name' => 'marketing_promotion_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'marketing_promotion_attr_type_l11n_title' => ['name' => 'marketing_promotion_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
|
||||
'marketing_promotion_attr_type_l11n_type' => ['name' => 'marketing_promotion_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
|
||||
'marketing_promotion_attr_type_l11n_lang' => ['name' => 'marketing_promotion_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
];
|
||||
|
||||
|
|
@ -54,4 +55,12 @@ final class PromotionAttributeTypeL11nMapper extends DataMapperFactory
|
|||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD ='marketing_promotion_attr_type_l11n_id';
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ final class PromotionAttributeTypeMapper extends DataMapperFactory
|
|||
'mapper' => PromotionAttributeTypeL11nMapper::class,
|
||||
'table' => 'marketing_promotion_attr_type_l11n',
|
||||
'self' => 'marketing_promotion_attr_type_l11n_type',
|
||||
'column' => 'title',
|
||||
'column' => 'content',
|
||||
'external' => null,
|
||||
],
|
||||
'defaults' => [
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
|
|
@ -38,12 +39,20 @@ class PromotionAttributeValue implements \JsonSerializable
|
|||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Type of the attribute
|
||||
* Depending attribute type
|
||||
*
|
||||
* @var int
|
||||
* @var null|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $type = 0;
|
||||
public ?int $dependingAttributeType = null;
|
||||
|
||||
/**
|
||||
* Depending attribute value
|
||||
*
|
||||
* @var null|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?int $dependingAttributeValue = null;
|
||||
|
||||
/**
|
||||
* Int value
|
||||
|
|
@ -86,37 +95,19 @@ class PromotionAttributeValue implements \JsonSerializable
|
|||
public bool $isDefault = false;
|
||||
|
||||
/**
|
||||
* Language
|
||||
* Unit of the value
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected string $language = ISO639x1Enum::_EN;
|
||||
public string $unit = '';
|
||||
|
||||
/**
|
||||
* Country
|
||||
* Localization
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
* @var null|BaseStringL11n
|
||||
*/
|
||||
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
|
||||
|
|
@ -139,16 +130,19 @@ class PromotionAttributeValue implements \JsonSerializable
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setValue(mixed $value) : void
|
||||
public function setValue(mixed $value, int $datatype) : 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 ($datatype === AttributeValueType::_STRING) {
|
||||
$this->valueStr = (string) $value;
|
||||
} elseif ($datatype === AttributeValueType::_INT
|
||||
|| $datatype === AttributeValueType::_FLOAT_INT
|
||||
|| $datatype === AttributeValueType::_BOOL
|
||||
) {
|
||||
$this->valueInt = (int) $value;
|
||||
} elseif ($datatype === AttributeValueType::_FLOAT) {
|
||||
$this->valueDec = (float) $value;
|
||||
} elseif ($datatype === AttributeValueType::_DATETIME) {
|
||||
$this->valueDat = new \DateTime($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,55 +169,39 @@ class PromotionAttributeValue implements \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set language
|
||||
* Set l11n
|
||||
*
|
||||
* @param string $language Language
|
||||
* @param string|BaseStringL11n $l11n Tag article l11n
|
||||
* @param string $lang Language
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setLanguage(string $language) : void
|
||||
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
|
||||
{
|
||||
$this->language = $language;
|
||||
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 language
|
||||
* Get localization
|
||||
*
|
||||
* @return string
|
||||
* @return null|string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLanguage() : string
|
||||
public function getL11n() : ?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;
|
||||
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -233,14 +211,11 @@ class PromotionAttributeValue 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,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,15 +35,30 @@ final class PromotionAttributeValueMapper extends DataMapperFactory
|
|||
public const COLUMNS = [
|
||||
'marketing_promotion_attr_value_id' => ['name' => 'marketing_promotion_attr_value_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_value_default' => ['name' => 'marketing_promotion_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
|
||||
'marketing_promotion_attr_value_type' => ['name' => 'marketing_promotion_attr_value_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'marketing_promotion_attr_value_valueStr' => ['name' => 'marketing_promotion_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
|
||||
'marketing_promotion_attr_value_valueInt' => ['name' => 'marketing_promotion_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
|
||||
'marketing_promotion_attr_value_valueDec' => ['name' => 'marketing_promotion_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
|
||||
'marketing_promotion_attr_value_valueDat' => ['name' => 'marketing_promotion_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
|
||||
'marketing_promotion_attr_value_lang' => ['name' => 'marketing_promotion_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
'marketing_promotion_attr_value_country' => ['name' => 'marketing_promotion_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' => EventAttributeValueL11nMapper::class,
|
||||
'table' => 'task_attr_value_l11n',
|
||||
'self' => 'task_attr_value_l11n_value',
|
||||
'column' => 'content',
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
*/
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user