From 36012aab4ef7a22f93e554ce94ae2237abbc0b3e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 25 Apr 2023 01:51:28 +0000 Subject: [PATCH] bug fixes and subscription improvements --- Controller/ApiController.php | 31 ++-- Models/NullUnitAttribute.php | 47 ------ Models/NullUnitAttributeType.php | 46 ------ Models/NullUnitAttributeValue.php | 46 ------ Models/Unit.php | 56 +------ Models/UnitAttribute.php | 102 ------------ Models/UnitAttributeMapper.php | 13 +- Models/UnitAttributeType.php | 216 -------------------------- Models/UnitAttributeTypeMapper.php | 11 +- Models/UnitAttributeValue.php | 230 ---------------------------- Models/UnitAttributeValueMapper.php | 11 +- 11 files changed, 51 insertions(+), 758 deletions(-) delete mode 100755 Models/NullUnitAttribute.php delete mode 100755 Models/NullUnitAttributeType.php delete mode 100755 Models/NullUnitAttributeValue.php delete mode 100755 Models/UnitAttribute.php delete mode 100755 Models/UnitAttributeType.php delete mode 100755 Models/UnitAttributeValue.php diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7222fda..9799948 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -20,6 +20,11 @@ use Modules\Admin\Models\Address; use Modules\Admin\Models\AddressMapper; use Modules\Admin\Models\NullAddress; use Modules\Admin\Models\SettingsEnum as ModelsSettingsEnum; +use Modules\Attribute\Models\Attribute; +use Modules\Attribute\Models\AttributeType; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeType; +use Modules\Attribute\Models\NullAttributeValue; use Modules\Media\Models\PathSettings; use Modules\Organization\Models\Department; use Modules\Organization\Models\DepartmentMapper; @@ -889,18 +894,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return UnitAttribute + * @return Attribute * * @since 1.0.0 */ - private function createUnitAttributeFromRequest(RequestAbstract $request) : UnitAttribute + private function createUnitAttributeFromRequest(RequestAbstract $request) : Attribute { - $attribute = new UnitAttribute(); - $attribute->unit = (int) $request->getData('unit'); - $attribute->type = new NullUnitAttributeType((int) $request->getData('type')); + $attribute = new Attribute(); + $attribute->ref = (int) $request->getData('unit'); + $attribute->type = new NullAttributeType((int) $request->getData('type')); if ($request->hasData('value')) { - $attribute->value = new NullUnitAttributeValue((int) $request->getData('value')); + $attribute->value = new NullAttributeValue((int) $request->getData('value')); } else { $newRequest = clone $request; $newRequest->setData('value', $request->getData('custom'), true); @@ -1037,13 +1042,13 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return UnitAttributeType + * @return AttributeType * * @since 1.0.0 */ - private function createUnitAttributeTypeFromRequest(RequestAbstract $request) : UnitAttributeType + private function createUnitAttributeTypeFromRequest(RequestAbstract $request) : AttributeType { - $attrType = new UnitAttributeType($request->getDataString('name') ?? ''); + $attrType = new AttributeType($request->getDataString('name') ?? ''); $attrType->datatype = $request->getDataInt('datatype') ?? 0; $attrType->custom = $request->getDataBool('custom') ?? false; $attrType->isRequired = (bool) ($request->getData('is_required') ?? false); @@ -1117,18 +1122,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return UnitAttributeValue + * @return AttributeValue * * @since 1.0.0 */ - private function createUnitAttributeValueFromRequest(RequestAbstract $request) : UnitAttributeValue + private function createUnitAttributeValueFromRequest(RequestAbstract $request) : AttributeValue { - /** @var UnitAttributeType $type */ + /** @var AttributeType $type */ $type = UnitAttributeTypeMapper::get() ->where('id', $request->getDataInt('type') ?? 0) ->execute(); - $attrValue = new UnitAttributeValue(); + $attrValue = new AttributeValue(); $attrValue->isDefault = $request->getDataBool('default') ?? false; $attrValue->setValue($request->getData('value'), $type->datatype); diff --git a/Models/NullUnitAttribute.php b/Models/NullUnitAttribute.php deleted file mode 100755 index fa117b7..0000000 --- a/Models/NullUnitAttribute.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullUnitAttributeType.php b/Models/NullUnitAttributeType.php deleted file mode 100755 index 54dc339..0000000 --- a/Models/NullUnitAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullUnitAttributeValue.php b/Models/NullUnitAttributeValue.php deleted file mode 100755 index c3b3905..0000000 --- a/Models/NullUnitAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Unit.php b/Models/Unit.php index c57ad30..27c0e73 100755 --- a/Models/Unit.php +++ b/Models/Unit.php @@ -89,14 +89,6 @@ class Unit implements \JsonSerializable private array $address = []; - /** - * Attributes. - * - * @var UnitAttribute[] - * @since 1.0.0 - */ - private array $attributes = []; - /** * Constructor. * @@ -121,52 +113,6 @@ class Unit implements \JsonSerializable return $this->id; } - /** - * Add attribute to client - * - * @param UnitAttribute $attribute Attribute - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(UnitAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return UnitAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - - /** - * Get attribute - * - * @param string $attrName Attribute name - * - * @return null|UnitAttribute - * - * @since 1.0.0 - */ - public function getAttribute(string $attrName) : ?UnitAttribute - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $attrName) { - return $attribute->value; - } - } - - return null; - } - /** * Get status * @@ -228,4 +174,6 @@ class Unit implements \JsonSerializable { return $this->toArray(); } + + use \Modules\Attribute\Models\AttributeHolderTrait; } diff --git a/Models/UnitAttribute.php b/Models/UnitAttribute.php deleted file mode 100755 index dfccd44..0000000 --- a/Models/UnitAttribute.php +++ /dev/null @@ -1,102 +0,0 @@ -type = new NullUnitAttributeType(); - $this->value = new NullUnitAttributeValue(); - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'unit' => $this->unit, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/UnitAttributeMapper.php b/Models/UnitAttributeMapper.php index 8822e7c..f4fb587 100755 --- a/Models/UnitAttributeMapper.php +++ b/Models/UnitAttributeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Organization\Models; +use Modules\Attribute\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; * @link https://jingga.app * @since 1.0.0 * - * @template T of UnitAttribute + * @template T of Attribute * @extends DataMapperFactory */ final class UnitAttributeMapper extends DataMapperFactory @@ -37,7 +38,7 @@ final class UnitAttributeMapper extends DataMapperFactory */ public const COLUMNS = [ 'unit_attr_id' => ['name' => 'unit_attr_id', 'type' => 'int', 'internal' => 'id'], - 'unit_attr_unit' => ['name' => 'unit_attr_unit', 'type' => 'int', 'internal' => 'unit'], + 'unit_attr_unit' => ['name' => 'unit_attr_unit', 'type' => 'int', 'internal' => 'ref'], 'unit_attr_type' => ['name' => 'unit_attr_type', 'type' => 'int', 'internal' => 'type'], 'unit_attr_value' => ['name' => 'unit_attr_value', 'type' => 'int', 'internal' => 'value'], ]; @@ -59,6 +60,14 @@ final class UnitAttributeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Attribute::class; + /** * Primary table. * diff --git a/Models/UnitAttributeType.php b/Models/UnitAttributeType.php deleted file mode 100755 index 1f19c09..0000000 --- a/Models/UnitAttributeType.php +++ /dev/null @@ -1,216 +0,0 @@ -name = $name; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - public function getDefaultByValue(mixed $value) : UnitAttributeValue - { - foreach ($this->defaults as $default) { - if ($default->getValue() === $value) { - return $default; - } - } - - return new NullUnitAttributeValue(); - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set fields - * - * @param int $fields Fields - * - * @return void - * - * @since 1.0.0 - */ - public function setFields(int $fields) : void - { - $this->fields = $fields; - } - - /** - * Get default values - * - * @return array - * - * @sicne 1.0.0 - */ - public function getDefaults() : array - { - return $this->defaults; - } - - /** - * {@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() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/UnitAttributeTypeMapper.php b/Models/UnitAttributeTypeMapper.php index c045bfc..61a9dd9 100755 --- a/Models/UnitAttributeTypeMapper.php +++ b/Models/UnitAttributeTypeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Organization\Models; +use Modules\Attribute\Models\AttributeType; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; * @link https://jingga.app * @since 1.0.0 * - * @template T of UnitAttributeType + * @template T of AttributeType * @extends DataMapperFactory */ final class UnitAttributeTypeMapper extends DataMapperFactory @@ -67,6 +68,14 @@ final class UnitAttributeTypeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeType::class; + /** * Primary table. * diff --git a/Models/UnitAttributeValue.php b/Models/UnitAttributeValue.php deleted file mode 100755 index c8e8dde..0000000 --- a/Models/UnitAttributeValue.php +++ /dev/null @@ -1,230 +0,0 @@ -id; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; - $this->l11n->setLanguage($lang); - } - } - - /** - * Get localization - * - * @return null|string - * - * @since 1.0.0 - */ - public function getL11n() : ?string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set value - * - * @param int|string|float $value Value - * @param int $datatype Datatype - * - * @return void - * - * @since 1.0.0 - */ - public function setValue(mixed $value, int $datatype) : void - { - 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((string) $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; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'valueInt' => $this->valueInt, - 'valueStr' => $this->valueStr, - 'valueDec' => $this->valueDec, - 'valueDat' => $this->valueDat, - 'isDefault' => $this->isDefault, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/UnitAttributeValueMapper.php b/Models/UnitAttributeValueMapper.php index 69245f5..8b21f26 100755 --- a/Models/UnitAttributeValueMapper.php +++ b/Models/UnitAttributeValueMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Organization\Models; +use Modules\Attribute\Models\AttributeValue; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; * @link https://jingga.app * @since 1.0.0 * - * @template T of UnitAttributeValue + * @template T of AttributeValue * @extends DataMapperFactory */ final class UnitAttributeValueMapper extends DataMapperFactory @@ -62,6 +63,14 @@ final class UnitAttributeValueMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeValue::class; + /** * Primary table. *