diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php index 7fb4f72..c5ad418 100755 --- a/Models/AttributeValueType.php +++ b/Models/AttributeValueType.php @@ -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; } diff --git a/Models/NullProjectAttributeTypeL11n.php b/Models/NullProjectAttributeTypeL11n.php deleted file mode 100755 index 257742a..0000000 --- a/Models/NullProjectAttributeTypeL11n.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/ProjectAttributeTypeL11n.php b/Models/ProjectAttributeTypeL11n.php deleted file mode 100755 index 0367256..0000000 --- a/Models/ProjectAttributeTypeL11n.php +++ /dev/null @@ -1,135 +0,0 @@ -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(); - } -} diff --git a/Models/ProjectAttributeTypeL11nMapper.php b/Models/ProjectAttributeTypeL11nMapper.php index 3ef2184..1dcd353 100755 --- a/Models/ProjectAttributeTypeL11nMapper.php +++ b/Models/ProjectAttributeTypeL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ProjectManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Project mapper class. @@ -34,8 +35,8 @@ final class ProjectAttributeTypeL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'projectmanagement_project_attr_type_l11n_id' => ['name' => 'projectmanagement_project_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'projectmanagement_project_attr_type_l11n_title' => ['name' => 'projectmanagement_project_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'projectmanagement_project_attr_type_l11n_type' => ['name' => 'projectmanagement_project_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + 'projectmanagement_project_attr_type_l11n_title' => ['name' => 'projectmanagement_project_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'projectmanagement_project_attr_type_l11n_type' => ['name' => 'projectmanagement_project_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], 'projectmanagement_project_attr_type_l11n_lang' => ['name' => 'projectmanagement_project_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class ProjectAttributeTypeL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='projectmanagement_project_attr_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/ProjectAttributeTypeMapper.php b/Models/ProjectAttributeTypeMapper.php index 02bf426..138ff06 100755 --- a/Models/ProjectAttributeTypeMapper.php +++ b/Models/ProjectAttributeTypeMapper.php @@ -52,7 +52,7 @@ final class ProjectAttributeTypeMapper extends DataMapperFactory 'mapper' => ProjectAttributeTypeL11nMapper::class, 'table' => 'projectmanagement_project_attr_type_l11n', 'self' => 'projectmanagement_project_attr_type_l11n_type', - 'column' => 'title', + 'column' => 'content', 'external' => null, ], 'defaults' => [ diff --git a/Models/ProjectAttributeValue.php b/Models/ProjectAttributeValue.php index 6149bf5..ee9d77c 100755 --- a/Models/ProjectAttributeValue.php +++ b/Models/ProjectAttributeValue.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\ProjectManagement\Models; +use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Localization\ISO639x1Enum; @@ -38,12 +39,20 @@ class ProjectAttributeValue 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 ProjectAttributeValue 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 ProjectAttributeValue 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 ProjectAttributeValue 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 ProjectAttributeValue 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, ]; } diff --git a/Models/ProjectAttributeValueMapper.php b/Models/ProjectAttributeValueMapper.php index 76ded08..24e104b 100755 --- a/Models/ProjectAttributeValueMapper.php +++ b/Models/ProjectAttributeValueMapper.php @@ -35,15 +35,30 @@ final class ProjectAttributeValueMapper extends DataMapperFactory public const COLUMNS = [ 'projectmanagement_project_attr_value_id' => ['name' => 'projectmanagement_project_attr_value_id', 'type' => 'int', 'internal' => 'id'], 'projectmanagement_project_attr_value_default' => ['name' => 'projectmanagement_project_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'projectmanagement_project_attr_value_type' => ['name' => 'projectmanagement_project_attr_value_type', 'type' => 'int', 'internal' => 'type'], 'projectmanagement_project_attr_value_valueStr' => ['name' => 'projectmanagement_project_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], 'projectmanagement_project_attr_value_valueInt' => ['name' => 'projectmanagement_project_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], 'projectmanagement_project_attr_value_valueDec' => ['name' => 'projectmanagement_project_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], 'projectmanagement_project_attr_value_valueDat' => ['name' => 'projectmanagement_project_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], - 'projectmanagement_project_attr_value_lang' => ['name' => 'projectmanagement_project_attr_value_lang', 'type' => 'string', 'internal' => 'language'], - 'projectmanagement_project_attr_value_country' => ['name' => 'projectmanagement_project_attr_value_country', 'type' => 'string', 'internal' => 'country'], ]; + /** + * Has many relation. + * + * @var array + * @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. *