todo implementations

This commit is contained in:
Dennis Eichhorn 2021-11-20 17:10:10 +01:00
parent 0e4eb561d6
commit 3bbe1887f8
21 changed files with 1663 additions and 73 deletions

View File

@ -27,18 +27,23 @@
"foreignTable": "calendar", "foreignTable": "calendar",
"foreignKey": "calendar_id" "foreignKey": "calendar_id"
}, },
"marketing_promotion_costs": { "marketing_promotion_budgetcosts": {
"name": "marketing_promotion_costs", "name": "marketing_promotion_budgetcosts",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"marketing_promotion_budget": { "marketing_promotion_budgetearnings": {
"name": "marketing_promotion_budget", "name": "marketing_promotion_budgetearnings",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"marketing_promotion_earnings": { "marketing_promotion_actualcosts": {
"name": "marketing_promotion_earnings", "name": "marketing_promotion_actualcosts",
"type": "INT",
"null": false
},
"marketing_promotion_actualearnings": {
"name": "marketing_promotion_actualearnings",
"type": "INT", "type": "INT",
"null": false "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": { "marketing_promotion_task_relation": {
"name": "marketing_promotion_task_relation", "name": "marketing_promotion_task_relation",
"fields": { "fields": {
@ -127,5 +163,197 @@
"foreignKey": "marketing_promotion_id" "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"
}
}
} }
} }

View File

@ -0,0 +1,85 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/**
* Promotion class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class AccountRelation
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Promotion
*
* @var int
* @since 1.0.0
*/
public int $promotion = 0;
/**
* Account
*
* @var Account
* @since 1.0.0
*/
public Account $account;
/**
* Account relation type
*
* @var int
* @since 1.0.0
*/
public int $type = AccountRelationType::CUSTOMER;
/**
* Constructor.
*
* @param string $name Event name/title
*
* @since 1.0.0
*/
public function __construct()
{
$this->account = new NullAccount();
}
/**
* Get id.
*
* @return int Model id
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Mapper class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class AccountRelationMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @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';
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Account relation type enum.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class AccountRelationType extends Enum
{
public const CUSTOMER = 1;
}

View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Attribute value type enum.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class AttributeValueType extends Enum
{
public const _INT = 1;
public const _STRING = 2;
public const _FLOAT = 3;
public const _DATETIME = 4;
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
/**
* Null model
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullPromotionAttribute extends PromotionAttribute
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
parent::__construct();
$this->id = $id;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
/**
* Null model
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullPromotionAttributeType extends PromotionAttributeType
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
/**
* Null model
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @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;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
/**
* Null model
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullPromotionAttributeValue extends PromotionAttributeValue
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
}

View File

@ -79,29 +79,37 @@ class Promotion
*/ */
public Calendar $calendar; public Calendar $calendar;
/** /**
* Costs. * Budget costs.
* *
* @var Money * @var Money
* @since 1.0.0 * @since 1.0.0
*/ */
public Money $costs; public Money $budgetCosts;
/** /**
* Budget. * Budget earnings.
* *
* @var Money * @var Money
* @since 1.0.0 * @since 1.0.0
*/ */
public Money $budget; public Money $budgetEarnings;
/** /**
* Earnings. * Current total costs.
* *
* @var Money * @var Money
* @since 1.0.0 * @since 1.0.0
*/ */
public Money $earnings; public Money $actualCosts;
/**
* Current total earnings.
*
* @var Money
* @since 1.0.0
*/
public Money $actualEarnings;
/** /**
* Tasks. * Tasks.
@ -151,6 +159,22 @@ class Promotion
*/ */
public Account $createdBy; 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. * Constructor.
* *
@ -163,9 +187,10 @@ class Promotion
$this->start = new \DateTime('now'); $this->start = new \DateTime('now');
$this->end = (new \DateTime('now'))->modify('+1 month'); $this->end = (new \DateTime('now'))->modify('+1 month');
$this->calendar = new Calendar(); $this->calendar = new Calendar();
$this->costs = new Money(); $this->actualCosts = new Money();
$this->budget = new Money(); $this->actualEarnings = new Money();
$this->earnings = new Money(); $this->budgetCosts = new Money();
$this->budgetEarnings = new Money();
$this->createdAt = new \DateTimeImmutable('now'); $this->createdAt = new \DateTimeImmutable('now');
$this->createdBy = new NullAccount(); $this->createdBy = new NullAccount();
@ -308,6 +333,46 @@ class Promotion
return \count($this->tasks); 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} * {@inheritdoc}
*/ */
@ -320,9 +385,10 @@ class Promotion
'name' => $this->name, 'name' => $this->name,
'description' => $this->description, 'description' => $this->description,
'calendar' => $this->calendar, 'calendar' => $this->calendar,
'costs' => $this->costs, 'budgetCosts' => $this->budgetCosts,
'budget' => $this->budget, 'budgetEarnings' => $this->budgetEarnings,
'earnings' => $this->earnings, 'actualCosts' => $this->actualCosts,
'actualEarnings' => $this->actualEarnings,
'tasks' => $this->tasks, 'tasks' => $this->tasks,
'media' => $this->media, 'media' => $this->media,
'progress' => $this->progress, 'progress' => $this->progress,

View File

@ -0,0 +1,104 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Contract\ArrayableInterface;
/**
* Promotion class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class PromotionAttribute implements \JsonSerializable, ArrayableInterface
{
/**
* Id.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Promotion this attribute belongs to
*
* @var int
* @since 1.0.0
*/
public int $promotion = 0;
/**
* Attribute type the attribute belongs to
*
* @var PromotionAttributeType
* @since 1.0.0
*/
public PromotionAttributeType $type;
/**
* Attribute value the attribute belongs to
*
* @var PromotionAttributeValue
* @since 1.0.0
*/
public PromotionAttributeValue $value;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->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();
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Promotion mapper class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class PromotionAttributeMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @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';
}

View File

@ -0,0 +1,172 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* Promotion Attribute Type class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class PromotionAttributeType implements \JsonSerializable, ArrayableInterface
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
public string $name = ''; // @todo: currently not filled, should be used as identifier or if not required removed (at the moment it seems like it is useless?!)
/**
* Which field data type is required (string, int, ...) in the value
*
* @var int
* @since 1.0.0
*/
protected int $fields = 0;
/**
* Is a custom value allowed (e.g. custom string)
*
* @var bool
* @since 1.0.0
*/
public bool $custom = false;
public string $validationPattern = '';
public bool $isRequired = false;
/**
* Localization
*
* @var PromotionAttributeTypeL11n
*/
private string | PromotionAttributeTypeL11n $l11n;
/**
* Possible default attribute values
*
* @var array
*/
private array $defaults = [];
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->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();
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* Promotion class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class PromotionAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
{
/**
* 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()
{
return $this->toArray();
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Promotion mapper class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class PromotionAttributeTypeL11nMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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';
}

View File

@ -0,0 +1,83 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Promotion mapper class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class PromotionAttributeTypeMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @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';
}

View File

@ -0,0 +1,255 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
/**
* Promotion attribute value class.
*
* The relation with the type/item is defined in the PromotionAttribute class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class PromotionAttributeValue implements \JsonSerializable, ArrayableInterface
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Type of the attribute
*
* @var int
* @since 1.0.0
*/
public int $type = 0;
/**
* Int value
*
* @var null|int
* @since 1.0.0
*/
public ?int $valueInt = null;
/**
* String value
*
* @var null|string
* @since 1.0.0
*/
public ?string $valueStr = null;
/**
* Decimal value
*
* @var null|float
* @since 1.0.0
*/
public ?float $valueDec = null;
/**
* DateTime value
*
* @var null|\DateTimeInterface
* @since 1.0.0
*/
public ?\DateTimeInterface $valueDat = null;
/**
* Is a default value which can be selected
*
* @var bool
* @since 1.0.0
*/
public bool $isDefault = false;
/**
* Language
*
* @var string
* @since 1.0.0
*/
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);
}
/**
* 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();
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Marketing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https: //orange-management.org
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Promotion mapper class.
*
* @package Modules\Marketing\Models
* @license OMS License 1.0
* @link https: //orange-management.org
* @since 1.0.0
*/
final class PromotionAttributeValueMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @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';
}

