From 1d696915384e514530d9794fc7e001c30b1540ba Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 6 May 2023 11:42:05 +0000 Subject: [PATCH] make id public, organigram impl. media password/encryption, settings bug fix, Money->FloatInt change, ... --- Controller/ApiController.php | 2 +- Models/Attribute.php | 10 +++++++++- Models/AttributeHolderTrait.php | 6 +++--- Models/AttributeType.php | 22 ++++++++++++++++++---- Models/AttributeValue.php | 4 ++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9f4b1b3..1545f82 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -290,7 +290,7 @@ final class ApiController extends Controller $this->createModelRelation( $request->header->account, (int) $request->getData('type'), - $attrValue->getId(), + $attrValue->id, AttributeTypeMapper::class, 'defaults', '', $request->getOrigin() ); } diff --git a/Models/Attribute.php b/Models/Attribute.php index e0d495c..5bb35b8 100755 --- a/Models/Attribute.php +++ b/Models/Attribute.php @@ -30,7 +30,7 @@ class Attribute implements \JsonSerializable * @var int * @since 1.0.0 */ - protected int $id = 0; + public int $id = 0; /** * this attribute belongs to @@ -67,6 +67,14 @@ class Attribute implements \JsonSerializable $this->value = new NullAttributeValue(); } + public function deepClone() : self + { + $clone = clone $this; + $clone->value = clone $this->value; + + return $clone; + } + /** * Get id * diff --git a/Models/AttributeHolderTrait.php b/Models/AttributeHolderTrait.php index ba1c343..56f1d2d 100755 --- a/Models/AttributeHolderTrait.php +++ b/Models/AttributeHolderTrait.php @@ -84,11 +84,11 @@ trait AttributeHolderTrait * * @param string $attrName Attribute name * - * @return null|Attribute + * @return Attribute * * @since 1.0.0 */ - public function getAttribute(string $attrName) : ?Attribute + public function getAttribute(string $attrName) : Attribute { foreach ($this->attributes as $attribute) { if ($attribute->type->name === $attrName) { @@ -96,6 +96,6 @@ trait AttributeHolderTrait } } - return null; + return new NullAttribute(); } } diff --git a/Models/AttributeType.php b/Models/AttributeType.php index b156a16..f9938ff 100755 --- a/Models/AttributeType.php +++ b/Models/AttributeType.php @@ -33,7 +33,7 @@ class AttributeType implements \JsonSerializable * @var int * @since 1.0.0 */ - protected int $id = 0; + public int $id = 0; /** * Name/string identifier by which it can be found/categorized @@ -49,7 +49,7 @@ class AttributeType implements \JsonSerializable * @var int * @since 1.0.0 */ - protected int $fields = 0; + public int $fields = 0; /** * Is a custom value allowed (e.g. custom string) @@ -76,14 +76,14 @@ class AttributeType implements \JsonSerializable * * @var BaseStringL11n */ - private string | BaseStringL11n $l11n = ''; + public string | BaseStringL11n $l11n = ''; /** * Possible default attribute values * * @var array */ - private array $defaults = []; + public array $defaults = []; /** * Default attribute value @@ -128,6 +128,20 @@ class AttributeType implements \JsonSerializable */ public function getDefaultByValue(mixed $value) : AttributeValue { + $value = null; + if ($this->datatype === AttributeValueType::_STRING) { + $value = (string) $value; + } elseif ($this->datatype === AttributeValueType::_INT + || $this->datatype === AttributeValueType::_FLOAT_INT + || $this->datatype === AttributeValueType::_BOOL + ) { + $value = (int) $value; + } elseif ($this->datatype === AttributeValueType::_FLOAT) { + $value = (float) $value; + } elseif ($this->datatype === AttributeValueType::_DATETIME) { + $value = new \DateTime((string) $value); + } + foreach ($this->defaults as $default) { if ($default->getValue() === $value) { return $default; diff --git a/Models/AttributeValue.php b/Models/AttributeValue.php index 600d013..e1c909a 100755 --- a/Models/AttributeValue.php +++ b/Models/AttributeValue.php @@ -35,7 +35,7 @@ class AttributeValue implements \JsonSerializable * @var int * @since 1.0.0 */ - protected int $id = 0; + public int $id = 0; /** * Depending attribute type @@ -106,7 +106,7 @@ class AttributeValue implements \JsonSerializable * * @var null|BaseStringL11n */ - private ?BaseStringL11n $l11n = null; + public ?BaseStringL11n $l11n = null; /** * Get id