Skip to content

Commit

Permalink
cleanup collection admin filter
Browse files Browse the repository at this point in the history
  • Loading branch information
aheinze committed Oct 23, 2020
1 parent 3787d47 commit 74c0eb5
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions modules/Collections/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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)) {
Expand Down

0 comments on commit 74c0eb5

Please sign in to comment.