Skip to content

Commit

Permalink
Filter Petitions by COU
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored and arlen committed Oct 14, 2024
1 parent 24df845 commit 4640e3a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
25 changes: 21 additions & 4 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ public function expressionsConstructor(Query $query, QueryExpression $exp, strin
// Use the `lower` function to apply uniformity for the search
'string' => $exp->like($query->func()->lower([$attributeWithModelPrefix => 'identifier']),
strtolower('%' . $search . '%')),
'integer',
'select', // AutoviewVar type
'parent', // AutoviewVar type
'boolean',
'parent' => $exp->add([$attributeWithModelPrefix => $search]),
'integer' => $exp->add([$attributeWithModelPrefix => $search]),
'date' => $exp->add([$attributeWithModelPrefix => FrozenTime::parseDate($search, 'y-M-d')]),
'timestamp' => $this->constructDateComparisonClause($exp, $attributeWithModelPrefix, $search),
default => $exp->eq($query->func()->lower([$attributeWithModelPrefix => 'identifier']),
Expand Down Expand Up @@ -238,6 +239,12 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null):
$modelname = Inflector::classify(Inflector::underscore($controller));
$filterConfig = $this->getFilterConfig();

// We get the filter keys and we will force include the fields that we
// have excluded in the filterMetadataFields() method. This way we have a
// method to exclude a field globally but then force its usage when needed through
// configuration
$filterKeys = array_keys($filterConfig);

// Gather up related models defined in the $filterConfig
// XXX For now, we'll list these first - but we should probably provide a better way to order these.
foreach ($filterConfig as $field => $f) {
Expand Down Expand Up @@ -274,9 +281,19 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null):
];
}

foreach ($this->filterMetadataFields() as $column => $type) {
// Include meta fields that are defined in the configuration
// FORCE USAGE
$filterMetadatFielsList = $this->filterMetadataFields();
foreach ($filterKeys as $key) {
if (isset($filterMetadatFielsList['meta'][$key])) {
$filterMetadatFielsList[$key] = $filterMetadatFielsList['meta'][$key];
}

}

foreach ($filterMetadatFielsList as $column => $type) {
// If the column is an array, then we are accessing the Metadata fields. Skip
if(is_array($type)) {
if(\is_array($type)) {
continue;
}

Expand Down
25 changes: 24 additions & 1 deletion app/src/Model/Table/PetitionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,32 @@ public function initialize(array $config): void {
'statuses' => [
'type' => 'enum',
'class' => 'PetitionStatusEnum'
],
'couIds' => [
'type' => 'select',
'model' => 'Cous'
]
]);


$this->setFilterConfig(
[
'cou_id' => [
// We want to keep the default column configuration and add extra functionality.
// Here the extra functionality is additional to select options since the cou_id
// is of type select
// XXX If the extras key is present, no other provided key will be evaluated. The rest
// of the configuration will be expected from the TableMetaTrait::filterMetadataFields()
'extras' => [
'options' => [
'isnotnull' => __d('operation','any'),
'isnull' => __d('operation','none'),
__d('information','table.list', 'COUs') => '@DATA@',
]
]
]
]
);

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
'entity' => [
Expand Down
2 changes: 1 addition & 1 deletion app/templates/element/filter/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

$label = Inflector::humanize(
Inflector::underscore(
$options['label'] ?? $columns[$key]['label']
strtolower($options['label'] ?? $columns[$key]['label'])
)
);

Expand Down

0 comments on commit 4640e3a

Please sign in to comment.