View File

@ -41,9 +41,10 @@ final class PromotionMapper extends DataMapperAbstract
'marketing_promotion_name' => ['name' => 'marketing_promotion_name', 'type' => 'string', 'internal' => 'name'], 'marketing_promotion_name' => ['name' => 'marketing_promotion_name', 'type' => 'string', 'internal' => 'name'],
'marketing_promotion_description' => ['name' => 'marketing_promotion_description', 'type' => 'string', 'internal' => 'description'], 'marketing_promotion_description' => ['name' => 'marketing_promotion_description', 'type' => 'string', 'internal' => 'description'],
'marketing_promotion_calendar' => ['name' => 'marketing_promotion_calendar', 'type' => 'int', 'internal' => 'calendar'], 'marketing_promotion_calendar' => ['name' => 'marketing_promotion_calendar', 'type' => 'int', 'internal' => 'calendar'],
'marketing_promotion_costs' => ['name' => 'marketing_promotion_costs', 'type' => 'Serializable', 'internal' => 'costs'], 'marketing_promotion_budgetcosts' => ['name' => 'marketing_promotion_budgetcosts', 'type' => 'Serializable', 'internal' => 'budgetCosts'],
'marketing_promotion_budget' => ['name' => 'marketing_promotion_budget', 'type' => 'Serializable', 'internal' => 'budget'], 'marketing_promotion_budgetearnings' => ['name' => 'marketing_promotion_budgetearnings', 'type' => 'Serializable', 'internal' => 'budgetEarnings'],
'marketing_promotion_earnings' => ['name' => 'marketing_promotion_earnings', 'type' => 'Serializable', 'internal' => 'earnings'], '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_start' => ['name' => 'marketing_promotion_start', 'type' => 'DateTime', 'internal' => 'start'],
'marketing_promotion_end' => ['name' => 'marketing_promotion_end', 'type' => 'DateTime', 'internal' => 'end'], 'marketing_promotion_end' => ['name' => 'marketing_promotion_end', 'type' => 'DateTime', 'internal' => 'end'],
'marketing_promotion_progress' => ['name' => 'marketing_promotion_progress', 'type' => 'int', 'internal' => 'progress'], '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', 'external' => 'marketing_promotion_media_dst',
'self' => 'marketing_promotion_media_src', '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,
],
]; ];
/** /**

View File

@ -44,9 +44,10 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
$money = new Money(); $money = new Money();
$money->setString('1.23'); $money->setString('1.23');
$promotion->costs = $money; $promotion->budgetCosts = $money;
$promotion->budget = $money; $promotion->budgetEarnings = $money;
$promotion->earnings = $money; $promotion->actualCosts = $money;
$promotion->actualEarnings = $money;
$task = new Task(); $task = new Task();
$task->title = 'EventTask 1'; $task->title = 'EventTask 1';
@ -82,9 +83,10 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($promotion->countTasks(), $promotionR->countTasks()); self::assertEquals($promotion->countTasks(), $promotionR->countTasks());
self::assertEquals($promotion->start->format('Y-m-d'), $promotionR->start->format('Y-m-d')); 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->end->format('Y-m-d'), $promotionR->end->format('Y-m-d'));
self::assertEquals($promotion->costs->getAmount(), $promotionR->costs->getAmount()); self::assertEquals($promotion->budgetCosts->getAmount(), $promotionR->budgetCosts->getAmount());
self::assertEquals($promotion->budget->getAmount(), $promotionR->budget->getAmount()); self::assertEquals($promotion->budgetEarnings->getAmount(), $promotionR->budgetEarnings->getAmount());
self::assertEquals($promotion->earnings->getAmount(), $promotionR->earnings->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->progress, $promotionR->progress);
self::assertEquals($promotion->getProgressType(), $promotionR->getProgressType()); self::assertEquals($promotion->getProgressType(), $promotionR->getProgressType());

View File

@ -45,9 +45,10 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $this->promotion->calendar); 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'))->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((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->budgetCosts->getInt());
self::assertEquals(0, $this->promotion->budget->getInt()); self::assertEquals(0, $this->promotion->budgetEarnings->getInt());
self::assertEquals(0, $this->promotion->earnings->getInt()); self::assertEquals(0, $this->promotion->actualCosts->getInt());
self::assertEquals(0, $this->promotion->actualEarnings->getInt());
self::assertFalse($this->promotion->removeTask(2)); self::assertFalse($this->promotion->removeTask(2));
self::assertEmpty($this->promotion->getTasks()); self::assertEmpty($this->promotion->getTasks());
self::assertEmpty($this->promotion->getMedia()); self::assertEmpty($this->promotion->getMedia());
@ -56,45 +57,6 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase
self::assertEquals(ProgressType::MANUAL, $this->promotion->getProgressType()); 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 * @covers Modules\Marketing\Models\Promotion
* @group module * @group module
@ -168,9 +130,10 @@ final class PromotionTest extends \PHPUnit\Framework\TestCase
'end' => $this->promotion->end, 'end' => $this->promotion->end,
'name' => 'Name', 'name' => 'Name',
'description' => 'Description', 'description' => 'Description',
'costs' => new Money(), 'budgetCosts' => new Money(),
'budget' => new Money(), 'budgetEarnings' => new Money(),
'earnings' => new Money(), 'actualCosts' => new Money(),
'actualEarnings' => new Money(),
'tasks' => [], 'tasks' => [],
'media' => [], 'media' => [],
'progress' => 10, 'progress' => 10,