From 38bacc3bc5d19e4430234fc51463584183b784cf Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 24 May 2023 18:11:37 +0000 Subject: [PATCH] bug fixes and item management improvements --- Models/Attribute.php | 2 +- Models/Attribute.php.out | 121 +++++++++++++++++++++++++++++++++ Models/AttributeType.php | 12 ++-- Models/AttributeValue.php | 8 +-- Theme/Backend/Lang/en.lang.php | 11 ++- 5 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 Models/Attribute.php.out diff --git a/Models/Attribute.php b/Models/Attribute.php index 5bb35b8..af3fa63 100755 --- a/Models/Attribute.php +++ b/Models/Attribute.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\Attribute\Models; /** - * class. + * Attribute class. * * @package Modules\Attribute\Models * @license OMS License 2.0 diff --git a/Models/Attribute.php.out b/Models/Attribute.php.out new file mode 100644 index 0000000..823a5c2 --- /dev/null +++ b/Models/Attribute.php.out @@ -0,0 +1,121 @@ +type = new NullAttributeType(); + $this->value = new NullAttributeValue(); + } + + /** + * Creates a deep clone of the object. + * + * @return self + * + * @since 1.0.0 + */ + public function deepClone() : self + { + $clone = clone $this; + $clone->value = clone $this->value; + + return $clone; + } + + /** + * Returns the id of the attribute. + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Converts the attribute to an array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'ref' => $this->ref, + 'type' => $this->type, + 'value' => $this->value, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/AttributeType.php b/Models/AttributeType.php index f9938ff..b0f07b8 100755 --- a/Models/AttributeType.php +++ b/Models/AttributeType.php @@ -128,22 +128,22 @@ class AttributeType implements \JsonSerializable */ public function getDefaultByValue(mixed $value) : AttributeValue { - $value = null; + $mValue = null; if ($this->datatype === AttributeValueType::_STRING) { - $value = (string) $value; + $mValue = (string) $value; } elseif ($this->datatype === AttributeValueType::_INT || $this->datatype === AttributeValueType::_FLOAT_INT || $this->datatype === AttributeValueType::_BOOL ) { - $value = (int) $value; + $mValue = (int) $value; } elseif ($this->datatype === AttributeValueType::_FLOAT) { - $value = (float) $value; + $mValue = (float) $value; } elseif ($this->datatype === AttributeValueType::_DATETIME) { - $value = new \DateTime((string) $value); + $mValue = new \DateTime((string) $value); } foreach ($this->defaults as $default) { - if ($default->getValue() === $value) { + if ($default->getValue() === $mValue) { return $default; } } diff --git a/Models/AttributeValue.php b/Models/AttributeValue.php index e1c909a..dc3db4e 100755 --- a/Models/AttributeValue.php +++ b/Models/AttributeValue.php @@ -192,13 +192,13 @@ class AttributeValue implements \JsonSerializable */ public function getValue() : mixed { - if (!empty($this->valueStr)) { + if ($this->valueStr !== null) { return $this->valueStr; - } elseif (!empty($this->valueInt)) { + } elseif ($this->valueInt !== null) { return $this->valueInt; - } elseif (!empty($this->valueDec)) { + } elseif ($this->valueDec !== null) { return $this->valueDec; - } elseif ($this->valueDat instanceof \DateTimeInterface) { + } elseif ($this->valueDat !== null) { return $this->valueDat; } diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 9fa8447..a90c494 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -13,5 +13,14 @@ declare(strict_types=1); return ['Attribute' => [ - 'Accounts/Groups' => 'Accounts/Groups', + 'AttributeTypes' => 'Attribute Types', + 'Attribute' => 'Attribute', + 'Name' => 'Name', + 'Title' => 'Title', + 'Datatype' => 'Datatype', + 'Status' => 'Status', + 'DefaultValues' => 'Default Values', + 'Pattern' => 'Pattern', + 'IsRequired' => 'Is required?', + 'CustomValue' => 'Custom values allowed?', ]];