From 74c0eb527bda655b6f7e2f87201a3824b3f56c00 Mon Sep 17 00:00:00 2001 From: Artur Heinze Date: Fri, 23 Oct 2020 14:13:43 +0200 Subject: [PATCH] cleanup collection admin filter --- modules/Collections/Controller/Admin.php | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/Collections/Controller/Admin.php b/modules/Collections/Controller/Admin.php index c37895fb3..fe7539dd6 100755 --- a/modules/Collections/Controller/Admin.php +++ b/modules/Collections/Controller/Admin.php @@ -517,25 +517,13 @@ public function revisions($collection, $id) { protected function _filter($filter, $collection, $lang = null) { - if ($this->app->storage->type == 'mongolite') { - return $this->_filterMongo($filter, $collection, $lang, true); - } - - if ($this->app->storage->type == 'mongodb') { - return $this->_filterMongo($filter, $collection, $lang); - } - - return null; - - } - - protected function _filterMongo($filter, $collection, $lang, $isMongoLite = false) { + $isMongoLite = ($this->app->storage->type == 'mongolite'); $allowedtypes = ['text','longtext','boolean','select','html','wysiwyg','markdown','code']; $criterias = []; $_filter = null; - $this->app->trigger("collections.admin._filterMongo.before", [&$filter, &$allowedtypes, &$criterias]); + $this->app->trigger('collections.admin._filter.before', [$collection, &$filter, &$allowedtypes, &$criterias]); foreach ($collection['fields'] as $field) { @@ -546,33 +534,42 @@ protected function _filterMongo($filter, $collection, $lang, $isMongoLite = fals } if ($field['type'] != 'boolean' && in_array($field['type'], $allowedtypes)) { + $criteria = []; $criteria[$name] = ['$regex' => $filter]; + if (!$isMongoLite) { $criteria[$name]['$options'] = 'i'; } + $criterias[] = $criteria; } if ($field['type']=='collectionlink') { + $criteria = []; $criteria[$name.'.display'] = ['$regex' => $filter]; + if (!$isMongoLite) { $criteria[$name]['$options'] = 'i'; } + $criterias[] = $criteria; } if ($field['type']=='location') { + $criteria = []; $criteria[$name.'.address'] = ['$regex' => $filter]; + if (!$isMongoLite) { $criteria[$name]['$options'] = 'i'; } + $criterias[] = $criteria; } - $this->app->trigger("collections.admin._filterMongo.field", [$name, $field, $filter, &$criterias]); + $this->app->trigger('collections.admin._filter.field', [$collection, $name, $field, $filter, &$criterias]); } if (count($criterias)) {