Skip to content

Commit

Permalink
Webservice: Add support service to get social groups/classes of a giv…
Browse files Browse the repository at this point in the history
…en user - refs BT#20460
  • Loading branch information
ywarnier committed Sep 25, 2023
1 parent e0bd097 commit e4d8655
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main/inc/lib/webservices/Rest.php
Expand Up @@ -101,6 +101,7 @@ class Rest extends WebService
public const DELETE_USER = 'delete_user';
public const GET_USERS_API_KEYS = 'get_users_api_keys';
public const GET_USER_API_KEY = 'get_user_api_key';
public const GET_USER_SUB_GROUP = 'get_user_sub_group';

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

/**
* Get the list of group/class IDs to which the user belongs.
*
* @param int $userId
*
* @return array Array containing the group IDs like ['groups' => [1, 2, 3]]
*/
public function getUserSubGroup(int $userId): array
{
$userGroup = new UserGroup();

$res = $userGroup->get_usergroup_by_user($userId);
return ['groups' => $res];
}

/**
* Add a new course to which the given group/class is subscribed.
*
Expand Down
10 changes: 10 additions & 0 deletions main/webservices/api/v2.php
Expand Up @@ -627,6 +627,16 @@
)
);
break;
case Rest::GET_USER_SUB_GROUP:
$userId = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
if (empty($userId)) {
throw new Exception('user_id not provided');
}

Event::addEvent(LOG_WS.$action, 'user_id', $userId);
$data = $restApi->getUserSubGroup($userId);
$restResponse->setData($data);
break;
case Rest::GET_COURSES:
$campusId = api_get_current_access_url_id();
if (!empty($_POST['id_campus'])) {
Expand Down

0 comments on commit e4d8655

Please sign in to comment.