Skip to content

CFM-134_filtering_bug_fixes #339

Merged
merged 2 commits into from
Sep 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ public function index() {
$table = $this->getCurrentTable();
// $tableName = models
$tableName = $table->getTable();
// AutoViewVarsTrait
$this->populateAutoViewVars();
// Construct the Query
$query = $this->getIndexQuery();

Expand Down Expand Up @@ -667,8 +669,6 @@ public function index() {
// Pass vars to the View
$this->set($tableName, $resultSet);
$this->set('vv_permission_set', $this->RegistryAuth->calculatePermissionsForResultSet($resultSet));
// AutoViewVarsTrait
$this->populateAutoViewVars();

// Default index view title is model name
[$title, , ] = StringUtilities::entityAndActionToTitle($resultSet, $modelsName, 'index');
Expand Down
1 change: 0 additions & 1 deletion app/src/Lib/Traits/AutoViewVarsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use App\Lib\Util\FunctionUtilities;
use App\Lib\Util\StringUtilities;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;

trait AutoViewVarsTrait {
// Array (and configuration) of view variables to automatically populate
Expand Down
4 changes: 1 addition & 3 deletions app/src/Lib/Traits/IndexQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ public function getIndexQuery(bool $pickerMode = false, array $requestParams = [

// Attributes to search for
if(method_exists($table, 'getSearchableAttributes')) {
$searchableAttributes = $table->getSearchableAttributes($this->name,
$this->viewBuilder()
->getVar('vv_tz'));
$searchableAttributes = $table->getSearchableAttributes($this->name, $this->viewBuilder());

// Extra View Variables
foreach ($table->getViewVars() as $key => $variable) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
use Bake\Utility\Model\AssociationFilter;
use Cake\Database\Expression\QueryExpression;
use Cake\Http\ServerRequest;
use Cake\I18n\FrozenTime;
use Cake\ORM\Query;
use Cake\Utility\Inflector;
use Cake\I18n\FrozenTime;
use Cake\View\ViewBuilder;

trait SearchFilterTrait {
/**
Expand Down Expand Up @@ -233,11 +234,12 @@ public function getFilterConfig(): array {
*
* @since COmanage Registry v5.0.0
* @param string $controller Controller name
* @param DateTimeZone $vv_tz Current time zone, if known
* @param ViewBuilder $viewBuilder View Builder Object
* @return array Array of permitted search attributes and configuration elements needed for display
*/

public function getSearchableAttributes(string $controller, \DateTimeZone $vv_tz=null): array {
public function getSearchableAttributes(string $controller, ViewBuilder $viewBuilder): array {
$vv_tz = $viewBuilder->getVar('vv_tz') ?? null;
$modelname = Inflector::classify(Inflector::underscore($controller));
$filterConfig = $this->getFilterConfig();

Expand Down
1 change: 1 addition & 0 deletions app/src/Lib/Traits/TableMetaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ protected function filterMetadataFields() {
'lft', // XXX For now i skip lft.rght column for tree structures
'rght',
'api_key',
'adopted_person_id',
// XXX maybe replace this with a regex, source_*_id?
'source_ad_hoc_attribute_id',
'source_address_id',
Expand Down
27 changes: 27 additions & 0 deletions app/src/Lib/Util/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ public static function columnKey(
return ($cfield !== $c) ? $cfield : \Cake\Utility\Inflector::humanize($c);
}

/**
* Convert a database column name to an auto view variable name
*
* @param string $column Database column name to convert
* @return string Converted view variable name
* @since COmanage Registry v5.2.0
*/
public static function columnToAutoViewVar(string $column): string {
// strip trailing _type_id if present, else _id
$base = preg_replace('/_type_id$/', '', $column);
$base = preg_replace('/_id$/', '', $base);

// if it originally was *_type_id, we want “...Types”
$isType = str_ends_with($column, '_type_id');

// convert snake_case to camelCase
$camel = Inflector::variable($base); // eg email_address -> emailAddress

if ($isType) {
// ensure a plural sense by appending “Types” (matches repo usage)
return $camel . 'Types';
}

// default pluralization
return Inflector::variable(Inflector::pluralize($base));
}

/**
* Determines the translation domain for a plugin
*
Expand Down
8 changes: 1 addition & 7 deletions app/src/Model/Table/CousTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CousTable extends Table {
use \App\Lib\Traits\SearchFilterTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

/**
* Perform Cake Model initialization.
*
Expand Down Expand Up @@ -116,12 +116,6 @@ public function initialize(array $config): void {
]);

$this->setFilterConfig([
'identifier' => [
'type' => 'string',
'model' => 'Identifiers',
'active' => true,
'order' => 4
],
'parent_id' => [
// We want to keep the default column configuration and add extra functionality.
// Here the extra functionality is additional to select options since the parent_id
Expand Down
1 change: 1 addition & 0 deletions app/src/Model/Table/MessageTemplatesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MessageTemplatesTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\SearchFilterTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

Expand Down
5 changes: 3 additions & 2 deletions app/src/View/Helper/FilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@

namespace App\View\Helper;

use App\Lib\Util\StringUtilities;
use Cake\Collection\Collection;
use Cake\ORM\TableRegistry;
use Cake\Utility\{Inflector, Hash};
use Cake\Utility\Hash;
use Cake\View\Helper;

class FilterHelper extends Helper
Expand All @@ -50,7 +51,7 @@ public function calculateFieldParams(string $columnName, string $label): array{
$populatedVarData = $this->getView()->get(
// 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
lcfirst(Inflector::pluralize(Inflector::camelize($columnName)))
StringUtilities::columnToAutoViewVar($columnName)
);

// Field options
Expand Down
3 changes: 2 additions & 1 deletion app/templates/element/filter/topButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

declare(strict_types = 1);

use App\Lib\Util\StringUtilities;
use Cake\Utility\{Inflector, Hash};

// Construct aria-controls string
Expand All @@ -41,7 +42,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 = lcfirst(Inflector::pluralize(Inflector::camelize($key)));
$populated_vvar = StringUtilities::columnToAutoViewVar($key);
$button_label = 'Range';
if(isset($$populated_vvar) && isset($$populated_vvar[$params])) {
// Get label name from AutoViewPopulated vars
Expand Down