From 83a0b9050d659025810f716f0388199b7d2c71f4 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Fri, 16 Feb 2024 06:27:59 +0100 Subject: [PATCH 1/9] Feature: add more column types and allow filtering by relation --- .../public/js/pimcore/report/custom/item.js | 8 +- .../public/js/pimcore/report/custom/report.js | 182 +++++++++++++++++- .../src/Tool/Adapter/Sql.php | 92 +++++++++ 3 files changed, 279 insertions(+), 3 deletions(-) diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js index 7e3687b50e8..8d76ef6fec8 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js @@ -123,7 +123,13 @@ pimcore.bundle.customreports.custom.item = Class.create({ ["string", t("text")], ["numeric", t("numeric")], ["date", t("date")], - ["boolean", t("bool")] + ["boolean", t("bool")], + ["@manyToOneRelation:asset", t("Asset relation (has one)")], + ["@manyToOneRelation:object", t("Object relation (has one)")], + ["@manyToOneRelation:document", t("Document relation (has one)")], + ["@manyToManyRelation:asset", t("Asset relation (has many)")], + ["@manyToManyRelation:object", t("Object relation (has many)")], + ["@manyToManyRelation:document", t("Document relation (has many)")], ], queryMode: 'local', typeAhead: false, diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js index 663a3c68f8f..e4acdb87e15 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js @@ -20,6 +20,11 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr drillDownFilters: {}, drillDownStores: [], + filtersByRelation: {}, + relationColumnTypes: {}, + + systemColumns: [], + progressBar: {}, progressWindow: {}, progressStop: false, @@ -41,6 +46,8 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr }, prepareGridConfig: function(data) { + this.RELATION_FILTER_REGEX = /^([^\:]+)(\:(.*))$/; + this.drillDownFilters = {}; this.drillDownStores = []; @@ -51,6 +58,15 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr this.columnLabels = {}; this.gridfilters = {}; + + this.relationColumnTypes = {}; + this.filtersByRelation = { + '@manyToOneRelation': [], + '@manyToManyRelation': [] + }; + + this.systemColumns = []; + var gridColConfig = {}; for(var f=0; f -1) { + return; + } + + var fieldInfo = this.grid.getColumns()[columnIndex].config; + var fieldInfoLayout = { + name: dataIndexName, + classes: [], + displayMode: 'grid', + objectsAllowed: dataType == 'object', + assetsAllowed: dataType == 'asset', + assetTypes: null, + documentsAllowed: dataType == 'document', + documentTypes: null + } + + var editor = new pimcore.object.tags[relationType](null, fieldInfoLayout); + editor.setObject({id: 1}); + + editor.updateContext({ + containerType: "filterByRelationWindow" + }); + + var formPanel = Ext.create('Ext.form.Panel', { + xtype: "form", + border: false, + items: [editor.getLayoutEdit()], + bodyStyle: "padding: 10px;", + buttons: [ + { + text: t("clear_relation_filter"), + iconCls: "pimcore_icon_filter_condition pimcore_icon_overlay_delete", + handler: function () { + this.filterByRelationWindow.close(); + this.grid.store.filters.removeByKey("x-gridfilter-"+fieldInfo.dataIndex); + }.bind(this) + }, + { + text: t("apply_filter"), + iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", + handler: function () { + if (formPanel.isValid()) { + this.grid.filters.getStore().addFilter( + this.getRelationFilter(fieldInfo.dataIndex, editor) + ); + this.filterByRelationWindow.close(); + } + }.bind(this) + } + ] + }); + + var title = t("filter_by_relation_field") + " " + column.text; + this.filterByRelationWindow = new Ext.Window({ + autoScroll: true, + modal: false, + title: title, + items: [formPanel], + bodyStyle: "background: #fff;", + width: 700, + maxHeight: 650 + }); + this.filterByRelationWindow.show(); + this.filterByRelationWindow.updateLayout(); + }, + getRelationFilter: function (dataIndex, editor) { + var filterValue = editor.data && editor.data.id !== undefined ? 1893 : null; + return new Ext.util.Filter({ + operator: "eq", + type: "int", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValue + }); } }); diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php index be841ddbc3e..7f97a573823 100644 --- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php +++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php @@ -17,12 +17,19 @@ namespace Pimcore\Bundle\CustomReportsBundle\Tool\Adapter; use Pimcore\Db; +use Pimcore\Model; /** * @internal */ class Sql extends AbstractAdapter { + private $relationLoaderDictionary = [ + 'object' => Model\DataObject::class, + 'asset' => Model\Asset::class, + 'document' => Model\Document::class, + ]; + public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offset, ?int $limit, array $fields = null, array $drillDownFilters = null): array { $db = Db::get(); @@ -46,11 +53,82 @@ public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offs } $data = $db->fetchAllAssociative($sql); + + $this->loadRelationData($data); } return ['data' => $data, 'total' => $total]; } + protected function loadRelationData(&$data): void + { + $columnsDictionary = $this->getRelationColumns(); + $columnNames = array_keys($columnsDictionary); + + $relationDataDictionary = []; + foreach ($data as $index =>$row) { + foreach ($columnNames as $columnName) { + if (empty($row[$columnName])) { + continue; + } + + $type = $columnsDictionary[$columnName]; + $relationDataDictionary[$type] = $relationDataDictionary[$type] ?? []; + $relationDataDictionary[$type][] = $row[$columnName]; + + $element = $this->loadElementById($row[$columnName], $type); + $data[$index][$columnName] = $element ? $element->getFullPath() : $row[$columnName]; + } + } + } + + /** + * Load many elements by ids for specific model type and return assoc array + * + * @param number[]|string[] $ids + * @param string $type + * + * @return Model\Element\AbstractElement[] + */ + protected function loadElementsByIds(array $ids, string $type): array + { + $ids = array_unique(array_filter($ids)); + + return array_reduce( + $ids, + function ($carrier, $id) use ($type) { + $carrier[strval($id)] = $this->loadElementById($id, $type); + + return $carrier; + }, + [] + ); + } + + protected function loadElementById($id, string $type): ?Model\Element\AbstractElement + { + $class = $this->relationLoaderDictionary[$type] ?? null; + + $element = call_user_func([$class, 'getById'], $id); + + return $element; + } + + protected function getRelationColumns(): array + { + return array_reduce( + $this->fullConfig->getColumnConfiguration(), + function ($carrier, $item) { + if (preg_match("/^\@\w+\:(object|asset|document)$/", $item['filter'] ?? '', $match)) { + $carrier[$item['name']] = $match[1]; + } + + return $carrier; + }, + [] + ); + } + public function getColumns(?\stdClass $configuration): array { $sql = ''; @@ -150,6 +228,20 @@ protected function getBaseQuery(array $filters, array $fields, bool $ignoreSelec $fields[] = $filter['property']; $condition[] = $db->quoteIdentifier($filter['property']) . ' LIKE ' . $db->quote('%' . $value. '%'); + break; + case 'in': + $values = array_map( + function ($str) use ($db) { + return $db->quote($str); + }, + explode(',', $value) + ); + + $fields[] = $filter['property']; + $condition[] = $db->quoteIdentifier( + sprintf("%s IN (%s)", $filter['property'], implode(',', $values)) + ); + break; case 'lt': case 'gt': From ed65318fc5d6d6e268a9b895fb6627c8399663f3 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Thu, 22 Feb 2024 06:59:04 +0100 Subject: [PATCH 2/9] fix issue with in condition --- .../CustomReportsBundle/src/Tool/Adapter/Sql.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php index 7f97a573823..15fcb040e9c 100644 --- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php +++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php @@ -230,18 +230,10 @@ protected function getBaseQuery(array $filters, array $fields, bool $ignoreSelec break; case 'in': - $values = array_map( - function ($str) use ($db) { - return $db->quote($str); - }, - explode(',', $value) - ); - - $fields[] = $filter['property']; - $condition[] = $db->quoteIdentifier( - sprintf("%s IN (%s)", $filter['property'], implode(',', $values)) - ); - + if (!empty($value)) { + $values = implode(', ', array_map(fn ($id) => intval($id), $value)); + $condition[] = sprintf("%s IN (%s)", $db->quoteIdentifier($filter['property']), $values); + } break; case 'lt': case 'gt': From 663488004e5caa22ae09d1ce00c77e128618fe62 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Thu, 22 Feb 2024 06:59:37 +0100 Subject: [PATCH 3/9] change relation type --- .../public/js/pimcore/report/custom/item.js | 6 ++-- .../public/js/pimcore/report/custom/report.js | 34 +++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js index 8d76ef6fec8..9f0d2c41771 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js @@ -127,9 +127,9 @@ pimcore.bundle.customreports.custom.item = Class.create({ ["@manyToOneRelation:asset", t("Asset relation (has one)")], ["@manyToOneRelation:object", t("Object relation (has one)")], ["@manyToOneRelation:document", t("Document relation (has one)")], - ["@manyToManyRelation:asset", t("Asset relation (has many)")], - ["@manyToManyRelation:object", t("Object relation (has many)")], - ["@manyToManyRelation:document", t("Document relation (has many)")], + ["@advancedManyToManyRelation:asset", t("Asset relation (has many)")], + ["@advancedManyToManyRelation:object", t("Object relation (has many)")], + ["@advancedManyToManyRelation:document", t("Document relation (has many)")], ], queryMode: 'local', typeAhead: false, diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js index e4acdb87e15..e101daf2aba 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js @@ -685,9 +685,12 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr } var fieldInfo = this.grid.getColumns()[columnIndex].config; + + // Fix for editor so we can use existing functionality var fieldInfoLayout = { name: dataIndexName, classes: [], + columns: [], displayMode: 'grid', objectsAllowed: dataType == 'object', assetsAllowed: dataType == 'asset', @@ -722,9 +725,16 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function () { if (formPanel.isValid()) { - this.grid.filters.getStore().addFilter( - this.getRelationFilter(fieldInfo.dataIndex, editor) - ); + var method = 'get' + relationType.charAt(0).toUpperCase() + relationType.slice(1) + 'Filter'; + + if (typeof this[method] == 'function') { + this.grid.filters.getStore().addFilter( + this[method](fieldInfo.dataIndex, editor) + ); + } else { + console.warn('CustomReportsBundle: No method found for ' + method + '!'); + } + this.filterByRelationWindow.close(); } }.bind(this) @@ -745,8 +755,9 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr this.filterByRelationWindow.show(); this.filterByRelationWindow.updateLayout(); }, - getRelationFilter: function (dataIndex, editor) { - var filterValue = editor.data && editor.data.id !== undefined ? 1893 : null; + + getManyToOneRelationFilter: function (dataIndex, editor) { + var filterValue = editor.data && editor.data.id || null; return new Ext.util.Filter({ operator: "eq", type: "int", @@ -755,5 +766,16 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr dataIndex: dataIndex, value: filterValue }); - } + }, + getAdvancedManyToManyRelationFilter: function (dataIndex, editor) { + var filterValue = editor.store.getData().items.map(function (record) { return record.get('id'); }); + return new Ext.util.Filter({ + operator: "in", + type: "array", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValue + }); + }, }); From 9e6631eea1ecaaa16c1b840c1883b8609f3e8a84 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Thu, 22 Feb 2024 07:01:29 +0100 Subject: [PATCH 4/9] allow user to clear selected filter in button and refactor filter resolving --- .../public/js/pimcore/report/custom/report.js | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js index e101daf2aba..09ac66edf44 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js @@ -22,6 +22,7 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr filtersByRelation: {}, relationColumnTypes: {}, + filterButtons: {}, systemColumns: [], @@ -329,14 +330,29 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr dataIndex: _item["name"], text: _item["label"], }; - drillDownFilterComboboxes.push({ + + var filterKey = "x-gridfilter-" + _item["name"]; + var filterButton = Ext.create({ xtype: 'button', - text: _item["label"], + text: _item["label"] || _item["name"], iconCls: 'pimcore_icon_filter', - handler: function (column, relationMatch) { - this.filterByRelationPrepare(column, relationMatch[1].substr(1), relationMatch[3]); - }.bind(this, column, relationMatch) }); + + filterButton.setHandler(function (button, column, relationMatch, filterKey) { + if (this.grid.filters.getStore().getFilters().getByKey(filterKey)) { + this.grid.filters.getStore().removeFilter(filterKey); + + button.setIconCls('pimcore_icon_filter'); + button.setText(column.text || column.dataIndex); + return; + } + + this.filterByRelationPrepare(column, relationMatch[1].substr(1), relationMatch[3]); + }.bind(this, filterButton, column, relationMatch, filterKey)) + + // Store value into dictionary so we can change look on selection + this.filterButtons[filterKey] = filterButton; + drillDownFilterComboboxes.push(filterButton); continue; } @@ -685,8 +701,6 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr } var fieldInfo = this.grid.getColumns()[columnIndex].config; - - // Fix for editor so we can use existing functionality var fieldInfoLayout = { name: dataIndexName, classes: [], @@ -699,6 +713,7 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr documentTypes: null } + // Fix for editor so we can use existing functionality var editor = new pimcore.object.tags[relationType](null, fieldInfoLayout); editor.setObject({id: 1}); @@ -725,14 +740,11 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function () { if (formPanel.isValid()) { - var method = 'get' + relationType.charAt(0).toUpperCase() + relationType.slice(1) + 'Filter'; + var filter = this.makeFilter(relationType, fieldInfo, editor); - if (typeof this[method] == 'function') { - this.grid.filters.getStore().addFilter( - this[method](fieldInfo.dataIndex, editor) - ); - } else { - console.warn('CustomReportsBundle: No method found for ' + method + '!'); + if (filter) { + this.grid.filters.getStore().addFilter(filter); + this.markFilterButton(fieldInfo); } this.filterByRelationWindow.close(); @@ -756,6 +768,25 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr this.filterByRelationWindow.updateLayout(); }, + markFilterButton: function (fieldInfo) { + var button = this.filterButtons["x-gridfilter-" + fieldInfo.dataIndex]; + button.setIconCls('pimcore_icon_clear_filters'); + button.setText('Clear '+fieldInfo['text'] || fieldInfo['name']); + }, + + makeFilter: function (relationType, fieldInfo, editor) { + var method = 'get' + relationType.charAt(0).toUpperCase() + relationType.slice(1) + 'Filter'; + var filter = null; + + if (typeof this[method] == 'function') { + filter = this[method](fieldInfo.dataIndex, editor); + } else { + console.warn('CustomReportsBundle: No method found for ' + method + '!'); + } + + return filter; + }, + getManyToOneRelationFilter: function (dataIndex, editor) { var filterValue = editor.data && editor.data.id || null; return new Ext.util.Filter({ From 2930d3f4d77e874904d328a3f5bc116685070047 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Thu, 22 Feb 2024 07:02:33 +0100 Subject: [PATCH 5/9] fix phpstan issues and optimize relation loading --- .../src/Tool/Adapter/Sql.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php index 15fcb040e9c..a3cfc98b606 100644 --- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php +++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php @@ -24,7 +24,12 @@ */ class Sql extends AbstractAdapter { - private $relationLoaderDictionary = [ + /** + * Relation loaders dictionary + * + * @var array + */ + private array $relationLoaderDictionary = [ 'object' => Model\DataObject::class, 'asset' => Model\Asset::class, 'document' => Model\Document::class, @@ -60,7 +65,7 @@ public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offs return ['data' => $data, 'total' => $total]; } - protected function loadRelationData(&$data): void + protected function loadRelationData(array &$data): void { $columnsDictionary = $this->getRelationColumns(); $columnNames = array_keys($columnsDictionary); @@ -105,7 +110,7 @@ function ($carrier, $id) use ($type) { ); } - protected function loadElementById($id, string $type): ?Model\Element\AbstractElement + protected function loadElementById(int $id, string $type): ?Model\Element\AbstractElement { $class = $this->relationLoaderDictionary[$type] ?? null; @@ -114,11 +119,19 @@ protected function loadElementById($id, string $type): ?Model\Element\AbstractEl return $element; } + /** + * Return columns that are marked as relations + * + * @return array + */ protected function getRelationColumns(): array { return array_reduce( $this->fullConfig->getColumnConfiguration(), function ($carrier, $item) { + if (!$item["display"] && !$item["export"]) { + return $carrier; + } if (preg_match("/^\@\w+\:(object|asset|document)$/", $item['filter'] ?? '', $match)) { $carrier[$item['name']] = $match[1]; } From 07371b2010b45f6bf55932c08be0f53d341b4161 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Thu, 22 Feb 2024 11:37:54 +0100 Subject: [PATCH 6/9] fix issue with drilldown filter when column is hidden --- .../public/js/pimcore/report/custom/item.js | 14 ++++++------- .../public/js/pimcore/report/custom/report.js | 20 ++----------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js index 9f0d2c41771..707120aafd9 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/item.js @@ -113,7 +113,7 @@ pimcore.bundle.customreports.custom.item = Class.create({ checkOrder, { text: t("filter_type"), - width: 100, + width: 160, sortable: false, dataIndex: 'filter', editable: true, @@ -124,12 +124,12 @@ pimcore.bundle.customreports.custom.item = Class.create({ ["numeric", t("numeric")], ["date", t("date")], ["boolean", t("bool")], - ["@manyToOneRelation:asset", t("Asset relation (has one)")], - ["@manyToOneRelation:object", t("Object relation (has one)")], - ["@manyToOneRelation:document", t("Document relation (has one)")], - ["@advancedManyToManyRelation:asset", t("Asset relation (has many)")], - ["@advancedManyToManyRelation:object", t("Object relation (has many)")], - ["@advancedManyToManyRelation:document", t("Document relation (has many)")], + ["@manyToOneRelation:asset", t("Has one Asset relation")], + ["@manyToOneRelation:object", t("Has one Object relation")], + ["@manyToOneRelation:document", t("Has one Document relation")], + ["@advancedManyToManyRelation:asset", t("Has many Asset relation")], + ["@advancedManyToManyRelation:object", t("Has many Object relation")], + ["@advancedManyToManyRelation:document", t("Has many Document relation")], ], queryMode: 'local', typeAhead: false, diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js index 09ac66edf44..8b89eddf8f2 100644 --- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js +++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js @@ -683,24 +683,8 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr filterByRelationPrepare: function (column, relationType, dataType) { var dataIndexName = column.dataIndex - var gridColumns = this.grid.getColumns(); - var columnIndex = -1; - for (let i = 0; i < gridColumns.length; i++) { - let dataIndex = gridColumns[i].dataIndex; - if (dataIndex == dataIndexName) { - columnIndex = i; - break; - } - } - if (columnIndex < 0) { - return; - } - - if (this.systemColumns.indexOf(gridColumns[columnIndex].dataIndex) > -1) { - return; - } + var fieldInfo = column; - var fieldInfo = this.grid.getColumns()[columnIndex].config; var fieldInfoLayout = { name: dataIndexName, classes: [], @@ -771,7 +755,7 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr markFilterButton: function (fieldInfo) { var button = this.filterButtons["x-gridfilter-" + fieldInfo.dataIndex]; button.setIconCls('pimcore_icon_clear_filters'); - button.setText('Clear '+fieldInfo['text'] || fieldInfo['name']); + button.setText('Clear '+fieldInfo.text || fieldInfo.dataIndex); }, makeFilter: function (relationType, fieldInfo, editor) { From 9dfa9a288126018073411329fae2f7fb7308b384 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Mon, 15 Apr 2024 10:31:55 +0200 Subject: [PATCH 7/9] skip relation loading if data or relations definition empty --- bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php index a3cfc98b606..ea0703fe236 100644 --- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php +++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php @@ -67,7 +67,14 @@ public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offs protected function loadRelationData(array &$data): void { - $columnsDictionary = $this->getRelationColumns(); + if (empty($data)) { + return; + } + + if (!$columnsDictionary = $this->getRelationColumns()) { + return; + } + $columnNames = array_keys($columnsDictionary); $relationDataDictionary = []; From ed28b0cf1af67738cf2473bab7db047004463427 Mon Sep 17 00:00:00 2001 From: Goran Jorgic Date: Mon, 15 Apr 2024 10:32:25 +0200 Subject: [PATCH 8/9] allow user to define output format for relation element name --- .../CustomReportsBundle/src/Tool/Adapter/Sql.php | 9 ++++++++- .../Tool/HumanReadableElementNameInterface.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php index ea0703fe236..13236e00afd 100644 --- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php +++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\CustomReportsBundle\Tool\Adapter; +use Pimcore\Bundle\CustomReportsBundle\Tool\HumanReadableElementNameInterface; use Pimcore\Db; use Pimcore\Model; @@ -89,7 +90,13 @@ protected function loadRelationData(array &$data): void $relationDataDictionary[$type][] = $row[$columnName]; $element = $this->loadElementById($row[$columnName], $type); - $data[$index][$columnName] = $element ? $element->getFullPath() : $row[$columnName]; + + if ($element instanceof HumanReadableElementNameInterface) { + $data[$index][$columnName] = $element->getHumanReadableElementName(); + + } else { + $data[$index][$columnName] = $element ? $element->getFullPath() : $row[$columnName]; + } } } } diff --git a/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php b/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php new file mode 100644 index 00000000000..ff45bf418bb --- /dev/null +++ b/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php @@ -0,0 +1,15 @@ + Date: Mon, 15 Apr 2024 12:52:19 +0200 Subject: [PATCH 9/9] fix: add declare keyword into new file --- .../src/Tool/HumanReadableElementNameInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php b/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php index ff45bf418bb..1bfd33d0eb5 100644 --- a/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php +++ b/bundles/CustomReportsBundle/src/Tool/HumanReadableElementNameInterface.php @@ -1,4 +1,5 @@