From 24af73ce43b5a79c96e3deaf23942281edd15992 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 4 Mar 2024 18:35:15 +0200 Subject: [PATCH] fix group filtering --- app/src/Lib/Traits/SearchFilterTrait.php | 19 +++++++- app/src/Lib/Traits/TableMetaTrait.php | 3 +- app/src/Lib/Util/ArrayUtilities.php | 57 ++++++++++++++++++++++++ app/src/Model/Table/GroupsTable.php | 9 ++++ app/src/Model/Table/PeopleTable.php | 2 +- app/templates/element/filter.php | 14 +----- 6 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 app/src/Lib/Util/ArrayUtilities.php diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 70ffd5e18..d90440646 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -90,14 +90,29 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null): $fieldIsActive = $filterConfig[$column]['active']; } } - - $this->searchFilters[$column] = [ + + $attribute = [ 'type' => $type, 'label' => \App\Lib\Util\StringUtilities::columnKey($modelname, $column, $vv_tz, true), 'active' => $fieldIsActive, 'order' => 99 // this is the default ]; + // The column name should always go first, then the description will follow. + if($column == 'name') { + $this->searchFilters = [ $column => $attribute, ...$this->searchFilters]; + } else if ($column == 'description') { + if(isset($this->searchFilters['name'])) { + $this->searchFilters = array_slice($this->searchFilters, 0, 1) + + [ $column => $attribute ] + + array_slice($this->searchFilters, 1); + } else { + $this->searchFilters = [ $column => $attribute, ...$this->searchFilters]; + } + } else { + $this->searchFilters[$column] = $attribute; + } + // For the date fields we search ranges if($type === 'timestamp') { $this->searchFilters[$column]['alias'][] = $column . '_starts_at'; diff --git a/app/src/Lib/Traits/TableMetaTrait.php b/app/src/Lib/Traits/TableMetaTrait.php index e7590c0f7..c2a80da6f 100644 --- a/app/src/Lib/Traits/TableMetaTrait.php +++ b/app/src/Lib/Traits/TableMetaTrait.php @@ -84,7 +84,8 @@ protected function filterMetadataFields() { 'source_name_id', 'source_pronoun_id', 'source_telephone_number_id', - 'source_url_id' + 'source_url_id', + 'owners_group_id' ]; $newa = array(); diff --git a/app/src/Lib/Util/ArrayUtilities.php b/app/src/Lib/Util/ArrayUtilities.php new file mode 100644 index 000000000..416465a10 --- /dev/null +++ b/app/src/Lib/Util/ArrayUtilities.php @@ -0,0 +1,57 @@ + 'GroupTypeEnum' ] ]); + + $this->setFilterConfig([ + 'identifier' => [ + 'type' => 'relatedModel', + 'model' => 'Identifier', + 'active' => true, + 'order' => 4 + ] + ]); $this->setPermissions([ // XXX update for couAdmins, etc diff --git a/app/src/Model/Table/PeopleTable.php b/app/src/Model/Table/PeopleTable.php index 4883768d2..74f95c0f1 100644 --- a/app/src/Model/Table/PeopleTable.php +++ b/app/src/Model/Table/PeopleTable.php @@ -564,7 +564,7 @@ public function recalculateStatus(int $id): ?string { // Locked status cannot be recalculated. This isn't an error, per se. if($person->status == StatusEnum::Locked) { $this->llog('trace', 'Not recalculating Person " . $person->id . " status since the record is locked'); - return $curStatus; + return $person->status; } // Update the Person status diff --git a/app/templates/element/filter.php b/app/templates/element/filter.php index f772e7648..513555371 100644 --- a/app/templates/element/filter.php +++ b/app/templates/element/filter.php @@ -113,7 +113,7 @@ // The populated variables are in plural while the column names are singular // Convention: It is a prerequisite that the vvar should be the plural of the column name - $populated_vvar = Inflector::pluralize($key); + $populated_vvar = lcfirst(Inflector::pluralize(Inflector::camelize($key))); $button_label = isset($$populated_vvar) ? $$populated_vvar[ $search_params[$key] ] : (is_array($search_params[$key]) ? 'Range' : $search_params[$key]); @@ -146,16 +146,6 @@ $field_datetime_columns = []; $inactiveFiltersCount = 0; // for re-balancing the columns and submit buttons - - if(!empty($columns)) { - // The searchable attributes will be sorted first alphabetically - asort($vv_searchable_attributes); - // Sort the order attribute - uasort($vv_searchable_attributes, function ($item1, $item2) { - if ($item1['order'] == $item2['order']) return 0; - return $item1['order'] < $item2['order'] ? -1 : 1; - }); - } foreach($vv_searchable_attributes as $key => $options) { if($options['type'] == 'boolean') { @@ -226,7 +216,7 @@ // The populated variables are in plural while the column names are singular // Convention: It is a prerequisite that the vvar should be the plural of the column name - $populated_vvar = Inflector::pluralize($key); + $populated_vvar = lcfirst(Inflector::pluralize(Inflector::camelize($key))); if(isset($$populated_vvar)) { // If we have an AutoViewVar matching the name of this key, // convert to a select