Skip to content

Commit

Permalink
Remove viewConfigParameter:for. Left join both group members and non …
Browse files Browse the repository at this point in the history
…group members.
  • Loading branch information
Ioannis committed Aug 20, 2024
1 parent e3042f7 commit d0fc590
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/src/Lib/Traits/IndexQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ public function getIndexQuery(bool $pickerMode = false, array $requestParams = [
$query = $query->where(fn(QueryExpression $exp, Query $query) => $exp->in($table->getAlias().'.status', [StatusEnum::Active, StatusEnum::GracePeriod]));

// Specific expressions per view
$query = match($requestParams['for'] ?? '') {
$query = match(true) {
// GroupMembers Add view: We need to filter the active members
'GroupMembers' => $query->leftJoinWith('GroupMembers', fn($q) => $q->where(['GroupMembers.group_id' => (int)($requestParams['group_id'] ?? -1)]))
->where($this->getTableLocator()->get('GroupMembers')->checkValidity($query))
->where(fn(QueryExpression $exp, Query $query) => $exp->isNull('GroupMembers.' . StringUtilities::classNameToForeignKey($table->getAlias()))),
(isset($requestParams['group_id']) && $modelsName === 'People') => $query
->leftJoinWith('GroupMembers', fn($q) => $q->where(['GroupMembers.group_id' => (int)($requestParams['group_id'] ?? -1)])),
// XXX We want to get both members and not members. The frontend will handle the rest
// ->where($this->getTableLocator()->get('GroupMembers')->checkValidity($query))
// ->where(fn(QueryExpression $exp, Query $query) => $exp->isNull('GroupMembers.' . StringUtilities::classNameToForeignKey($table->getAlias()))),
// Just return the query
default => $query
};
Expand Down
1 change: 0 additions & 1 deletion app/templates/GroupMembers/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ $subnav = [
$peoplePicker = [
'label' => __d('operation','add.member'),
'viewConfigParameters' => [
'for' => 'GroupMembers',
'groupId' => $this->getRequest()?->getQuery('group_id')
],
'actionUrl' => [
Expand Down
2 changes: 1 addition & 1 deletion app/templates/element/peopleAutocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
viewConfigParameters: <?= json_encode($viewConfigParameters) ?>,
webroot: '<?= $this->request->getAttribute('webroot') ?>',
// co_id query parameter is required since it is the People's primary link
searchPeople: `<?= $this->request->getAttribute('webroot') ?>api/ajax/v2/people/pick?co_id=<?= $vv_cur_co->id ?>&for=<?= $viewConfigParameters['for'] ?>`
searchPeople: `<?= $this->request->getAttribute('webroot') ?>api/ajax/v2/people/pick?co_id=<?= $vv_cur_co->id ?>`
}
}

Expand Down

0 comments on commit d0fc590

Please sign in to comment.