WebServices: get work list (details for works)

pull/3953/head
Angel Fernando Quiroz Campos 4 years ago
parent 8f79a6f763
commit 5ab7fe025b
  1. 64
      main/inc/lib/webservices/Rest.php
  2. 9
      main/webservices/api/v2.php

@ -60,6 +60,7 @@ class Rest extends WebService
const SAVE_FORUM_THREAD = 'save_forum_thread';
const SET_THREAD_NOTIFY = 'set_thread_notify';
const GET_WORK_LIST = 'get_work_list';
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';
@ -2653,6 +2654,69 @@ class Rest extends WebService
return get_lang('Deleted');
}
public function getWorkList(int $workId): array
{
$isAllowedToEdit = api_is_allowed_to_edit();
Event::event_access_tool(TOOL_STUDENTPUBLICATION);
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$userId = $this->user->getId();
$courseId = $this->course->getId();
$sessionId = $this->session ? $this->session->getId() : 0;
$courseInfo = api_get_course_info_by_id($courseId);
$webPath = api_get_path(WEB_PATH);
$whereCondition = !$isAllowedToEdit ? " AND u.id = $userId" : '';
$works = get_work_user_list(
0,
0,
'title',
'asc',
$workId,
$whereCondition,
null,
false,
$courseId,
$sessionId
);
return array_map(
function (array $work) use ($courseInfo, $webPath) {
$itemId = $work['id'];
$count = getWorkCommentCount($itemId, $courseInfo);
$work['feedback'] = $count.' '.Display::returnFontAwesomeIcon('comments-o');
$work['feedback_clean'] = $count;
$workInfo = get_work_data_by_id($itemId);
$commentsTmp = getWorkComments($workInfo);
$comments = [];
foreach ($commentsTmp as $comment) {
$comment['comment'] = str_replace('src="/', 'src="'.$webPath.'app/', $comment['comment']);
$comments[] = $comment;
}
$work['comments'] = $comments;
if (empty($workInfo['qualificator_id'])) {
$qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
} else {
$qualificator_id = Display::label(get_lang('Revised'), 'success');
}
$work['qualificator_id'] = $qualificator_id;
return $work;
},
$works
);
}
public static function isAllowedByRequest(bool $inpersonate = false): bool
{
$username = $_GET['username'] ?? null;

@ -296,6 +296,15 @@ try {
);
break;
case Rest::GET_WORK_LIST:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
$restResponse->setData(
$restApi->getWorkList((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