Skip to content

Commit

Permalink
Don't return duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
blackcoder87 committed Dec 18, 2024
1 parent 1c411bc commit 8ae5401
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/modules/user/mappers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function getUserListByGroupId(int $groupId, int $confirmed = 0, $paginati

/**
* Get users (not all fields) by group ids. The users have to be in at least one of the groups.
* This will return duplicated users if a user is in multiple of the groups.
*
* @param int[] $groupIds array of group ids.
* @param int $confirmed
Expand All @@ -133,7 +132,8 @@ public function getUserListByGroupIds(array $groupIds, int $confirmed = 0, $pagi
->from(['u' => 'users'])
->join(['g' => 'users_groups'], 'u.id = g.user_id', 'LEFT', ['group_id' => 'g.group_id'])
->where(['group_id' => $groupIds], 'or')
->andWhere(['confirmed' => $confirmed]);
->andWhere(['confirmed' => $confirmed])
->group(['u.id']);
if ($pagination !== null) {
$select->limit($pagination->getLimit())
->useFoundRows();
Expand Down
10 changes: 4 additions & 6 deletions tests/modules/user/mappers/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,15 @@ public function testGetUserListByGroupIds()
/** @var \Modules\User\Models\User[] $users */
$users = $userMapper->getUserListByGroupIds([1, 3], 1);
self::assertNotEmpty($users);
self::assertCount(2, $users);

self::assertEquals(1, $users[0]->getId());
self::assertEquals('Testuser1', $users[0]->getName());
self::assertEquals(1, $users[0]->getConfirmed());

self::assertEquals(1, $users[1]->getId());
self::assertEquals('Testuser1', $users[1]->getName());
self::assertEquals(2, $users[1]->getId());
self::assertEquals('Testuser2', $users[1]->getName());
self::assertEquals(1, $users[1]->getConfirmed());

self::assertEquals(2, $users[2]->getId());
self::assertEquals('Testuser2', $users[2]->getName());
self::assertEquals(1, $users[2]->getConfirmed());
}

/**
Expand Down

0 comments on commit 8ae5401

Please sign in to comment.