Skip to content

Commit

Permalink
Return distinct records
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed Oct 2, 2023
1 parent 1826c32 commit e30366a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/src/Controller/PeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// XXX not doing anything with Log yet
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use http\QueryString;

class PeopleController extends StandardController {
public $paginate = [
Expand All @@ -49,7 +50,8 @@ class PeopleController extends StandardController {
'sortableFields' => [
'PrimaryName.given',
'PrimaryName.family'
]
],
'finder' => 'indexed'
];

/**
Expand Down
8 changes: 6 additions & 2 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,13 @@ public function index() {
if(!empty($link->attr)) {
// If a link attribute is defined but no value is provided, then query
// where the link attribute is NULL
$query = $table->find()->where([$table->getAlias().'.'.$link->attr => $link->value]);
// "all" is the default finder. But since we are utilizing the paginator here, we will check the configuration
// for any custom finder.
$query = $table->find(
$this->paginate['finder'] ?? "all"
)->where([$table->getAlias().'.'.$link->attr => $link->value]);
} else {
$query = $table->find();
$query = $table->find($this->paginate['finder'] ?? "all");
}

// QueryModificationTrait
Expand Down
24 changes: 24 additions & 0 deletions app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function initialize(array $config): void {
->setDependent(true)
->setCascadeCallbacks(true);
$this->hasMany('GroupOwners')
->setClassName('GroupMembers')
->setDependent(true)
->setCascadeCallbacks(true);
$this->hasMany('HistoryRecords')
Expand Down Expand Up @@ -249,6 +250,29 @@ public function beforeDelete(\Cake\Event\Event $event, $entity, \ArrayObject $op
return true;
}

/**
* Customized finder for the Index Population View
*
* @param Query $query Cake ORM Query
* @param array $options Cake ORM Query options
*
* @return CakeORMQuery Cake ORM Query
* @since COmanage Registry v5.0.0
*/
public function findIndexed(Query $query, array $options): Query {
return $query->select([
'People.id',
'PrimaryName.given',
'PrimaryName.family',
'People.status',
'People.created',
'People.modified',
'People.timezone',
'People.date_of_birth'
])
->distinct();
}

/**
* Table specific logic to generate a display field.
*
Expand Down
3 changes: 0 additions & 3 deletions app/templates/element/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,3 @@

<?= $this->Form->end(); ?>

<!--<pre>-->
<!-- --><?//= print_r($vv_searchable_attributes) ?>
<!--</pre>-->

0 comments on commit e30366a

Please sign in to comment.