|
33 | 33 | require_once("$CFG->libdir/file/file_info_coursecat.php");
|
34 | 34 | require_once("$CFG->libdir/file/file_info_course.php");
|
35 | 35 | require_once("$CFG->libdir/file/file_info_coursesection.php");
|
| 36 | +require_once("$CFG->libdir/file/file_info_coursesectionbackup.php"); |
36 | 37 | require_once("$CFG->libdir/file/file_info_coursefile.php");
|
37 | 38 | require_once("$CFG->libdir/file/virtual_root_file.php");
|
38 | 39 |
|
@@ -317,7 +318,7 @@ private function get_file_info_course($context, $filearea=null, $itemid=null, $f
|
317 | 318 | return null;
|
318 | 319 | }
|
319 | 320 |
|
320 |
| - if (!is_null($filearea) and !in_array($filearea, array('course_intro', 'course_content', 'course_section', 'course_backup'))) { |
| 321 | + if (!is_null($filearea) and !in_array($filearea, array('course_intro', 'course_content', 'course_section', 'course_backup', 'section_backup'))) { |
321 | 322 | // file area does not exist, sorry
|
322 | 323 | $filearea = null;
|
323 | 324 | }
|
@@ -422,6 +423,39 @@ private function get_file_info_course_backup($course, $context, $filearea=null,
|
422 | 423 |
|
423 | 424 | }
|
424 | 425 |
|
| 426 | + private function get_file_info_section_backup($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) { |
| 427 | + global $CFG, $DB; |
| 428 | + |
| 429 | + $fs = get_file_storage(); |
| 430 | + if (empty($itemid)) { |
| 431 | + // list all sections |
| 432 | + return new file_info_coursesectionbackup($this, $context, $course); |
| 433 | + } |
| 434 | + |
| 435 | + if (!has_capability('moodle/backup:backupcourse', $context) and !has_capability('moodle/restore:restorecourse', $context)) { |
| 436 | + return null; |
| 437 | + } |
| 438 | + |
| 439 | + if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'id'=>$itemid))) { |
| 440 | + return null; // does not exist |
| 441 | + } |
| 442 | + |
| 443 | + |
| 444 | + $urlbase = $CFG->wwwroot.'/pluginfile.php'; |
| 445 | + if (!$storedfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) { |
| 446 | + if ($filepath === '/' and $filename === '.') { |
| 447 | + $storedfile = new virtual_root_file($context->id, $filearea, $itemid); |
| 448 | + } else { |
| 449 | + // not found |
| 450 | + return null; |
| 451 | + } |
| 452 | + } |
| 453 | + |
| 454 | + $downloadable = has_capability('moodle/backup:downloadfile', $context); |
| 455 | + $uploadable = has_capability('moodle/restore:uploadfile', $context); |
| 456 | + return new file_info_stored($this, $context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false); |
| 457 | + } |
| 458 | + |
425 | 459 | private function get_file_info_course_content($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
426 | 460 | $fs = get_file_storage();
|
427 | 461 |
|
@@ -484,15 +518,24 @@ private function get_file_info_module($context, $filearea=null, $itemid=null, $f
|
484 | 518 | and has_capability('moodle/course:managefiles', $context)) {
|
485 | 519 | $areas = array_merge(array($modname.'_intro'=>get_string('moduleintro')), $areas);
|
486 | 520 | }
|
| 521 | + |
| 522 | + if (has_capability('moodle/backup:downloadfile', $context)) { |
| 523 | + $areas = array_merge(array('activity_backup'=>get_string('activitybackup', 'repository')), $areas); |
| 524 | + } |
| 525 | + |
487 | 526 | if (empty($areas)) {
|
488 | 527 | return null;
|
489 | 528 | }
|
490 | 529 |
|
491 |
| - if ($filearea === $modname.'_intro') { |
| 530 | + if ($filearea === $modname.'_intro' || $filearea === 'activity_backup') { |
492 | 531 | // always only itemid 0
|
493 | 532 | if (!has_capability('moodle/course:managefiles', $context)) {
|
494 | 533 | return null;
|
495 | 534 | }
|
| 535 | + // need downloadfile cap when accessing activity_backup area |
| 536 | + if ($filearea === 'activity_backup' && !has_capability('moodle/backup:downloadfile', $context)) { |
| 537 | + return null; |
| 538 | + } |
496 | 539 |
|
497 | 540 | $filepath = is_null($filepath) ? '/' : $filepath;
|
498 | 541 | $filename = is_null($filename) ? '.' : $filename;
|
|
0 commit comments