From 18cbfe9b1ec501b934f533d538f3fcb11a58c93b Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 17:50:48 +0000 Subject: [PATCH] Displays embeded files in assessment forms --- .../grading/accumulative/assessment_form.php | 2 +- .../grading/accumulative/strategy.php | 9 ++- mod/workshop/lib.php | 69 +++++++++++-------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/mod/workshop/grading/accumulative/assessment_form.php b/mod/workshop/grading/accumulative/assessment_form.php index 99d9cbe8cc9..b847ed8d2e7 100644 --- a/mod/workshop/grading/accumulative/assessment_form.php +++ b/mod/workshop/grading/accumulative/assessment_form.php @@ -57,7 +57,7 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form { // dimension description $desc = '
'."\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
"; $mform->addElement('html', $desc); diff --git a/mod/workshop/grading/accumulative/strategy.php b/mod/workshop/grading/accumulative/strategy.php index 25130b8b9d8..bbb4b326535 100644 --- a/mod/workshop/grading/accumulative/strategy.php +++ b/mod/workshop/grading/accumulative/strategy.php @@ -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; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 67654b704c4..4793818a250 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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; } /**