WebServices: download attachments from assignments

pull/3955/head
Angel Fernando Quiroz Campos 4 years ago
parent 655124a7d9
commit 47465bf5d5
  1. 36
      main/inc/lib/webservices/Rest.php
  2. 23
      main/webservices/api/v2.php

@ -69,6 +69,9 @@ class Rest extends WebService
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';
const DOWNLOAD_WORK_FOLDER = 'download_work_folder';
const DOWNLOAD_WORK_COMMENT_ATTACHMENT = 'download_work_comment_attachment';
const DOWNLOAD_WORK = 'download_work';
const VIEW_DOCUMENT_IN_FRAME = 'view_document_in_frame';
@ -2964,6 +2967,39 @@ class Rest extends WebService
exit;
}
public function downloadWorkFolder(int $workId)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/downloadfolder.inc.php?id=$workId&$cidReq";
header("Location: $url");
exit;
}
public function downloadWorkCommentAttachment(int $commentId)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/download_comment_file.php?comment_id=$commentId&$cidReq";
header("Location: $url");
exit;
}
public function downloadWork(int $workId, bool $isCorrection = false)
{
$cidReq = api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH)."work/download.php?$cidReq&"
.http_build_query(
[
'id' => $workId,
'correction' => $isCorrection ? 1 : null,
]
);
header("Location: $url");
exit;
}
public static function isAllowedByRequest(bool $inpersonate = false): bool
{
$username = $_GET['username'] ?? null;

@ -402,6 +402,29 @@ try {
]
);
break;
case Rest::DOWNLOAD_WORK_FOLDER:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
$restApi->downloadWorkFolder((int) $_GET['work']);
break;
case Rest::DOWNLOAD_WORK_COMMENT_ATTACHMENT:
if (!isset($_GET['comment'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
$restApi->downloadWorkCommentAttachment((int) $_GET['comment']);
break;
case Rest::DOWNLOAD_WORK:
if (!isset($_GET['work'])) {
throw new Exception(get_lang('ActionNotAllowed'));
}
$isCorrection = isset($_GET['correction']);
$restApi->downloadWork((int) $_GET['work'], $isCorrection);
break;
case Rest::VIEW_DOCUMENT_IN_FRAME:
$lpId = isset($_REQUEST['document']) ? (int) $_REQUEST['document'] : 0;

Loading…
Cancel
Save