]> git.mjollnir.org Git - moodle.git/commitdiff
Displays embeded files in assessment forms
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:50:48 +0000 (17:50 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:50:48 +0000 (17:50 +0000)
mod/workshop/grading/accumulative/assessment_form.php
mod/workshop/grading/accumulative/strategy.php
mod/workshop/lib.php

index 99d9cbe8cc9ee54fe1ffe0f626fe2784e190af53..b847ed8d2e71fb0b1358203c72bd3f2b8397fa8e 100644 (file)
@@ -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);
 
index 25130b8b9d8ac0481fb08f051b8944a6e01bfca3..bbb4b326535ec3b18e82fc7878f1c6a3cca02b9e 100644 (file)
@@ -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;
index 67654b704c406239b12891281e71bd40193fd1f7..4793818a2501e36006ce137c877a89fe0f94974a 100644 (file)
@@ -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;
 }
 
 /**