From f8afe183e1f31371b6e6c5079cca6372a593203e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 12 Jan 2024 00:30:03 +0000 Subject: [PATCH] continue implementations --- Admin/Install/db.json | 5 +++++ Controller/ApiAssetAttributeController.php | 18 +++++++++++++++++- Controller/BackendController.php | 6 ++---- Models/Attribute/AssetAttributeTypeMapper.php | 1 + Models/Attribute/AssetAttributeValueMapper.php | 1 + Theme/Backend/Lang/en.lang.php | 1 - 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 1330d6c..57b682b 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -147,6 +147,11 @@ "type": "TINYINT(1)", "null": false }, + "assetmgmt_attr_type_repeatable": { + "name": "assetmgmt_attr_type_repeatable", + "type": "TINYINT(1)", + "null": false + }, "assetmgmt_attr_type_required": { "description": "Every asset must have this attribute type if set to true.", "name": "assetmgmt_attr_type_required", diff --git a/Controller/ApiAssetAttributeController.php b/Controller/ApiAssetAttributeController.php index 5dfdf71..d1ba8d0 100644 --- a/Controller/ApiAssetAttributeController.php +++ b/Controller/ApiAssetAttributeController.php @@ -61,7 +61,23 @@ final class ApiAssetAttributeController extends Controller return; } - $type = AssetAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + $type = AssetAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + + if (!$type->repeatable) { + $attr = AssetAttributeMapper::count() + ->with('type') + ->where('type/id', (int) $request->getData('type')) + ->where('ref', (int) $request->getData('ref')) + ->execute(); + + if ($attr > 0) { + $response->header->status = RequestStatusCode::R_409; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + } + $attribute = $this->createAttributeFromRequest($request, $type); $this->createModel($request->header->account, $attribute, AssetAttributeMapper::class, 'attribute', $request->getOrigin()); $this->createStandardCreateResponse($request, $response, $attribute); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 02d525f..9d0716e 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -175,12 +175,10 @@ final class BackendController extends Controller $view->data['units'] = $units; /** @var \Model\Setting $settings */ - $settings = $this->app->appSettings->get(null, [ - SettingsEnum::DEFAULT_LOCALIZATION, - ]); + $settings = $this->app->appSettings->get(null, SettingsEnum::DEFAULT_LOCALIZATION); $view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response); - $view->data['attributeView']->data['defaultlocalization'] = LocalizationMapper::get()->where('id', (int) $settings->id)->execute(); + $view->data['attributeView']->data['default_localization'] = LocalizationMapper::get()->where('id', (int) $settings->id)->execute(); $view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response); $view->data['asset-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response); diff --git a/Models/Attribute/AssetAttributeTypeMapper.php b/Models/Attribute/AssetAttributeTypeMapper.php index 6ec6937..80bcfe3 100644 --- a/Models/Attribute/AssetAttributeTypeMapper.php +++ b/Models/Attribute/AssetAttributeTypeMapper.php @@ -42,6 +42,7 @@ final class AssetAttributeTypeMapper extends DataMapperFactory 'assetmgmt_attr_type_datatype' => ['name' => 'assetmgmt_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'], 'assetmgmt_attr_type_fields' => ['name' => 'assetmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'assetmgmt_attr_type_custom' => ['name' => 'assetmgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'assetmgmt_attr_type_repeatable' => ['name' => 'assetmgmt_attr_type_repeatable', 'type' => 'bool', 'internal' => 'repeatable'], 'assetmgmt_attr_type_pattern' => ['name' => 'assetmgmt_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], 'assetmgmt_attr_type_required' => ['name' => 'assetmgmt_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], ]; diff --git a/Models/Attribute/AssetAttributeValueMapper.php b/Models/Attribute/AssetAttributeValueMapper.php index cbc16b4..eba9825 100644 --- a/Models/Attribute/AssetAttributeValueMapper.php +++ b/Models/Attribute/AssetAttributeValueMapper.php @@ -59,6 +59,7 @@ final class AssetAttributeValueMapper extends DataMapperFactory 'mapper' => AssetAttributeValueL11nMapper::class, 'table' => 'assetmgmt_attr_value_l11n', 'self' => 'assetmgmt_attr_value_l11n_value', + 'column' => 'content', 'external' => null, ], ]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index f80f250..b282fcd 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -16,7 +16,6 @@ return ['AssetManagement' => [ 'Assets' => 'Assets', 'Status' => 'Status', 'Name' => 'Name', - 'Number' => 'Number', 'Type' => 'Type', ':status1' => 'Active', ':status2' => 'Inactive',