diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index b4f2a550d..5552d9bf9 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -353,11 +353,13 @@ public function index() { $searchableAttributes = $table->getSearchableAttributes(); if(!empty($searchableAttributes)) { - foreach($searchableAttributes as $attribute) { + foreach(array_keys($searchableAttributes) as $attribute) { if(!empty($this->request->getQuery($attribute))) { $query = $table->whereFilter($query, $attribute, $this->request->getQuery($attribute)); } } + + $this->set('vv_searchable_attributes', $searchableAttributes); } } diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 70b35cfd3..54c88abde 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -33,15 +33,52 @@ trait SearchFilterTrait { // Array (and configuration) of permitted search filters private $searchFilters = array(); + /** + * Determine the UI label for the specified attribute. + * + * @since COmanage Match v1.0.0 + * @param string $attribute Attribute + * @return string Label + * @todo Merge this with _column_key from index.ctp + */ + + public function getLabel($attribute) { + if(isset($this->searchFilters[$attribute]['label']) + && $this->searchFilters[$attribute]['label'] !== null) { + return $this->searchFilters[$attribute]['label']; + } + + // Try to construct a label from the language key. + $l = __('match.fd.'.$attribute); + + if($l != 'match.fd.'.$attribute) { + return $l; + } + + // If we make it here, just return $attribute + return $attribute; + } + /** * Obtain the set of permitted search attributes. * * @since COmanage Match v1.0.0 - * @return array Array of permitted search attributes + * @return array Array of permitted search attributes and configuration elements needed for display */ public function getSearchableAttributes() { - return array_keys($this->searchFilters); + // Not every configuration element is necessary for the search form, and + // some need to be calculated, so we do that work here. + + $ret = []; + + foreach(array_keys($this->searchFilters) as $attr) { + $ret[ $attr ] = [ + 'label' => $this->getLabel($attr) + ]; + } + + return $ret; } /** @@ -50,14 +87,15 @@ public function getSearchableAttributes() { * @since COmanage Match v1.0.0 * @param string $attribute Attribute that filtering is permitted on (database name) * @param bool $caseSensitive Whether this attribute is case sensitive - * @param bool $substring Whether substring searching is permitted for this attrimute + * @param string $label Label for this search field, or null to autocalculate + * @param bool $substring Whether substring searching is permitted for this attribute */ - public function setSearchFilter(string $attribute, bool $caseSensitive=false, bool $substring=true) { - $this->searchFilters[$attribute] = [ - 'caseSensitive' => $caseSensitive, - 'substring' => $substring - ]; + public function setSearchFilter(string $attribute, + bool $caseSensitive=false, + string $label=null, + bool $substring=true) { + $this->searchFilters[$attribute] = compact('caseSensitive', 'label', 'substring'); } /** diff --git a/app/src/Locale/en_US/default.po b/app/src/Locale/en_US/default.po index c2fe138af..dde5e45aa 100644 --- a/app/src/Locale/en_US/default.po +++ b/app/src/Locale/en_US/default.po @@ -463,7 +463,7 @@ msgid "match.fd.select" msgstr "(Please select a value)" msgid "match.fd.sor" -msgstr "System of Record" +msgstr "System of Record (SOR)" msgid "match.fd.sor.abbr" msgstr "SOR" diff --git a/app/src/Model/Table/MatchgridRecordsTable.php b/app/src/Model/Table/MatchgridRecordsTable.php index 52150ba12..a89ab45d1 100644 --- a/app/src/Model/Table/MatchgridRecordsTable.php +++ b/app/src/Model/Table/MatchgridRecordsTable.php @@ -71,15 +71,15 @@ public function initialize(array $config) { $mgconfig = $Matchgrid->getMatchgridConfig($config['matchgrid_id']); + // Always permit search on SOR, SORID, and Reference ID + $this->setSearchFilter('sor', true, null, false); + $this->setSearchFilter('sorid', true, null, false); + $this->setSearchFilter('referenceid', true, null, false); + foreach($mgconfig->attributes as $attr) { // XXX for now we permit substring on all fields since we don't have a better way to distinguish - $this->setSearchFilter($attr->name, $attr->case_sensitive, true); + $this->setSearchFilter($attr->name, $attr->case_sensitive, null, true); } - - // Also permit search on SOR, SORID, and Reference ID - $this->setSearchFilter('sor', true, false); - $this->setSearchFilter('sorid', true, false); - $this->setSearchFilter('referenceid', true, false); } /** diff --git a/app/src/Template/Element/search.ctp b/app/src/Template/Element/search.ctp index 3fcfc0666..da31050a8 100644 --- a/app/src/Template/Element/search.ctp +++ b/app/src/Template/Element/search.ctp @@ -19,37 +19,32 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @link http://www.internet2.edu/comanage COmanage Project + * @link https://www.internet2.edu/comanage COmanage Project * @package match * @since COmanage Match v1.0.0 * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ -use \Cake\Utility\Inflector; +// $this->name = Models +$modelsName = $this->name; +// $modelName = Model +$modelName = \Cake\Utility\Inflector::singularize($modelsName); -// Globals -global $cm_lang, $cm_texts; - -// Get a pointer to our controller -$controller = $this->request->getParam('controller'); -$req = Inflector::singularize($controller); - // Get the query string and separate the search params from the non-search params $query = $this->request->getQueryParams(); -$non_search_params = array_diff_key($query, $vv_search_fields); -$search_params = array_intersect_key($query, $vv_search_fields); - -// Begin the form -print $this->Form->create($req, [ +$non_search_params = array_diff_key($query, $vv_searchable_attributes); +$search_params = array_intersect_key($query, $vv_searchable_attributes); + +// Begin the form +print $this->Form->create(null, [ 'id' => 'top-search-form', - 'type' => 'get', - 'url' => ['action' => $this->request->action] + 'type' => 'get' ]); // Pass back the non-search params as hidden fields, but always exclude the page parameter // because we need to start new searches on page one (or we're likely to end up with a 404). if(!empty($non_search_params)) { - foreach ($non_search_params as $param => $value) { + foreach($non_search_params as $param => $value) { if($param != 'page') { print $this->Form->hidden(filter_var($param, FILTER_SANITIZE_SPECIAL_CHARS), array('default' => filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS))) . "\n"; } @@ -57,11 +52,10 @@ if(!empty($non_search_params)) { } // Boolean to distinguish between search filters and sort parameters -// XXX may no longer need this $hasActiveFilters = false; ?> -