From ac181da801d97169b3b2aaa89b1bd11fdb0afa9f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 4 Apr 2021 17:10:52 +0200 Subject: [PATCH] many fixes and expands and module expansions --- Admin/Install/db.json | 192 ++++++++++++ Controller/ApiController.php | 327 ++++++++++++++++++++- Controller/BackendController.php | 14 +- Models/AttributeValueType.php | 36 +++ Models/NullSupplierAttribute.php | 38 +++ Models/NullSupplierAttributeType.php | 38 +++ Models/NullSupplierAttributeTypeL11n.php | 38 +++ Models/NullSupplierAttributeValue.php | 38 +++ Models/Supplier.php | 9 + Models/SupplierAttribute.php | 88 ++++++ Models/SupplierAttributeMapper.php | 74 +++++ Models/SupplierAttributeType.php | 180 ++++++++++++ Models/SupplierAttributeTypeL11n.php | 147 +++++++++ Models/SupplierAttributeTypeL11nMapper.php | 57 ++++ Models/SupplierAttributeTypeMapper.php | 83 ++++++ Models/SupplierAttributeValue.php | 214 ++++++++++++++ Models/SupplierAttributeValueMapper.php | 62 ++++ Models/SupplierMapper.php | 7 + 18 files changed, 1638 insertions(+), 4 deletions(-) create mode 100755 Models/AttributeValueType.php create mode 100755 Models/NullSupplierAttribute.php create mode 100755 Models/NullSupplierAttributeType.php create mode 100755 Models/NullSupplierAttributeTypeL11n.php create mode 100755 Models/NullSupplierAttributeValue.php create mode 100755 Models/SupplierAttribute.php create mode 100755 Models/SupplierAttributeMapper.php create mode 100755 Models/SupplierAttributeType.php create mode 100755 Models/SupplierAttributeTypeL11n.php create mode 100755 Models/SupplierAttributeTypeL11nMapper.php create mode 100755 Models/SupplierAttributeTypeMapper.php create mode 100755 Models/SupplierAttributeValue.php create mode 100755 Models/SupplierAttributeValueMapper.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index f080d42..6288fb1 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -82,6 +82,198 @@ } } }, + "suppliermgmt_attr_type": { + "name": "suppliermgmt_attr_type", + "fields": { + "suppliermgmt_attr_type_id": { + "name": "suppliermgmt_attr_type_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "suppliermgmt_attr_type_name": { + "name": "suppliermgmt_attr_type_name", + "type": "VARCHAR(255)", + "null": false + }, + "suppliermgmt_attr_type_fields": { + "name": "suppliermgmt_attr_type_fields", + "type": "INT(11)", + "null": false + }, + "suppliermgmt_attr_type_custom": { + "name": "suppliermgmt_attr_type_custom", + "type": "TINYINT(1)", + "null": false + }, + "suppliermgmt_attr_type_required": { + "description": "Every item must have this attribute type if set to true.", + "name": "suppliermgmt_attr_type_required", + "type": "TINYINT(1)", + "null": false + }, + "suppliermgmt_attr_type_pattern": { + "description": "This is a regex validation pattern.", + "name": "suppliermgmt_attr_type_pattern", + "type": "VARCHAR(255)", + "null": false + } + } + }, + "suppliermgmt_attr_type_l11n": { + "name": "suppliermgmt_attr_type_l11n", + "fields": { + "suppliermgmt_attr_type_l11n_id": { + "name": "suppliermgmt_attr_type_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "suppliermgmt_attr_type_l11n_title": { + "name": "suppliermgmt_attr_type_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "suppliermgmt_attr_type_l11n_type": { + "name": "suppliermgmt_attr_type_l11n_type", + "type": "INT(11)", + "null": false, + "foreignTable": "suppliermgmt_attr_type", + "foreignKey": "suppliermgmt_attr_type_id" + }, + "suppliermgmt_attr_type_l11n_lang": { + "name": "suppliermgmt_attr_type_l11n_lang", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + } + } + }, + "suppliermgmt_attr_value": { + "name": "suppliermgmt_attr_value", + "fields": { + "suppliermgmt_attr_value_id": { + "name": "suppliermgmt_attr_value_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "suppliermgmt_attr_value_default": { + "name": "suppliermgmt_attr_value_default", + "type": "TINYINT(1)", + "null": false + }, + "suppliermgmt_attr_value_type": { + "name": "suppliermgmt_attr_value_type", + "type": "INT(11)", + "null": false + }, + "suppliermgmt_attr_value_valueStr": { + "name": "suppliermgmt_attr_value_valueStr", + "type": "VARCHAR(255)", + "null": true, + "default": null + }, + "suppliermgmt_attr_value_valueInt": { + "name": "suppliermgmt_attr_value_valueInt", + "type": "INT(11)", + "null": true, + "default": null + }, + "suppliermgmt_attr_value_valueDec": { + "name": "suppliermgmt_attr_value_valueDec", + "type": "DECIMAL(19,5)", + "null": true, + "default": null + }, + "suppliermgmt_attr_value_valueDat": { + "name": "suppliermgmt_attr_value_valueDat", + "type": "DATETIME", + "null": true, + "default": null + }, + "suppliermgmt_attr_value_lang": { + "name": "suppliermgmt_attr_value_lang", + "type": "VARCHAR(2)", + "null": true, + "default": null, + "foreignTable": "language", + "foreignKey": "language_639_1" + }, + "suppliermgmt_attr_value_country": { + "name": "suppliermgmt_attr_value_country", + "type": "VARCHAR(2)", + "null": true, + "default": null, + "foreignTable": "country", + "foreignKey": "country_code2" + } + } + }, + "suppliermgmt_supplier_attr_default": { + "name": "suppliermgmt_supplier_attr_default", + "fields": { + "suppliermgmt_supplier_attr_default_id": { + "name": "suppliermgmt_supplier_attr_default_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "suppliermgmt_supplier_attr_default_type": { + "name": "suppliermgmt_supplier_attr_default_type", + "type": "INT(11)", + "null": false, + "foreignTable": "suppliermgmt_attr_type", + "foreignKey": "suppliermgmt_attr_type_id" + }, + "suppliermgmt_supplier_attr_default_value": { + "name": "suppliermgmt_supplier_attr_default_value", + "type": "INT(11)", + "null": false, + "foreignTable": "suppliermgmt_attr_value", + "foreignKey": "suppliermgmt_attr_value_id" + } + } + }, + "suppliermgmt_supplier_attr": { + "name": "suppliermgmt_supplier_attr", + "fields": { + "suppliermgmt_supplier_attr_id": { + "name": "suppliermgmt_supplier_attr_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "suppliermgmt_supplier_attr_supplier": { + "name": "suppliermgmt_supplier_attr_supplier", + "type": "INT(11)", + "null": false, + "foreignTable": "suppliermgmt_supplier", + "foreignKey": "suppliermgmt_supplier_id" + }, + "suppliermgmt_supplier_attr_type": { + "name": "suppliermgmt_supplier_attr_type", + "type": "INT(11)", + "null": false, + "foreignTable": "suppliermgmt_attr_type", + "foreignKey": "suppliermgmt_attr_type_id" + }, + "suppliermgmt_supplier_attr_value": { + "name": "suppliermgmt_supplier_attr_value", + "type": "INT(11)", + "null": true, + "default": null, + "foreignTable": "suppliermgmt_attr_value", + "foreignKey": "suppliermgmt_attr_value_id" + } + } + }, "suppliermgmt_supplier_media": { "name": "suppliermgmt_supplier_media", "fields": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index ab4ba4a..eafe965 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -26,6 +26,18 @@ use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; +use Modules\SupplierManagement\Models\SupplierAttribute; +use Modules\SupplierManagement\Models\NullSupplierAttributeValue; +use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n; +use phpOMS\Message\Http\HttpRequest; +use Modules\SupplierManagement\Models\SupplierAttributeType; +use Modules\SupplierManagement\Models\SupplierAttributeValue; +use Modules\SupplierManagement\Models\AttributeValueType; +use Modules\SupplierManagement\Models\NullSupplierAttributeType; +use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper; +use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper; +use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; +use Modules\SupplierManagement\Models\SupplierAttributeMapper; /** * SupplierManagement class. @@ -153,7 +165,318 @@ final class ApiController extends Controller } /** - * Api method to create item files + * Api method to create supplier attribute + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSupplierAttributeCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!empty($val = $this->validateSupplierAttributeCreate($request))) { + $response->set('attribute_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $attribute = $this->createSupplierAttributeFromRequest($request); + $this->createModel($request->header->account, $attribute, SupplierAttributeMapper::class, 'attribute', $request->getOrigin()); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute); + } + + /** + * Method to create supplier attribute from request. + * + * @param RequestAbstract $request Request + * + * @return SupplierAttribute + * + * @since 1.0.0 + */ + private function createSupplierAttributeFromRequest(RequestAbstract $request) : SupplierAttribute + { + $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')); + + return $attribute; + } + + /** + * Validate supplier attribute create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateSupplierAttributeCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['type'] = empty($request->getData('type'))) + || ($val['value'] = empty($request->getData('value'))) + || ($val['supplier'] = empty($request->getData('supplier'))) + ) { + return $val; + } + + return []; + } + + /** + * Api method to create supplier attribute l11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSupplierAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!empty($val = $this->validateSupplierAttributeTypeL11nCreate($request))) { + $response->set('attr_type_l11n_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $attrL11n = $this->createSupplierAttributeTypeL11nFromRequest($request); + $this->createModel($request->header->account, $attrL11n, SupplierAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type localization', 'Attribute type localization successfully created', $attrL11n); + } + + /** + * Method to create supplier attribute l11n from request. + * + * @param RequestAbstract $request Request + * + * @return SupplierAttributeTypeL11n + * + * @since 1.0.0 + */ + private function createSupplierAttributeTypeL11nFromRequest(RequestAbstract $request) : SupplierAttributeTypeL11n + { + $attrL11n = new SupplierAttributeTypeL11n(); + $attrL11n->setType((int) ($request->getData('type') ?? 0)); + $attrL11n->setLanguage((string) ( + $request->getData('language') ?? $request->getLanguage() + )); + $attrL11n->title = (string) ($request->getData('title') ?? ''); + + return $attrL11n; + } + + /** + * Validate supplier attribute l11n create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateSupplierAttributeTypeL11nCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['title'] = empty($request->getData('title'))) + || ($val['type'] = empty($request->getData('type'))) + ) { + return $val; + } + + return []; + } + + /** + * Api method to create supplier attribute type + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSupplierAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!empty($val = $this->validateSupplierAttributeTypeCreate($request))) { + $response->set('attr_type_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $attrType = $this->createSupplierAttributeTypeFromRequest($request); + $this->createModel($request->header->account, $attrType, SupplierAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); + + $l11nRequest = new HttpRequest($request->uri); + $l11nRequest->setData('type', $attrType->getId()); + $l11nRequest->setData('title', $request->getData('title')); + $l11nRequest->setData('language', $request->getData('language')); + + $l11nAttributeType = $this->createSupplierAttributeTypeL11nFromRequest($l11nRequest); + $this->createModel($request->header->account, $l11nAttributeType, SupplierAttributeTypeL11nMapper::class, 'attr_type_l11n_create', $request->getOrigin()); + + $attrType->setL11n($l11nAttributeType); + + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType); + } + + /** + * Method to create supplier attribute from request. + * + * @param RequestAbstract $request Request + * + * @return SupplierAttributeType + * + * @since 1.0.0 + */ + private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType + { + $attrType = new SupplierAttributeType(); + $attrType->setL11n((string) ($request->getData('name') ?? '')); + $attrType->setFields((int) ($request->getData('fields') ?? 0)); + $attrType->setCustom((bool) ($request->getData('custom') ?? false)); + + return $attrType; + } + + /** + * Validate supplier attribute create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateSupplierAttributeTypeCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['name'] = empty($request->getData('name'))) + || ($val['title'] = empty($request->getData('title'))) + ) { + return $val; + } + + return []; + } + + /** + * Api method to create supplier attribute value + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSupplierAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!empty($val = $this->validateSupplierAttributeValueCreate($request))) { + $response->set('attr_value_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $attrValue = $this->createSupplierAttributeValueFromRequest($request); + $this->createModel($request->header->account, $attrValue, SupplierAttributeValueMapper::class, 'attr_value', $request->getOrigin()); + + if ($attrValue->isDefault) { + $this->createModelRelation( + $request->header->account, + (int) $request->getData('attributetype'), + $attrValue->getId(), + SupplierAttributeTypeMapper::class, 'defaults', '', $request->getOrigin() + ); + } + + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue); + } + + /** + * Method to create supplier attribute value from request. + * + * @param RequestAbstract $request Request + * + * @return SupplierAttributeValue + * + * @since 1.0.0 + */ + private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : SupplierAttributeValue + { + $attrValue = new SupplierAttributeValue(); + + $type = $request->getData('type') ?? 0; + if ($type === AttributeValueType::_INT) { + $attrValue->valueInt = (int) $request->getData('value'); + } elseif ($type === AttributeValueType::_STRING) { + $attrValue->valueStr = (string) $request->getData('value'); + } elseif ($type === AttributeValueType::_FLOAT) { + $attrValue->valueDec = (float) $request->getData('value'); + } elseif ($type === AttributeValueType::_DATETIME) { + $attrValue->valueDat = new \DateTime($request->getData('value') ?? ''); + } + + $attrValue->type = $type; + $attrValue->isDefault = (bool) ($request->getData('default') ?? false); + + if ($request->hasData('language')) { + $attrValue->setLanguage((string) ($request->getData('language') ?? $request->getLanguage())); + } + + if ($request->hasData('country')) { + $attrValue->setCountry((string) ($request->getData('country') ?? $request->header->l11n->getCountry())); + } + + return $attrValue; + } + + /** + * Validate supplier attribute value create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateSupplierAttributeValueCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['type'] = empty($request->getData('type'))) + || ($val['value'] = empty($request->getData('value'))) + ) { + return $val; + } + + return []; + } + + /** + * Api method to create supplier files * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response @@ -199,7 +522,7 @@ final class ApiController extends Controller } /** - * Api method to create item files + * Api method to create supplier files * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 6c9cc8f..a34eb21 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -24,6 +24,7 @@ use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Stdlib\Base\SmartDateTime; use phpOMS\Views\View; +use Modules\Media\Models\Media; /** * SupplierManagement controller class. @@ -53,7 +54,12 @@ final class BackendController extends Controller $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response)); - $supplier = SupplierMapper::getAfterPivot(0, null, 25); + $supplier = SupplierMapper + ::with('notes', models: null) + ::with('contactElements', models: null) + ::with('type', 'backend_image', models: [Media::class]) // @todo: it would be nicer if I coult say files:type or files/type and remove the models parameter? + ::getAfterPivot(0, null, 25); + $view->addData('supplier', $supplier); return $view; @@ -103,7 +109,11 @@ final class BackendController extends Controller $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-profile'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response)); - $supplier = SupplierMapper::get((int) $request->getData('id')); + $supplier = SupplierMapper + ::with('files', limit: 5, orderBy: 'createdAt', sortOrder: 'ASC') + ::with('notes', limit: 5, orderBy: 'id', sortOrder: 'ASC') + ::get((int) $request->getData('id')); + $view->setData('supplier', $supplier); // stats diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php new file mode 100755 index 0000000..c900c56 --- /dev/null +++ b/Models/AttributeValueType.php @@ -0,0 +1,36 @@ +id = $id; + } +} diff --git a/Models/NullSupplierAttributeType.php b/Models/NullSupplierAttributeType.php new file mode 100755 index 0000000..94beb9b --- /dev/null +++ b/Models/NullSupplierAttributeType.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/NullSupplierAttributeTypeL11n.php b/Models/NullSupplierAttributeTypeL11n.php new file mode 100755 index 0000000..9d0af32 --- /dev/null +++ b/Models/NullSupplierAttributeTypeL11n.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/NullSupplierAttributeValue.php b/Models/NullSupplierAttributeValue.php new file mode 100755 index 0000000..65bead0 --- /dev/null +++ b/Models/NullSupplierAttributeValue.php @@ -0,0 +1,38 @@ +id = $id; + } +} diff --git a/Models/Supplier.php b/Models/Supplier.php index 67c5fdf..0e6d0d7 100755 --- a/Models/Supplier.php +++ b/Models/Supplier.php @@ -21,6 +21,7 @@ use Modules\Media\Models\Media; use Modules\Profile\Models\ContactElement; use Modules\Profile\Models\NullContactElement; use Modules\Profile\Models\Profile; +use Modules\Media\Models\NullMedia; /** * Supplier class. @@ -54,6 +55,14 @@ class Supplier public Profile $profile; + /** + * Attributes. + * + * @var int[]|SupplierAttribute[] + * @since 1.0.0 + */ + private array $attributes = []; + /** * Files. * diff --git a/Models/SupplierAttribute.php b/Models/SupplierAttribute.php new file mode 100755 index 0000000..8455a5c --- /dev/null +++ b/Models/SupplierAttribute.php @@ -0,0 +1,88 @@ +id; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return []; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/SupplierAttributeMapper.php b/Models/SupplierAttributeMapper.php new file mode 100755 index 0000000..e1416ec --- /dev/null +++ b/Models/SupplierAttributeMapper.php @@ -0,0 +1,74 @@ + + * @since 1.0.0 + */ + protected static array $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_type' => ['name' => 'suppliermgmt_supplier_attr_type', 'type' => 'int', 'internal' => 'type'], + 'suppliermgmt_supplier_attr_value' => ['name' => 'suppliermgmt_supplier_attr_value', 'type' => 'int', 'internal' => 'value'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $ownsOne = [ + 'type' => [ + 'mapper' => SupplierAttributeTypeMapper::class, + 'external' => 'suppliermgmt_supplier_attr_type', + ], + 'value' => [ + 'mapper' => SupplierAttributeValueMapper::class, + 'external' => 'suppliermgmt_supplier_attr_value', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'suppliermgmt_supplier_attr'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'suppliermgmt_supplier_attr_id'; +} diff --git a/Models/SupplierAttributeType.php b/Models/SupplierAttributeType.php new file mode 100755 index 0000000..9eb69fa --- /dev/null +++ b/Models/SupplierAttributeType.php @@ -0,0 +1,180 @@ +setL11n($name); + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Set l11n + * + * @param string|SupplierAttributeTypeL11n $l11n Tag article l11n + * @param string $lang Language + * + * @return void + * + * @since 1.0.0 + */ + public function setL11n($l11n, string $lang = ISO639x1Enum::_EN) : void + { + if ($l11n instanceof SupplierAttributeTypeL11n) { + $this->l11n = $l11n; + } elseif ($this->l11n instanceof SupplierAttributeTypeL11n && \is_string($l11n)) { + $this->l11n->title = $l11n; + } elseif (\is_string($l11n)) { + $this->l11n = new SupplierAttributeTypeL11n(); + $this->l11n->title = $l11n; + $this->l11n->setLanguage($lang); + } + } + + /** + * @return string + * + * @since 1.0.0 + */ + public function getL11n() : string + { + return $this->l11n instanceof SupplierAttributeTypeL11n ? $this->l11n->title : $this->l11n; + } + + /** + * Set fields + * + * @param int $fields Fields + * + * @return void + * + * @since 1.0.0 + */ + public function setFields(int $fields) : void + { + $this->fields = $fields; + } + + /** + * Set custom + * + * @param bool $custom FieldsCustom + * + * @return void + * + * @since 1.0.0 + */ + public function setCustom(bool $custom) : void + { + $this->custom = $custom; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return []; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/SupplierAttributeTypeL11n.php b/Models/SupplierAttributeTypeL11n.php new file mode 100755 index 0000000..258cf95 --- /dev/null +++ b/Models/SupplierAttributeTypeL11n.php @@ -0,0 +1,147 @@ +type = $type; + $this->title = $title; + $this->language = $language; + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Get attribute type + * + * @return int|SupplierAttributeType + * + * @since 1.0.0 + */ + public function getType() + { + return $this->type; + } + + /** + * Set type. + * + * @param int $type Type id + * + * @return void + * + * @since 1.0.0 + */ + public function setType(int $type) : void + { + $this->type = $type; + } + + /** + * 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 []; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/SupplierAttributeTypeL11nMapper.php b/Models/SupplierAttributeTypeL11nMapper.php new file mode 100755 index 0000000..4ea3115 --- /dev/null +++ b/Models/SupplierAttributeTypeL11nMapper.php @@ -0,0 +1,57 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'suppliermgmt_attr_type_l11n_id' => ['name' => 'suppliermgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'suppliermgmt_attr_type_l11n_title' => ['name' => 'suppliermgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + 'suppliermgmt_attr_type_l11n_type' => ['name' => 'suppliermgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + 'suppliermgmt_attr_type_l11n_lang' => ['name' => 'suppliermgmt_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'suppliermgmt_attr_type_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'suppliermgmt_attr_type_l11n_id'; +} diff --git a/Models/SupplierAttributeTypeMapper.php b/Models/SupplierAttributeTypeMapper.php new file mode 100755 index 0000000..72190b4 --- /dev/null +++ b/Models/SupplierAttributeTypeMapper.php @@ -0,0 +1,83 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'suppliermgmt_attr_type_id' => ['name' => 'suppliermgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'], + 'suppliermgmt_attr_type_name' => ['name' => 'suppliermgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'suppliermgmt_attr_type_fields' => ['name' => 'suppliermgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], + 'suppliermgmt_attr_type_custom' => ['name' => 'suppliermgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'suppliermgmt_attr_type_pattern' => ['name' => 'suppliermgmt_attr_type_pattern', 'type' => 'bool', 'internal' => 'validationPattern'], + 'suppliermgmt_attr_type_required' => ['name' => 'suppliermgmt_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'l11n' => [ + 'mapper' => SupplierAttributeTypeL11nMapper::class, + 'table' => 'suppliermgmt_attr_type_l11n', + 'self' => 'suppliermgmt_attr_type_l11n_type', + 'column' => 'title', + 'conditional' => true, + 'external' => null, + ], + 'defaults' => [ + 'mapper' => SupplierAttributeValueMapper::class, + 'table' => 'suppliermgmt_supplier_attr_default', + 'self' => 'suppliermgmt_supplier_attr_default_type', + 'external' => 'suppliermgmt_supplier_attr_default_value', + 'conditional' => false, + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'suppliermgmt_attr_type'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'suppliermgmt_attr_type_id'; +} diff --git a/Models/SupplierAttributeValue.php b/Models/SupplierAttributeValue.php new file mode 100755 index 0000000..d8f09db --- /dev/null +++ b/Models/SupplierAttributeValue.php @@ -0,0 +1,214 @@ +type = $type; + $this->language = $language; + + $this->setValue($value); + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Set value + * + * @param int|string|float|\DateTimeInterface $value Value + * + * @return void + * + * @since 1.0.0 + */ + public function setValue($value) : 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; + } + } + + 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; + } + + /** + * Set language + * + * @param string $language Language + * + * @return void + * + * @since 1.0.0 + */ + public function setLanguage(string $language) : void + { + $this->language = $language; + } + + /** + * Set country + * + * @param string $country Country + * + * @return void + * + * @since 1.0.0 + */ + public function setCountry(string $country) : void + { + $this->country = $country; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return []; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Models/SupplierAttributeValueMapper.php b/Models/SupplierAttributeValueMapper.php new file mode 100755 index 0000000..1c6b82f --- /dev/null +++ b/Models/SupplierAttributeValueMapper.php @@ -0,0 +1,62 @@ + + * @since 1.0.0 + */ + protected static array $columns = [ + 'suppliermgmt_attr_value_id' => ['name' => 'suppliermgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'], + 'suppliermgmt_attr_value_default' => ['name' => 'suppliermgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], + 'suppliermgmt_attr_value_type' => ['name' => 'suppliermgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'], + 'suppliermgmt_attr_value_valueStr' => ['name' => 'suppliermgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], + 'suppliermgmt_attr_value_valueInt' => ['name' => 'suppliermgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], + 'suppliermgmt_attr_value_valueDec' => ['name' => 'suppliermgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], + 'suppliermgmt_attr_value_valueDat' => ['name' => 'suppliermgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], + 'suppliermgmt_attr_value_lang' => ['name' => 'suppliermgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'], + 'suppliermgmt_attr_value_country' => ['name' => 'suppliermgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static string $table = 'suppliermgmt_attr_value'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static string $primaryField = 'suppliermgmt_attr_value_id'; +} diff --git a/Models/SupplierMapper.php b/Models/SupplierMapper.php index 26f2f56..a6bc750 100755 --- a/Models/SupplierMapper.php +++ b/Models/SupplierMapper.php @@ -115,5 +115,12 @@ final class SupplierMapper extends DataMapperAbstract 'external' => 'suppliermgmt_supplier_contactelement_dst', 'self' => 'suppliermgmt_supplier_contactelement_src', ], + 'attributes' => [ + 'mapper' => SupplierAttributeMapper::class, + 'table' => 'suppliermgmt_supplier_attr', + 'self' => 'suppliermgmt_supplier_attr_supplier', + 'conditional' => true, + 'external' => null, + ], ]; }