diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index 7c3fae976..b80d637d4 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -640,6 +640,8 @@ public function index() { $table = $this->getCurrentTable(); // $tableName = models $tableName = $table->getTable(); + // AutoViewVarsTrait + $this->populateAutoViewVars(); // Construct the Query $query = $this->getIndexQuery(); @@ -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'); diff --git a/app/src/Lib/Traits/AutoViewVarsTrait.php b/app/src/Lib/Traits/AutoViewVarsTrait.php index 5893f5a8f..a128b1e6e 100644 --- a/app/src/Lib/Traits/AutoViewVarsTrait.php +++ b/app/src/Lib/Traits/AutoViewVarsTrait.php @@ -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 diff --git a/app/src/Lib/Traits/IndexQueryTrait.php b/app/src/Lib/Traits/IndexQueryTrait.php index 13683debd..e1fd4598b 100644 --- a/app/src/Lib/Traits/IndexQueryTrait.php +++ b/app/src/Lib/Traits/IndexQueryTrait.php @@ -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) { diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 34f1d5bc4..c1641cb45 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -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 { /** @@ -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(); diff --git a/app/src/Lib/Traits/TableMetaTrait.php b/app/src/Lib/Traits/TableMetaTrait.php index a91aa4eac..495c3044e 100644 --- a/app/src/Lib/Traits/TableMetaTrait.php +++ b/app/src/Lib/Traits/TableMetaTrait.php @@ -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', diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index 287b9256c..e3a6328fc 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -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 * diff --git a/app/src/Model/Table/CousTable.php b/app/src/Model/Table/CousTable.php index a69ef3af7..32b8ec114 100644 --- a/app/src/Model/Table/CousTable.php +++ b/app/src/Model/Table/CousTable.php @@ -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. * @@ -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 diff --git a/app/src/Model/Table/MessageTemplatesTable.php b/app/src/Model/Table/MessageTemplatesTable.php index 92e18d66a..384929fa7 100644 --- a/app/src/Model/Table/MessageTemplatesTable.php +++ b/app/src/Model/Table/MessageTemplatesTable.php @@ -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; diff --git a/app/src/View/Helper/FilterHelper.php b/app/src/View/Helper/FilterHelper.php index 5c7b169ae..b6258bb14 100644 --- a/app/src/View/Helper/FilterHelper.php +++ b/app/src/View/Helper/FilterHelper.php @@ -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 @@ -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 diff --git a/app/templates/element/filter/topButtons.php b/app/templates/element/filter/topButtons.php index b56107bd8..91ecbdeb0 100644 --- a/app/templates/element/filter/topButtons.php +++ b/app/templates/element/filter/topButtons.php @@ -27,6 +27,7 @@ declare(strict_types = 1); +use App\Lib\Util\StringUtilities; use Cake\Utility\{Inflector, Hash}; // Construct aria-controls string @@ -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