diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index eb7ec11cc..180629d86 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -444,6 +444,13 @@ public function index() { foreach(array_keys($searchableAttributes) as $attribute) { if(!empty($this->request->getQuery($attribute))) { $query = $table->whereFilter($query, $attribute, $this->request->getQuery($attribute)); + } elseif (!empty($this->request->getQuery($attribute . "_starts_at")) + || !empty($this->request->getQuery($attribute . "_ends_at"))) { + $search_date = []; + // We allow empty for dates since we might refer to infinity (from whenever or to always) + $search_date[] = $this->request->getQuery($attribute . "_starts_at") ?? ""; + $search_date[] = $this->request->getQuery($attribute . "_ends_at") ?? ""; + $query = $table->whereFilter($query, $attribute, $search_date); } } diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 9f031df0a..c401034af 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -49,7 +49,6 @@ public function getSearchableAttributes(): array { } $this->searchFilters[$column] = [ 'type' => $type, - // todo: Probably the following line is redundant but i am leaving it for now 'label' => (__d('field', $column) ?? Inflector::humanize($column)) ]; } @@ -60,14 +59,15 @@ public function getSearchableAttributes(): array { /** * Build a query where() clause for the configured attribute. * - * @since COmanage Registry v5.0.0 - * @param \Cake\ORM\Query $query Cake ORM Query object - * @param string $attribute Attribute to filter on (database name) - * @param string $q Value to filter on + * @param \Cake\ORM\Query $query Cake ORM Query object + * @param string|array $attribute Attribute to filter on (database name) + * @param string $q Value to filter on + * * @return \Cake\ORM\Query Cake ORM Query object + * @since COmanage Registry v5.0.0 */ - public function whereFilter(\Cake\ORM\Query $query, string $attribute, string $q): object { + public function whereFilter(\Cake\ORM\Query $query, string|array $attribute, string $q): object { // not a permitted attribute if(empty($this->searchFilters[$attribute])) { return $query; @@ -75,15 +75,17 @@ public function whereFilter(\Cake\ORM\Query $query, string $attribute, string $q $search = $q; $sub = false; + // Primitive types + $search_types = ['integer', 'boolean']; if( $this->searchFilters[$attribute]['type'] == "string") { $search = "%" . $search . "%"; $sub = true; - } - - // Primitive types - $search_types = ['integer', 'boolean']; - if(in_array($this->searchFilters[$attribute]['type'], $search_types, true)) { + } elseif(in_array($this->searchFilters[$attribute]['type'], $search_types, true)) { return $query->where([$attribute => $search]); + } elseif( $this->searchFilters[$attribute]['type'] == "timestamp") { + return $query->where(function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) use ($attribute, $search) { + return $exp->between($attribute, $search[0], $search[1]); + }); } // String values diff --git a/app/templates/element/filter.php b/app/templates/element/filter.php index eec0a41bd..6ca492da8 100644 --- a/app/templates/element/filter.php +++ b/app/templates/element/filter.php @@ -100,11 +100,15 @@