Skip to content

Commit

Permalink
add filtering with given and family name. Fetch only active users.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Mar 13, 2024
1 parent 772b865 commit 99fab63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions app/src/Lib/Traits/IndexQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace App\Lib\Traits;

use App\Lib\Enum\StatusEnum;
use Cake\Database\Expression\QueryExpression;
use Cake\ORM\Query;

trait IndexQueryTrait {
Expand Down Expand Up @@ -98,12 +100,12 @@ public function constructGetIndexContains(Query $query): object {
/**
* Build the Index Query
*
* @params boolean $mode True for OR and False for AND. AND is the default behavior
* @params boolean $picker_mode True for OR and False for AND. AND is the default behavior
*
* @return object Cake ORM Query object
* @since COmanage Registry v5.0.0
*/
public function getIndexQuery(bool $mode = false): object {
public function getIndexQuery(bool $picker_mode = false): object {
// $this->name = Models
$modelsName = $this->name;
// $table = the actual table object
Expand All @@ -116,7 +118,7 @@ public function getIndexQuery(bool $mode = false): object {
$newexp = $query->newExpr();
// The searchable attributes can have an AND or an OR conjunction. The first one is used from the filtering block
// while the second one from the picker vue module.
$newexp = $newexp->setConjunction($mode ? 'OR' : 'AND');
$newexp = $newexp->setConjunction($picker_mode ? 'OR' : 'AND');

if(!empty($link->attr) && !empty($link->value)) {
// If a link attribute is defined but no value is provided, then query
Expand Down Expand Up @@ -155,6 +157,12 @@ public function getIndexQuery(bool $mode = false): object {
}
}

if($picker_mode) {
// Get only the active People
// XXX Perhaps we need to make this a configuration
$query = $query->where(fn(QueryExpression $exp, Query $query) => $exp->in($table->getAlias().'.status', [StatusEnum::Active, StatusEnum::GracePeriod]));
}

// Append the new conditions
$query = $query->where($newexp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export default {
const queryParams =
`identifier=${event.query}` +
`&mail=${event.query}` +
`&name=${event.query}` +
`&family=${event.query}` +
`&given=${event.query}` +
`&limit=10`

// AJAX Request
Expand Down

0 comments on commit 99fab63

Please sign in to comment.