WebServices: get work users

pull/3953/head
Angel Fernando Quiroz Campos 5 years ago
parent 475fde3f8c
commit 7e2d42c0e7
  1. 66
      main/inc/lib/webservices/Rest.php
  2. 13
      main/webservices/api/v2.php

@ -62,6 +62,7 @@ class Rest extends WebService
const GET_WORK_LIST = 'get_work_list';
const GET_WORK_STUDENTS_WITHOUT_PUBLICATIONS = 'get_work_students_without_publications';
const GET_WORK_USERS = 'get_work_users';
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility';
const DELETE_WORK_STUDENT_ITEM = 'delete_work_student_item';
const DELETE_WORK_CORRECTIONS = 'delete_work_corrections';
@ -2727,6 +2728,71 @@ class Rest extends WebService
return get_list_users_without_publication($workId);
}
public function getWorkUsers(int $workId): array
{
Event::event_access_tool(TOOL_STUDENTPUBLICATION);
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$courseId = $this->course->getId();
$sessionId = $this->session ? $this->session->getId() : 0;
$courseInfo = api_get_course_info_by_id($courseId);
$items = getAllUserToWork($workId, $courseId);
$usersAdded = [];
$result = [
'users_added' => [],
'users_to_add' => [],
];
if (!empty($items)) {
foreach ($items as $data) {
$usersAdded[] = $data['user_id'];
$userInfo = api_get_user_info($data['user_id']);
$result['users_added'][] = [
'user_id' => (int) $data['user_id'],
'complete_name_with_username' => $userInfo['complete_name_with_username'],
];
}
}
if (empty($sessionId)) {
$status = STUDENT;
} else {
$status = 0;
}
$userList = CourseManager::get_user_list_from_course_code(
$courseInfo['code'],
$sessionId,
null,
null,
$status
);
$userToAddList = [];
foreach ($userList as $user) {
if (!in_array($user['user_id'], $usersAdded)) {
$userToAddList[] = $user;
}
}
if (!empty($userToAddList)) {
foreach ($userToAddList as $user) {
$userName = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
$result['users_to_add'][] = [
'user_id' => (int) $user['user_id'],
'complete_name_with_username' => $userName,
];
}
}
return $result;
}
public static function isAllowedByRequest(bool $inpersonate = false): bool
{
$username = $_GET['username'] ?? null;

@ -318,6 +318,19 @@ try {
$restApi->getWorkStudentsWithoutPublications((int) $_GET['work'])
);
break;
case Rest::GET_WORK_USERS:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
if (!api_is_allowed_to_edit()) {
throw new Exception(get_lang('NotAllowed'));
}
$restResponse->setData(
$restApi->getWorkUsers((int) $_GET['work'])
);
break;
case Rest::PUT_WORK_STUDENT_ITEM_VISIBILITY:
if (!isset($_POST['status'], $_POST['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));

Loading…
Cancel
Save