mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
Displays embeded files in assessment forms
This commit is contained in:
parent
c2441dd872
commit
18cbfe9b1e
@ -57,7 +57,7 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
|
||||
|
||||
// dimension description
|
||||
$desc = '<div id="id_dim_'.$fields['dimensionid__idx_'.$i].'_desc" class="fitem description accumulative">'."\n";
|
||||
$desc .= format_text($fields['description__idx_'.$i], $fields['descriptionformat__idx_'.$i]);
|
||||
$desc .= format_text($fields['description__idx_'.$i], $fields['description__idx_'.$i.'format']);
|
||||
$desc .= "\n</div>";
|
||||
$mform->addElement('html', $desc);
|
||||
|
||||
|
@ -81,7 +81,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
$norepeats += WORKSHOP_STRATEGY_ADDDIMS;
|
||||
}
|
||||
|
||||
// prepare the emebeded files
|
||||
// prepare the embeded files
|
||||
for ($i = 0; $i < $this->nodimensions; $i++) {
|
||||
// prepare all editor elements
|
||||
$fields = file_prepare_standard_editor($fields, 'description__idx_'.$i, $this->descriptionopts,
|
||||
@ -252,6 +252,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
*/
|
||||
public function get_assessment_form(moodle_url $actionurl=null, $mode='preview') {
|
||||
global $CFG; // needed because the included files use it
|
||||
global $PAGE;
|
||||
require_once(dirname(__FILE__) . '/assessment_form.php');
|
||||
|
||||
$fields = $this->load_fields();
|
||||
@ -259,6 +260,12 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
throw new coding_exception('You forgot to set the number of dimensions in load_fields()');
|
||||
}
|
||||
|
||||
// rewrite URLs to the embeded files
|
||||
for ($i = 0; $i < $this->nodimensions; $i++) {
|
||||
$fields->{'description__idx_'.$i} = file_rewrite_pluginfile_urls($fields->{'description__idx_'.$i},
|
||||
'pluginfile.php', $PAGE->context->id, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
|
||||
}
|
||||
|
||||
// set up the required custom data common for all strategies
|
||||
$customdata['strategy'] = $this;
|
||||
$customdata['mode'] = $mode;
|
||||
|
@ -309,45 +309,56 @@ function workshop_pluginfile($course, $cminfo, $context, $filearea, $args, $forc
|
||||
if (!$cminfo->uservisible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fileareas = array('workshop_submission_content', 'workshop_submission_attachment', 'workshop_dimension_description');
|
||||
if (!in_array($filearea, $fileareas)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$submissionid = (int)array_shift($args);
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance('workshop', $cminfo->instance, $course->id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_course_login($course, true, $cm);
|
||||
|
||||
if (!$submission = $DB->get_record('workshop_submissions', array('id' => $submissionid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$workshop = $DB->get_record('workshop', array('id' => $cminfo->instance))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
$relativepath = '/' . implode('/', $args);
|
||||
$fullpath = $context->id . $filearea . $submissionid . $relativepath;
|
||||
if ((!$file = $fs->get_file_by_hash(sha1($fullpath))) || ($file->is_directory())) {
|
||||
return false;
|
||||
}
|
||||
// TODO make sure the user is allowed to see the file
|
||||
|
||||
// finally send the file
|
||||
if ('workshop_dimension_description' == $filearea) {
|
||||
if ($filearea === 'workshop_dimension_description') {
|
||||
$itemid = (int)array_shift($args);
|
||||
if (!$dimension = $DB->get_record('workshop_forms', array('id' => $itemid))) {
|
||||
return false;
|
||||
}
|
||||
if (!$workshop = $DB->get_record('workshop', array('id' => $cminfo->instance))) {
|
||||
return false;
|
||||
}
|
||||
if ($workshop->id !== $dimension->workshopid) {
|
||||
// this should never happen but just in case
|
||||
return false;
|
||||
}
|
||||
// TODO now make sure the user is allowed to see the file
|
||||
// media embedded by teacher into the dimension description
|
||||
$fs = get_file_storage();
|
||||
$relativepath = '/' . implode('/', $args);
|
||||
$fullpath = $context->id . $filearea . $itemid . $relativepath;
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||
return false;
|
||||
}
|
||||
// finally send the file
|
||||
send_stored_file($file);
|
||||
}
|
||||
|
||||
} else {
|
||||
// files uploaded by students in their attachments - forcing download for security reasons
|
||||
if ($filearea === 'workshop_submission_content' or $filearea === 'workshop_submission_attachment') {
|
||||
$itemid = (int)array_shift($args);
|
||||
if (!$submission = $DB->get_record('workshop_submissions', array('id' => $itemid))) {
|
||||
return false;
|
||||
}
|
||||
if (!$workshop = $DB->get_record('workshop', array('id' => $cminfo->instance))) {
|
||||
return false;
|
||||
}
|
||||
// TODO now make sure the user is allowed to see the file
|
||||
$fs = get_file_storage();
|
||||
$relativepath = '/' . implode('/', $args);
|
||||
$fullpath = $context->id . $filearea . $itemid . $relativepath;
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||
return false;
|
||||
}
|
||||
// finally send the file
|
||||
// these files are uploaded by students - forcing download for security reasons
|
||||
send_stored_file($file, 0, 0, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user