From 3bbe1887f8a77b839e34669bb47bdce20fe0da77 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 20 Nov 2021 17:10:10 +0100 Subject: [PATCH] todo implementations --- Admin/Install/db.json | 240 +++++++++++++++++- Models/AccountRelation.php | 85 +++++++ Models/AccountRelationMapper.php | 70 ++++++ Models/AccountRelationType.php | 30 +++ Models/AttributeValueType.php | 36 +++ Models/NullPromotionAttribute.php | 39 +++ Models/NullPromotionAttributeType.php | 38 +++ Models/NullPromotionAttributeTypeL11n.php | 38 +++ Models/NullPromotionAttributeValue.php | 38 +++ Models/Promotion.php | 92 ++++++- Models/PromotionAttribute.php | 104 ++++++++ Models/PromotionAttributeMapper.php | 74 ++++++ Models/PromotionAttributeType.php | 172 +++++++++++++ Models/PromotionAttributeTypeL11n.php | 136 +++++++++++ Models/PromotionAttributeTypeL11nMapper.php | 57 +++++ Models/PromotionAttributeTypeMapper.php | 83 +++++++ Models/PromotionAttributeValue.php | 255 ++++++++++++++++++++ Models/PromotionAttributeValueMapper.php | 62 +++++ Models/PromotionMapper.php | 20 +- tests/Models/PromotionMapperTest.php | 14 +- tests/Models/PromotionTest.php | 53 +--- 21 files changed, 1663 insertions(+), 73 deletions(-) create mode 100644 Models/AccountRelation.php create mode 100644 Models/AccountRelationMapper.php create mode 100644 Models/AccountRelationType.php create mode 100644 Models/AttributeValueType.php create mode 100644 Models/NullPromotionAttribute.php create mode 100644 Models/NullPromotionAttributeType.php create mode 100644 Models/NullPromotionAttributeTypeL11n.php create mode 100644 Models/NullPromotionAttributeValue.php create mode 100644 Models/PromotionAttribute.php create mode 100644 Models/PromotionAttributeMapper.php create mode 100644 Models/PromotionAttributeType.php create mode 100644 Models/PromotionAttributeTypeL11n.php create mode 100644 Models/PromotionAttributeTypeL11nMapper.php create mode 100644 Models/PromotionAttributeTypeMapper.php create mode 100644 Models/PromotionAttributeValue.php create mode 100644 Models/PromotionAttributeValueMapper.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 042bc94..d847eb5 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -27,18 +27,23 @@ "foreignTable": "calendar", "foreignKey": "calendar_id" }, - "marketing_promotion_costs": { - "name": "marketing_promotion_costs", + "marketing_promotion_budgetcosts": { + "name": "marketing_promotion_budgetcosts", "type": "INT", "null": false }, - "marketing_promotion_budget": { - "name": "marketing_promotion_budget", + "marketing_promotion_budgetearnings": { + "name": "marketing_promotion_budgetearnings", "type": "INT", "null": false }, - "marketing_promotion_earnings": { - "name": "marketing_promotion_earnings", + "marketing_promotion_actualcosts": { + "name": "marketing_promotion_actualcosts", + "type": "INT", + "null": false + }, + "marketing_promotion_actualearnings": { + "name": "marketing_promotion_actualearnings", "type": "INT", "null": false }, @@ -102,6 +107,37 @@ } } }, + "marketing_promotion_accountrel": { + "name": "marketing_promotion_accountrel", + "fields": { + "marketing_promotion_accountrel_id": { + "name": "marketing_promotion_accountrel_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_accountrel_promotion": { + "name": "marketing_promotion_accountrel_promotion", + "type": "INT", + "null": false, + "foreignTable": "marketing_promotion", + "foreignKey": "marketing_promotion_id" + }, + "marketing_promotion_accountrel_type": { + "name": "marketing_promotion_accountrel_type", + "type": "INT", + "null": false + }, + "marketing_promotion_accountrel_account": { + "name": "marketing_promotion_accountrel_account", + "type": "INT", + "null": false, + "foreignTable": "account", + "foreignKey": "account_id" + } + } + }, "marketing_promotion_task_relation": { "name": "marketing_promotion_task_relation", "fields": { @@ -127,5 +163,197 @@ "foreignKey": "marketing_promotion_id" } } + }, + "marketing_promotion_attr_type": { + "name": "marketing_promotion_attr_type", + "fields": { + "marketing_promotion_attr_type_id": { + "name": "marketing_promotion_attr_type_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_attr_type_name": { + "name": "marketing_promotion_attr_type_name", + "type": "VARCHAR(255)", + "null": false + }, + "marketing_promotion_attr_type_fields": { + "name": "marketing_promotion_attr_type_fields", + "type": "INT(11)", + "null": false + }, + "marketing_promotion_attr_type_custom": { + "name": "marketing_promotion_attr_type_custom", + "type": "TINYINT(1)", + "null": false + }, + "marketing_promotion_attr_type_required": { + "description": "Every promotion must have this attribute type if set to true.", + "name": "marketing_promotion_attr_type_required", + "type": "TINYINT(1)", + "null": false + }, + "marketing_promotion_attr_type_pattern": { + "description": "This is a regex validation pattern.", + "name": "marketing_promotion_attr_type_pattern", + "type": "VARCHAR(255)", + "null": false + } + } + }, + "marketing_promotion_attr_type_l11n": { + "name": "marketing_promotion_attr_type_l11n", + "fields": { + "marketing_promotion_attr_type_l11n_id": { + "name": "marketing_promotion_attr_type_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_attr_type_l11n_title": { + "name": "marketing_promotion_attr_type_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "marketing_promotion_attr_type_l11n_type": { + "name": "marketing_promotion_attr_type_l11n_type", + "type": "INT(11)", + "null": false, + "foreignTable": "marketing_promotion_attr_type", + "foreignKey": "marketing_promotion_attr_type_id" + }, + "marketing_promotion_attr_type_l11n_lang": { + "name": "marketing_promotion_attr_type_l11n_lang", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + } + } + }, + "marketing_promotion_attr_value": { + "name": "marketing_promotion_attr_value", + "fields": { + "marketing_promotion_attr_value_id": { + "name": "marketing_promotion_attr_value_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_attr_value_default": { + "name": "marketing_promotion_attr_value_default", + "type": "TINYINT(1)", + "null": false + }, + "marketing_promotion_attr_value_type": { + "name": "marketing_promotion_attr_value_type", + "type": "INT(11)", + "null": false + }, + "marketing_promotion_attr_value_valueStr": { + "name": "marketing_promotion_attr_value_valueStr", + "type": "VARCHAR(255)", + "null": true, + "default": null + }, + "marketing_promotion_attr_value_valueInt": { + "name": "marketing_promotion_attr_value_valueInt", + "type": "INT(11)", + "null": true, + "default": null + }, + "marketing_promotion_attr_value_valueDec": { + "name": "marketing_promotion_attr_value_valueDec", + "type": "DECIMAL(19,5)", + "null": true, + "default": null + }, + "marketing_promotion_attr_value_valueDat": { + "name": "marketing_promotion_attr_value_valueDat", + "type": "DATETIME", + "null": true, + "default": null + }, + "marketing_promotion_attr_value_lang": { + "name": "marketing_promotion_attr_value_lang", + "type": "VARCHAR(2)", + "null": true, + "default": null, + "foreignTable": "language", + "foreignKey": "language_639_1" + }, + "marketing_promotion_attr_value_country": { + "name": "marketing_promotion_attr_value_country", + "type": "VARCHAR(2)", + "null": true, + "default": null, + "foreignTable": "country", + "foreignKey": "country_code2" + } + } + }, + "marketing_promotion_attr_default": { + "name": "marketing_promotion_attr_default", + "fields": { + "marketing_promotion_attr_default_id": { + "name": "marketing_promotion_attr_default_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_attr_default_type": { + "name": "marketing_promotion_attr_default_type", + "type": "INT(11)", + "null": false, + "foreignTable": "marketing_promotion_attr_type", + "foreignKey": "marketing_promotion_attr_type_id" + }, + "marketing_promotion_attr_default_value": { + "name": "marketing_promotion_attr_default_value", + "type": "INT(11)", + "null": false, + "foreignTable": "marketing_promotion_attr_value", + "foreignKey": "marketing_promotion_attr_value_id" + } + } + }, + "marketing_promotion_attr": { + "name": "marketing_promotion_attr", + "fields": { + "marketing_promotion_attr_id": { + "name": "marketing_promotion_attr_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "marketing_promotion_attr_promotion": { + "name": "marketing_promotion_attr_promotion", + "type": "INT(11)", + "null": false, + "foreignTable": "marketing_promotion", + "foreignKey": "marketing_promotion_id" + }, + "marketing_promotion_attr_type": { + "name": "marketing_promotion_attr_type", + "type": "INT(11)", + "null": false, + "foreignTable": "marketing_promotion_attr_type", + "foreignKey": "marketing_promotion_attr_type_id" + }, + "marketing_promotion_attr_value": { + "name": "marketing_promotion_attr_value", + "type": "INT(11)", + "null": true, + "default": null, + "foreignTable": "marketing_promotion_attr_value", + "foreignKey": "marketing_promotion_attr_value_id" + } + } } } \ No newline at end of file diff --git a/Models/AccountRelation.php b/Models/AccountRelation.php new file mode 100644 index 0000000..b4c4b7d --- /dev/null +++ b/Models/AccountRelation.php @@ -0,0 +1,85 @@ +account = new NullAccount(); + } + + /** + * Get id. + * + * @return int Model id + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } +} diff --git a/Models/AccountRelationMapper.php b/Models/AccountRelationMapper.php new file mode 100644 index 0000000..86b1177 --- /dev/null +++ b/Models/AccountRelationMapper.php @@ -0,0 +1,70 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'marketing_promotion_accountrel_id' => ['name' => 'marketing_promotion_accountrel_id', 'type' => 'int', 'internal' => 'id'], + 'marketing_promotion_accountrel_promotion' => ['name' => 'marketing_promotion_accountrel_promotion', 'type' => 'int', 'internal' => 'promotion'], + 'marketing_promotion_accountrel_type' => ['name' => 'marketing_promotion_accountrel_type', 'type' => 'int', 'internal' => 'type'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $ownsOne = [ + 'account' => [ + 'mapper' => AccountMapper::class, + 'external' => 'marketing_promotion_accountrel_account', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'marketing_promotion_accountrel'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'marketing_promotion_accountrel_id'; +} diff --git a/Models/AccountRelationType.php b/Models/AccountRelationType.php new file mode 100644 index 0000000..e326ef9 --- /dev/null +++ b/Models/AccountRelationType.php @@ -0,0 +1,30 @@ +id = $id; + } +} diff --git a/Models/NullPromotionAttributeType.php b/Models/NullPromotionAttributeType.php new file mode 100644 index 0000000..e7a2c1e --- /dev/null +++ b/Models/NullPromotionAttributeType.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/NullPromotionAttributeTypeL11n.php b/Models/NullPromotionAttributeTypeL11n.php new file mode 100644 index 0000000..adf5890 --- /dev/null +++ b/Models/NullPromotionAttributeTypeL11n.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/NullPromotionAttributeValue.php b/Models/NullPromotionAttributeValue.php new file mode 100644 index 0000000..e168fad --- /dev/null +++ b/Models/NullPromotionAttributeValue.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/Promotion.php b/Models/Promotion.php index a42b97b..da84148 100755 --- a/Models/Promotion.php +++ b/Models/Promotion.php @@ -79,29 +79,37 @@ class Promotion */ public Calendar $calendar; - /** - * Costs. + /** + * Budget costs. * * @var Money * @since 1.0.0 */ - public Money $costs; + public Money $budgetCosts; /** - * Budget. + * Budget earnings. * * @var Money * @since 1.0.0 */ - public Money $budget; + public Money $budgetEarnings; /** - * Earnings. + * Current total costs. * * @var Money * @since 1.0.0 */ - public Money $earnings; + public Money $actualCosts; + + /** + * Current total earnings. + * + * @var Money + * @since 1.0.0 + */ + public Money $actualEarnings; /** * Tasks. @@ -151,6 +159,22 @@ class Promotion */ public Account $createdBy; + /** + * Account relations + * + * @var AccountRelation[] + * @since 1.0.0 + */ + private array $accountRelations = []; + + /** + * Attributes. + * + * @var int[]|PromotionAttribute[] + * @since 1.0.0 + */ + private array $attributes = []; + /** * Constructor. * @@ -163,9 +187,10 @@ class Promotion $this->start = new \DateTime('now'); $this->end = (new \DateTime('now'))->modify('+1 month'); $this->calendar = new Calendar(); - $this->costs = new Money(); - $this->budget = new Money(); - $this->earnings = new Money(); + $this->actualCosts = new Money(); + $this->actualEarnings = new Money(); + $this->budgetCosts = new Money(); + $this->budgetEarnings = new Money(); $this->createdAt = new \DateTimeImmutable('now'); $this->createdBy = new NullAccount(); @@ -308,6 +333,46 @@ class Promotion return \count($this->tasks); } + /** + * Add account relation + * + * @param AccountRelation $accRel Account relation + * + * @return void + * + * @since 1.0.0 + */ + public function addAccount(AccountRelation $accRel) : void + { + $this->accountRelations[] = $accRel; + } + + /** + * Add attribute to item + * + * @param PromotionAttribute $attribute Note + * + * @return void + * + * @since 1.0.0 + */ + public function addAttribute(PromotionAttribute $attribute) : void + { + $this->attributes[] = $attribute; + } + + /** + * Get attributes + * + * @return int[]|PromotionAttribute[] + * + * @since 1.0.0 + */ + public function getAttributes() : array + { + return $this->attributes; + } + /** * {@inheritdoc} */ @@ -320,9 +385,10 @@ class Promotion 'name' => $this->name, 'description' => $this->description, 'calendar' => $this->calendar, - 'costs' => $this->costs, - 'budget' => $this->budget, - 'earnings' => $this->earnings, + 'budgetCosts' => $this->budgetCosts, + 'budgetEarnings' => $this->budgetEarnings, + 'actualCosts' => $this->actualCosts, + 'actualEarnings' => $this->actualEarnings, 'tasks' => $this->tasks, 'media' => $this->media, 'progress' => $this->progress, diff --git a/Models/PromotionAttribute.php b/Models/PromotionAttribute.php new file mode 100644 index 0000000..cc42aae --- /dev/null +++ b/Models/PromotionAttribute.php @@ -0,0 +1,104 @@ +type = new NullPromotionAttributeType(); + $this->value = new NullPromotionAttributeValue(); + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'item' => $this->item, + 'type' => $this->type, + 'value' => $this->value, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/PromotionAttributeMapper.php b/Models/PromotionAttributeMapper.php new file mode 100644 index 0000000..3205cb9 --- /dev/null +++ b/Models/PromotionAttributeMapper.php @@ -0,0 +1,74 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'marketing_promotion_attr_id' => ['name' => 'marketing_promotion_attr_id', 'type' => 'int', 'internal' => 'id'], + 'marketing_promotion_attr_promotion' => ['name' => 'marketing_promotion_attr_promotion', 'type' => 'int', 'internal' => 'promotion'], + 'marketing_promotion_attr_type' => ['name' => 'marketing_promotion_attr_type', 'type' => 'int', 'internal' => 'type'], + 'marketing_promotion_attr_value' => ['name' => 'marketing_promotion_attr_value', 'type' => 'int', 'internal' => 'value'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $ownsOne = [ + 'type' => [ + 'mapper' => PromotionAttributeTypeMapper::class, + 'external' => 'marketing_promotion_attr_type', + ], + 'value' => [ + 'mapper' => PromotionAttributeValueMapper::class, + 'external' => 'marketing_promotion_attr_value', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'marketing_promotion_attr'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'marketing_promotion_attr_id'; +} diff --git a/Models/PromotionAttributeType.php b/Models/PromotionAttributeType.php new file mode 100644 index 0000000..9429c94 --- /dev/null +++ b/Models/PromotionAttributeType.php @@ -0,0 +1,172 @@ +setL11n($name); + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Set l11n + * + * @param string|PromotionAttributeTypeL11n $l11n Tag article l11n + * @param string $lang Language + * + * @return void + * + * @since 1.0.0 + */ + public function setL11n(string | PromotionAttributeTypeL11n $l11n, string $lang = ISO639x1Enum::_EN) : void + { + if ($l11n instanceof PromotionAttributeTypeL11n) { + $this->l11n = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof PromotionAttributeTypeL11n) { + $this->l11n->title = $l11n; + } else { + $this->l11n = new PromotionAttributeTypeL11n(); + $this->l11n->title = $l11n; + $this->l11n->setLanguage($lang); + } + } + + /** + * @return string + * + * @since 1.0.0 + */ + public function getL11n() : string + { + return $this->l11n instanceof PromotionAttributeTypeL11n ? $this->l11n->title : $this->l11n; + } + + /** + * Set fields + * + * @param int $fields Fields + * + * @return void + * + * @since 1.0.0 + */ + public function setFields(int $fields) : void + { + $this->fields = $fields; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'validationPattern' => $this->validationPattern, + 'custom' => $this->custom, + 'isRequired' => $this->isRequired, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/PromotionAttributeTypeL11n.php b/Models/PromotionAttributeTypeL11n.php new file mode 100644 index 0000000..e7359bb --- /dev/null +++ b/Models/PromotionAttributeTypeL11n.php @@ -0,0 +1,136 @@ +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() + { + return $this->toArray(); + } +} diff --git a/Models/PromotionAttributeTypeL11nMapper.php b/Models/PromotionAttributeTypeL11nMapper.php new file mode 100644 index 0000000..facbfc8 --- /dev/null +++ b/Models/PromotionAttributeTypeL11nMapper.php @@ -0,0 +1,57 @@ + + * @since 1.0.0 + */ + protected static array $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_lang' => ['name' => 'marketing_promotion_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'marketing_promotion_attr_type_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'marketing_promotion_attr_type_l11n_id'; +} diff --git a/Models/PromotionAttributeTypeMapper.php b/Models/PromotionAttributeTypeMapper.php new file mode 100644 index 0000000..fec5cca --- /dev/null +++ b/Models/PromotionAttributeTypeMapper.php @@ -0,0 +1,83 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'marketing_promotion_attr_type_id' => ['name' => 'marketing_promotion_attr_type_id', 'type' => 'int', 'internal' => 'id'], + 'marketing_promotion_attr_type_name' => ['name' => 'marketing_promotion_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'marketing_promotion_attr_type_fields' => ['name' => 'marketing_promotion_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], + 'marketing_promotion_attr_type_custom' => ['name' => 'marketing_promotion_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'marketing_promotion_attr_type_pattern' => ['name' => 'marketing_promotion_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], + 'marketing_promotion_attr_type_required' => ['name' => 'marketing_promotion_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'l11n' => [ + 'mapper' => PromotionAttributeTypeL11nMapper::class, + 'table' => 'marketing_promotion_attr_type_l11n', + 'self' => 'marketing_promotion_attr_type_l11n_type', + 'column' => 'title', + 'conditional' => true, + 'external' => null, + ], + 'defaults' => [ + 'mapper' => PromotionAttributeValueMapper::class, + 'table' => 'marketing_promotion_attr_default', + 'self' => 'marketing_promotion_attr_default_type', + 'external' => 'marketing_promotion_attr_default_value', + 'conditional' => false, + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'marketing_promotion_attr_type'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'marketing_promotion_attr_type_id'; +} diff --git a/Models/PromotionAttributeValue.php b/Models/PromotionAttributeValue.php new file mode 100644 index 0000000..d41460d --- /dev/null +++ b/Models/PromotionAttributeValue.php @@ -0,0 +1,255 @@ +type = $type; + $this->language = $language; + + $this->setValue($value); + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Set value + * + * @param int|string|float|\DateTimeInterface $value Value + * + * @return void + * + * @since 1.0.0 + */ + public function setValue(mixed $value) : 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; + } + } + + /** + * Get value + * + * @return null|int|string|float|\DateTimeInterface + * + * @since 1.0.0 + */ + public function getValue() : mixed + { + if (!empty($this->valueStr)) { + return $this->valueStr; + } elseif (!empty($this->valueInt)) { + return $this->valueInt; + } elseif (!empty($this->valueDec)) { + return $this->valueDec; + } elseif ($this->valueDat instanceof \DateTimeInterface) { + return $this->valueDat; + } + + 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} + */ + public function toArray() : array + { + 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, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/PromotionAttributeValueMapper.php b/Models/PromotionAttributeValueMapper.php new file mode 100644 index 0000000..0b037a6 --- /dev/null +++ b/Models/PromotionAttributeValueMapper.php @@ -0,0 +1,62 @@ + + * @since 1.0.0 + */ + protected static array $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'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'marketing_promotion_attr_value'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'marketing_promotion_attr_value_id'; +} diff --git a/Models/PromotionMapper.php b/Models/PromotionMapper.php index 1beba0a..8d77f63 100755 --- a/Models/PromotionMapper.php +++ b/Models/PromotionMapper.php @@ -41,9 +41,10 @@ final class PromotionMapper extends DataMapperAbstract 'marketing_promotion_name' => ['name' => 'marketing_promotion_name', 'type' => 'string', 'internal' => 'name'], 'marketing_promotion_description' => ['name' => 'marketing_promotion_description', 'type' => 'string', 'internal' => 'description'], 'marketing_promotion_calendar' => ['name' => 'marketing_promotion_calendar', 'type' => 'int', 'internal' => 'calendar'], - 'marketing_promotion_costs' => ['name' => 'marketing_promotion_costs', 'type' => 'Serializable', 'internal' => 'costs'], - 'marketing_promotion_budget' => ['name' => 'marketing_promotion_budget', 'type' => 'Serializable', 'internal' => 'budget'], - 'marketing_promotion_earnings' => ['name' => 'marketing_promotion_earnings', 'type' => 'Serializable', 'internal' => 'earnings'], + 'marketing_promotion_budgetcosts' => ['name' => 'marketing_promotion_budgetcosts', 'type' => 'Serializable', 'internal' => 'budgetCosts'], + 'marketing_promotion_budgetearnings' => ['name' => 'marketing_promotion_budgetearnings', 'type' => 'Serializable', 'internal' => 'budgetEarnings'], + 'marketing_promotion_actualcosts' => ['name' => 'marketing_promotion_actualcosts', 'type' => 'Serializable', 'internal' => 'actualCosts'], + 'marketing_promotion_actualearnings' => ['name' => 'marketing_promotion_actualearnings', 'type' => 'Serializable', 'internal' => 'actualEarnings'], 'marketing_promotion_start' => ['name' => 'marketing_promotion_start', 'type' => 'DateTime', 'internal' => 'start'], 'marketing_promotion_end' => ['name' => 'marketing_promotion_end', 'type' => 'DateTime', 'internal' => 'end'], 'marketing_promotion_progress' => ['name' => 'marketing_promotion_progress', 'type' => 'int', 'internal' => 'progress'], @@ -71,6 +72,19 @@ final class PromotionMapper extends DataMapperAbstract 'external' => 'marketing_promotion_media_dst', 'self' => 'marketing_promotion_media_src', ], + 'accountRelations' => [ + 'mapper' => AccountRelationMapper::class, + 'table' => 'marketing_promotion_accountrel', + 'self' => 'marketing_promotion_accountrel_promotion', + 'external' => null, + ], + 'attributes' => [ + 'mapper' => PromotionAttributeMapper::class, + 'table' => 'marketing_promotion_attr', + 'self' => 'marketing_promotion_attr_promotion', + 'conditional' => true, + 'external' => null, + ], ]; /** diff --git a/tests/Models/PromotionMapperTest.php b/tests/Models/PromotionMapperTest.php index 8ab2be1..3db687c 100755 --- a/tests/Models/PromotionMapperTest.php +++ b/tests/Models/PromotionMapperTest.php @@ -44,9 +44,10 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase $money = new Money(); $money->setString('1.23'); - $promotion->costs = $money; - $promotion->budget = $money; - $promotion->earnings = $money; + $promotion->budgetCosts = $money; + $promotion->budgetEarnings = $money; + $promotion->actualCosts = $money; + $promotion->actualEarnings = $money; $task = new Task(); $task->title = 'EventTask 1'; @@ -82,9 +83,10 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($promotion->countTasks(), $promotionR->countTasks()); self::assertEquals($promotion->start->format('Y-m-d'), $promotionR->start->format('Y-m-d')); self::assertEquals($promotion->end->format('Y-m-d'), $promotionR->end->format('Y-m-d')); - self::assertEquals($promotion->costs->getAmount(), $promotionR->costs->getAmount()); - self::assertEquals($promotion->budget->getAmount(), $promotionR->budget->getAmount()); - self::assertEquals($promotion->earnings->getAmount(), $promotionR->earnings->getAmount()); + self::assertEquals($promotion->budgetCosts->getAmount(), $promotionR->budgetCosts->getAmount()); + self::assertEquals($promotion->budgetEarnings->getAmount(), $promotionR->budgetEarnings->getAmount()); + self::assertEquals($promotion->actualCosts->getAmount(), $promotionR->actualCosts->getAmount()); + self::assertEquals($promotion->actualEarnings->getAmount(), $promotionR->actualEarnings->getAmount()); self::assertEquals($promotion->progress, $promotionR->progress); self::assertEquals($promotion->getProgressType(), $promotionR->getProgressType()); diff --git a/tests/Models/PromotionTest.php b/tests/Models/PromotionTest.php index 5e2ff36..7edc8a1 100755 --- a/tests/Models/PromotionTest.php +++ b/tests/Models/PromotionTest.php @@ -45,9 +45,10 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $this->promotion->calendar); self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->promotion->start->format('Y-m-d')); self::assertEquals((new \DateTime('now'))->modify('+1 month')->format('Y-m-d'), $this->promotion->end->format('Y-m-d')); - self::assertEquals(0, $this->promotion->costs->getInt()); - self::assertEquals(0, $this->promotion->budget->getInt()); - self::assertEquals(0, $this->promotion->earnings->getInt()); + self::assertEquals(0, $this->promotion->budgetCosts->getInt()); + self::assertEquals(0, $this->promotion->budgetEarnings->getInt()); + self::assertEquals(0, $this->promotion->actualCosts->getInt()); + self::assertEquals(0, $this->promotion->actualEarnings->getInt()); self::assertFalse($this->promotion->removeTask(2)); self::assertEmpty($this->promotion->getTasks()); self::assertEmpty($this->promotion->getMedia()); @@ -56,45 +57,6 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase self::assertEquals(ProgressType::MANUAL, $this->promotion->getProgressType()); } - /** - * @covers Modules\Marketing\Models\Promotion - * @group module - */ - public function testCostsInputOutput() : void - { - $money = new Money(); - $money->setString('1.23'); - - $this->promotion->costs = $money; - self::assertEquals($money->getAmount(), $this->promotion->costs->getAmount()); - } - - /** - * @covers Modules\Marketing\Models\Promotion - * @group module - */ - public function testBudgetInputOutput() : void - { - $money = new Money(); - $money->setString('1.23'); - - $this->promotion->budget = $money; - self::assertEquals($money->getAmount(), $this->promotion->budget->getAmount()); - } - - /** - * @covers Modules\Marketing\Models\Promotion - * @group module - */ - public function testEarningsInputOutput() : void - { - $money = new Money(); - $money->setString('1.23'); - - $this->promotion->earnings = $money; - self::assertEquals($money->getAmount(), $this->promotion->earnings->getAmount()); - } - /** * @covers Modules\Marketing\Models\Promotion * @group module @@ -168,9 +130,10 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase 'end' => $this->promotion->end, 'name' => 'Name', 'description' => 'Description', - 'costs' => new Money(), - 'budget' => new Money(), - 'earnings' => new Money(), + 'budgetCosts' => new Money(), + 'budgetEarnings' => new Money(), + 'actualCosts' => new Money(), + 'actualEarnings' => new Money(), 'tasks' => [], 'media' => [], 'progress' => 10,