Skip to content

Commit 47465bf

Browse files
committed
WebServices: download attachments from assignments
1 parent 655124a commit 47465bf

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

main/inc/lib/webservices/Rest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class Rest extends WebService
6969
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility';
7070
const DELETE_WORK_STUDENT_ITEM = 'delete_work_student_item';
7171
const DELETE_WORK_CORRECTIONS = 'delete_work_corrections';
72+
const DOWNLOAD_WORK_FOLDER = 'download_work_folder';
73+
const DOWNLOAD_WORK_COMMENT_ATTACHMENT = 'download_work_comment_attachment';
74+
const DOWNLOAD_WORK = 'download_work';
7275

7376
const VIEW_DOCUMENT_IN_FRAME = 'view_document_in_frame';
7477

@@ -2964,6 +2967,39 @@ public function downloadForumPostAttachment(string $path)
29642967
exit;
29652968
}
29662969

2970+
public function downloadWorkFolder(int $workId)
2971+
{
2972+
$cidReq = api_get_cidreq();
2973+
$url = api_get_path(WEB_CODE_PATH)."work/downloadfolder.inc.php?id=$workId&$cidReq";
2974+
2975+
header("Location: $url");
2976+
exit;
2977+
}
2978+
2979+
public function downloadWorkCommentAttachment(int $commentId)
2980+
{
2981+
$cidReq = api_get_cidreq();
2982+
$url = api_get_path(WEB_CODE_PATH)."work/download_comment_file.php?comment_id=$commentId&$cidReq";
2983+
2984+
header("Location: $url");
2985+
exit;
2986+
}
2987+
2988+
public function downloadWork(int $workId, bool $isCorrection = false)
2989+
{
2990+
$cidReq = api_get_cidreq();
2991+
$url = api_get_path(WEB_CODE_PATH)."work/download.php?$cidReq&"
2992+
.http_build_query(
2993+
[
2994+
'id' => $workId,
2995+
'correction' => $isCorrection ? 1 : null,
2996+
]
2997+
);
2998+
2999+
header("Location: $url");
3000+
exit;
3001+
}
3002+
29673003
public static function isAllowedByRequest(bool $inpersonate = false): bool
29683004
{
29693005
$username = $_GET['username'] ?? null;

main/webservices/api/v2.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,29 @@
402402
]
403403
);
404404
break;
405+
case Rest::DOWNLOAD_WORK_FOLDER:
406+
if (!isset($_GET['work'])) {
407+
throw new Exception(get_lang('ActionNotAllowed'));
408+
}
409+
410+
$restApi->downloadWorkFolder((int) $_GET['work']);
411+
break;
412+
case Rest::DOWNLOAD_WORK_COMMENT_ATTACHMENT:
413+
if (!isset($_GET['comment'])) {
414+
throw new Exception(get_lang('ActionNotAllowed'));
415+
}
416+
417+
$restApi->downloadWorkCommentAttachment((int) $_GET['comment']);
418+
break;
419+
case Rest::DOWNLOAD_WORK:
420+
if (!isset($_GET['work'])) {
421+
throw new Exception(get_lang('ActionNotAllowed'));
422+
}
423+
424+
$isCorrection = isset($_GET['correction']);
425+
426+
$restApi->downloadWork((int) $_GET['work'], $isCorrection);
427+
break;
405428

406429
case Rest::VIEW_DOCUMENT_IN_FRAME:
407430
$lpId = isset($_REQUEST['document']) ? (int) $_REQUEST['document'] : 0;

0 commit comments

Comments
 (0)