diff --git a/Controller/ApiController.php b/Controller/ApiController.php index f686e59..53d4025 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -16,20 +16,18 @@ namespace Modules\SupplierManagement\Controller; use Modules\Admin\Models\Account; use Modules\Admin\Models\Address; +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\MediaMapper; use Modules\Media\Models\PathSettings; -use Modules\Profile\Models\ContactElementMapper; -use Modules\Profile\Models\Profile; -use Modules\SupplierManagement\Models\NullSupplierAttributeType; -use Modules\SupplierManagement\Models\NullSupplierAttributeValue; use Modules\SupplierManagement\Models\NullSupplierL11nType; use Modules\SupplierManagement\Models\Supplier; -use Modules\SupplierManagement\Models\SupplierAttribute; use Modules\SupplierManagement\Models\SupplierAttributeMapper; -use Modules\SupplierManagement\Models\SupplierAttributeType; use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper; use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper; -use Modules\SupplierManagement\Models\SupplierAttributeValue; use Modules\SupplierManagement\Models\SupplierAttributeValueL11nMapper; use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; use Modules\SupplierManagement\Models\SupplierL11n; @@ -302,16 +300,16 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return SupplierAttribute + * @return Attribute * * @since 1.0.0 */ - private function createSupplierAttributeFromRequest(RequestAbstract $request) : SupplierAttribute + private function createSupplierAttributeFromRequest(RequestAbstract $request) : Attribute { - $attribute = new SupplierAttribute(); - $attribute->supplier = (int) $request->getData('supplier'); - $attribute->type = new NullSupplierAttributeType((int) $request->getData('type')); - $attribute->value = new NullSupplierAttributeValue((int) $request->getData('value')); + $attribute = new Attribute(); + $attribute->ref = (int) $request->getData('supplier'); + $attribute->type = new NullAttributeType((int) $request->getData('type')); + $attribute->value = new NullAttributeValue((int) $request->getData('value')); return $attribute; } @@ -440,13 +438,13 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return SupplierAttributeType + * @return AttributeType * * @since 1.0.0 */ - private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType + private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : AttributeType { - $attrType = new SupplierAttributeType($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); @@ -520,18 +518,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return SupplierAttributeValue + * @return AttributeValue * * @since 1.0.0 */ - private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : SupplierAttributeValue + private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : AttributeValue { - /** @var SupplierAttributeType $type */ + /** @var AttributeType $type */ $type = SupplierAttributeTypeMapper::get() ->where('id', $request->getDataInt('type') ?? 0) ->execute(); - $attrValue = new SupplierAttributeValue(); + $attrValue = new AttributeValue(); $attrValue->isDefault = $request->getDataBool('default') ?? false; $attrValue->setValue($request->getData('value'), $type->datatype); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index c323491..6148aa0 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -56,7 +56,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\SupplierManagement\Models\SupplierAttributeType[] $attributes */ + /** @var \Modules\Attribute\Models\AttributeType[] $attributes */ $attributes = SupplierAttributeTypeMapper::getAll() ->with('l11n') ->where('l11n/language', $response->getLanguage()) @@ -85,7 +85,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-value-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\SupplierManagement\Models\SupplierAttributeValue[] $attributes */ + /** @var \Modules\Attribute\Models\AttributeValue[] $attributes */ $attributes = SupplierAttributeValueMapper::getAll() ->with('l11n') ->where('l11n/language', $response->getLanguage()) @@ -114,7 +114,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\SupplierManagement\Models\SupplierAttributeType $attribute */ + /** @var \Modules\Attribute\Models\AttributeType $attribute */ $attribute = SupplierAttributeTypeMapper::get() ->with('l11n') ->where('id', (int) $request->getData('id')) diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php deleted file mode 100755 index 4cf8585..0000000 --- a/Models/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullSupplierAttributeType.php b/Models/NullSupplierAttributeType.php deleted file mode 100755 index aea8f7f..0000000 --- a/Models/NullSupplierAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullSupplierAttributeValue.php b/Models/NullSupplierAttributeValue.php deleted file mode 100755 index 215b031..0000000 --- a/Models/NullSupplierAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Supplier.php b/Models/Supplier.php index e6544dd..1285f5c 100755 --- a/Models/Supplier.php +++ b/Models/Supplier.php @@ -20,10 +20,9 @@ use Modules\Admin\Models\NullAddress; use Modules\Editor\Models\EditorDoc; use Modules\Media\Models\Media; use Modules\Media\Models\NullMedia; +use Modules\Payment\Models\Payment; use Modules\Profile\Models\ContactElement; use Modules\Profile\Models\NullContactElement; -use Modules\Profile\Models\Profile; -use Modules\Payment\Models\Payment; /** * Supplier class. @@ -60,7 +59,7 @@ class Supplier /** * Attributes. * - * @var SupplierAttribute[] + * @var \Modules\Attribute\Models\Attribute[] * @since 1.0.0 */ private array $attributes = []; @@ -293,43 +292,6 @@ class Supplier return $this->partners; } - /** - * Add attribute to supplier - * - * @param SupplierAttribute $attribute Attribute - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(SupplierAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return SupplierAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - - public function getAttributeByTypeName(string $name) : SupplierAttribute - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $name) { - return $attribute; - } - } - - return new NullSupplierAttribute(); - } - /** * Get contacts. * @@ -467,4 +429,6 @@ class Supplier { return $this->toArray(); } + + use \Modules\Attribute\Models\AttributeHolderTrait; } diff --git a/Models/SupplierAttribute.php b/Models/SupplierAttribute.php deleted file mode 100755 index ae6065f..0000000 --- a/Models/SupplierAttribute.php +++ /dev/null @@ -1,102 +0,0 @@ -type = new SupplierAttributeType(); - $this->value = new SupplierAttributeValue(); - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'supplier' => $this->supplier, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/SupplierAttributeMapper.php b/Models/SupplierAttributeMapper.php index f0be5a3..d654a0c 100755 --- a/Models/SupplierAttributeMapper.php +++ b/Models/SupplierAttributeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Models; +use Modules\Attribute\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -34,7 +35,7 @@ final class SupplierAttributeMapper extends DataMapperFactory */ public const COLUMNS = [ 'suppliermgmt_supplier_attr_id' => ['name' => 'suppliermgmt_supplier_attr_id', 'type' => 'int', 'internal' => 'id'], - 'suppliermgmt_supplier_attr_supplier' => ['name' => 'suppliermgmt_supplier_attr_supplier', 'type' => 'int', 'internal' => 'supplier'], + 'suppliermgmt_supplier_attr_supplier' => ['name' => 'suppliermgmt_supplier_attr_supplier', 'type' => 'int', 'internal' => 'ref'], 'suppliermgmt_supplier_attr_type' => ['name' => 'suppliermgmt_supplier_attr_type', 'type' => 'int', 'internal' => 'type'], 'suppliermgmt_supplier_attr_value' => ['name' => 'suppliermgmt_supplier_attr_value', 'type' => 'int', 'internal' => 'value'], ]; @@ -56,6 +57,14 @@ final class SupplierAttributeMapper 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/SupplierAttributeType.php b/Models/SupplierAttributeType.php deleted file mode 100755 index bba62c4..0000000 --- a/Models/SupplierAttributeType.php +++ /dev/null @@ -1,209 +0,0 @@ -name = $name; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - public function getDefaultByValue(mixed $value) : SupplierAttributeValue - { - foreach ($this->defaults as $default) { - if ($default->getValue() === $value) { - return $default; - } - } - - return new NullSupplierAttributeValue(); - } - - /** - * 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, - 'fields' => $this->fields, - 'custom' => $this->custom, - 'validationPattern' => $this->validationPattern, - 'isRequired' => $this->isRequired, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/SupplierAttributeTypeMapper.php b/Models/SupplierAttributeTypeMapper.php index 701a9f7..c5f0e37 100755 --- a/Models/SupplierAttributeTypeMapper.php +++ b/Models/SupplierAttributeTypeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Models; +use Modules\Attribute\Models\AttributeTypeMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -64,6 +65,14 @@ final class SupplierAttributeTypeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeTypeMapper::class; + /** * Primary table. * diff --git a/Models/SupplierAttributeValue.php b/Models/SupplierAttributeValue.php deleted file mode 100755 index d683282..0000000 --- a/Models/SupplierAttributeValue.php +++ /dev/null @@ -1,231 +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/SupplierAttributeValueMapper.php b/Models/SupplierAttributeValueMapper.php index 75de6d0..f647313 100755 --- a/Models/SupplierAttributeValueMapper.php +++ b/Models/SupplierAttributeValueMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\SupplierManagement\Models; +use Modules\Attribute\Models\AttributeValueType; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -59,6 +60,14 @@ final class SupplierAttributeValueMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeValueType::class; + /** * Primary table. *