From a483e62725177a48f9d4c78c2dcd7a6b68419a1a Mon Sep 17 00:00:00 2001 From: Lucas van Lierop Date: Tue, 29 Nov 2016 14:57:45 +0000 Subject: [PATCH] Support searching for multiple roles --- src/AppBundle/Controller/GroupController.php | 6 +++--- src/AppBundle/Manager/MembershipManager.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AppBundle/Controller/GroupController.php b/src/AppBundle/Controller/GroupController.php index 4323339..f908362 100644 --- a/src/AppBundle/Controller/GroupController.php +++ b/src/AppBundle/Controller/GroupController.php @@ -260,7 +260,7 @@ public function deleteGroupAction($id) * {"name"="sort", "dataType"="string", "required"=false, "description"="sort property, prefix with '-' to change the order"}, * {"name"="query", "dataType"="string", "required"=false, "description"="search filter"}, * {"name"="users", "dataType"="array", "required"=false, "description"="array with user ids"}, - * {"name"="role", "dataType"="string", "required"=false, "description"="role filter"} + * {"name"="roles", "dataType"="array", "required"=false, "description"="role filter"} * }, * output="ArrayCollection", * statusCodes = { @@ -284,9 +284,9 @@ public function getGroupUsersAction(Request $request, $id) $sort = $request->query->get('sort', 'reference'); $query = $request->query->get('query'); $users = (array)$request->query->get('users'); - $role = $request->query->get('role'); + $roles = $request->query->get('roles'); - $result = $this->get('app.manager.membership')->findMemberships($id, $query, $role, $users, $sort, $offset, $limit); + $result = $this->get('app.manager.membership')->findMemberships($id, $query, $roles, $users, $sort, $offset, $limit); return $this->view($result); } diff --git a/src/AppBundle/Manager/MembershipManager.php b/src/AppBundle/Manager/MembershipManager.php index 31128d5..fec47ef 100644 --- a/src/AppBundle/Manager/MembershipManager.php +++ b/src/AppBundle/Manager/MembershipManager.php @@ -53,7 +53,7 @@ public function findMembership($userId, $groupId) /** * @param int $groupId * @param string $query - * @param string $role + * @param array $roles * @param array $users * @param string $sort * @param int $offset @@ -64,7 +64,7 @@ public function findMembership($userId, $groupId) public function findMemberships( $groupId, $query = null, - $role = null, + array $roles = null, array $users = [], $sort = 'reference', $offset = 0, @@ -97,8 +97,8 @@ public function findMemberships( $limit = count($users); } - if (!empty($role)) { - $qb->andWhere('ug.role = :role')->setParameter('role', $role); + if (!empty($roles)) { + $qb->andWhere($qb->expr()->in('ug.role', $roles)); } if ($sort === 'name') {