Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when filtering by empty user group #456

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions src/Users/Models/UserFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@
*/
public function filter(?array $params = null)
{
// two ways to go; if we have to search by groups, we have
// to perform two queries instead of one to avoid duplicates

if (isset($params['role']) && count($params['role'])) {
$secondQuery = true;
$this->select('users.id');
$this->distinct();

Check failure on line 71 in src/Users/Models/UserFilter.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 Static Analysis

Call to an undefined method Bonfire\Users\Models\UserFilter::distinct().

Check failure on line 71 in src/Users/Models/UserFilter.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 Static Analysis

Call to an undefined method Bonfire\Users\Models\UserFilter::distinct().

Check failure on line 71 in src/Users/Models/UserFilter.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Static Analysis

Call to an undefined method Bonfire\Users\Models\UserFilter::distinct().

Check failure on line 71 in src/Users/Models/UserFilter.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Static Analysis

Call to an undefined method Bonfire\Users\Models\UserFilter::distinct().
$this->select('users.*');
$this->join('auth_groups_users agu', 'agu.user_id = users.id')
->whereIn('agu.group', $params['role']);
} else {
$secondQuery = false;
$this->select('users.*');
}

if (isset($params['active']) && count($params['active'])) {
Expand All @@ -102,19 +98,6 @@
}
// omitting 'where' for $params['last_active'] == 'all'

// if we need second query to avoid duplicates:
if ($secondQuery) {
$idList = $this->findAll();
$in = [];

foreach ($idList as $v) {
$in[] = $v->id;
}
$nodup = array_unique($in);
$this->select('users.*');
$this->whereIn('id', $nodup);
}

return $this;
}

Expand Down
Loading