Skip to content

Commit e4d8655

Browse files
committed
Webservice: Add support service to get social groups/classes of a given user - refs BT#20460
1 parent e0bd097 commit e4d8655

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

main/inc/lib/webservices/Rest.php

+18
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Rest extends WebService
101101
public const DELETE_USER = 'delete_user';
102102
public const GET_USERS_API_KEYS = 'get_users_api_keys';
103103
public const GET_USER_API_KEY = 'get_user_api_key';
104+
public const GET_USER_SUB_GROUP = 'get_user_sub_group';
104105

105106
public const GET_COURSES = 'get_courses';
106107
public const GET_COURSES_FROM_EXTRA_FIELD = 'get_courses_from_extra_field';
@@ -4076,6 +4077,8 @@ public function getGroupSubscribedSessions(int $groupId): array
40764077
/**
40774078
* Add a new user to the given group/class.
40784079
*
4080+
* @param int $groupId
4081+
* @param int $userId
40794082
* @param int $relationType (1:admin, 2:reader, etc. See GROUP_USER_PERMISSION_ constants in api.lib.php)
40804083
*
40814084
* @return array One item array containing true on success, false otherwise
@@ -4087,6 +4090,21 @@ public function addGroupSubscribedUser(int $groupId, int $userId, int $relationT
40874090
return [$userGroup->add_user_to_group($userId, $groupId, $relationType)];
40884091
}
40894092

4093+
/**
4094+
* Get the list of group/class IDs to which the user belongs.
4095+
*
4096+
* @param int $userId
4097+
*
4098+
* @return array Array containing the group IDs like ['groups' => [1, 2, 3]]
4099+
*/
4100+
public function getUserSubGroup(int $userId): array
4101+
{
4102+
$userGroup = new UserGroup();
4103+
4104+
$res = $userGroup->get_usergroup_by_user($userId);
4105+
return ['groups' => $res];
4106+
}
4107+
40904108
/**
40914109
* Add a new course to which the given group/class is subscribed.
40924110
*

main/webservices/api/v2.php

+10
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,16 @@
627627
)
628628
);
629629
break;
630+
case Rest::GET_USER_SUB_GROUP:
631+
$userId = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
632+
if (empty($userId)) {
633+
throw new Exception('user_id not provided');
634+
}
635+
636+
Event::addEvent(LOG_WS.$action, 'user_id', $userId);
637+
$data = $restApi->getUserSubGroup($userId);
638+
$restResponse->setData($data);
639+
break;
630640
case Rest::GET_COURSES:
631641
$campusId = api_get_current_access_url_id();
632642
if (!empty($_POST['id_campus'])) {

0 commit comments

Comments
 (0)