MDL-31768 - it is not possible to add a picture to the thanks page in feedback
authorAndreas Grabs <moodle@grabs-edv.de>
Sat, 25 Feb 2012 11:29:57 +0000 (12:29 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 2 Apr 2012 03:16:32 +0000 (11:16 +0800)
mod/feedback/backup/moodle2/backup_feedback_stepslib.php
mod/feedback/backup/moodle2/restore_feedback_stepslib.php
mod/feedback/complete.php
mod/feedback/complete_guest.php
mod/feedback/lib.php
mod/feedback/mod_form.php
mod/feedback/view.php

index b4681c9..2258d8f 100644 (file)
@@ -130,6 +130,7 @@ class backup_feedback_activity_structure_step extends backup_activity_structure_
         // Define file annotations
 
         $feedback->annotate_files('mod_feedback', 'intro', null); // This file area hasn't itemid
+        $feedback->annotate_files('mod_feedback', 'page_after_submit', null); // This file area hasn't itemid
 
         $item->annotate_files('mod_feedback', 'item', 'id');
 
index b2024d4..9a4b373 100644 (file)
@@ -120,6 +120,7 @@ class restore_feedback_activity_structure_step extends restore_activity_structur
     protected function after_execute() {
         // Add feedback related files, no need to match by itemname (just internally handled context)
         $this->add_related_files('mod_feedback', 'intro', null);
+        $this->add_related_files('mod_feedback', 'page_after_submit', null);
         $this->add_related_files('mod_feedback', 'item', 'feedback_item');
     }
 }
index e6fe6cd..1ccf71e 100644 (file)
@@ -375,8 +375,18 @@ if ($feedback_can_submit) {
 
     if (isset($savereturn) && $savereturn == 'saved') {
         if ($feedback->page_after_submit) {
+
+            require_once($CFG->libdir . '/filelib.php');
+
+            $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
+                                                                    'pluginfile.php',
+                                                                    $context->id,
+                                                                    'mod_feedback',
+                                                                    'page_after_submit',
+                                                                    0);
+
             echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-            echo format_text($feedback->page_after_submit,
+            echo format_text($page_after_submit_output,
                              $feedback->page_after_submitformat,
                              array('overflowdiv' => true));
             echo $OUTPUT->box_end();
index a1d8586..25747a9 100644 (file)
@@ -329,8 +329,17 @@ if ($feedback_can_submit) {
 
     if (isset($savereturn) && $savereturn == 'saved') {
         if ($feedback->page_after_submit) {
+            require_once($CFG->libdir . '/filelib.php');
+
+            $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
+                                                                    'pluginfile.php',
+                                                                    $context->id,
+                                                                    'mod_feedback',
+                                                                    'page_after_submit',
+                                                                    0);
+
             echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-            echo format_text($feedback->page_after_submit,
+            echo format_text($page_after_submit_output,
                              $feedback->page_after_submitformat,
                              array('overflowdiv' => true));
             echo $OUTPUT->box_end();
index 45a9a3d..2966559 100644 (file)
@@ -98,6 +98,25 @@ function feedback_add_instance($feedback) {
 
     feedback_set_events($feedback);
 
+    if (!isset($feedback->coursemodule)) {
+        $cm = get_coursemodule_from_id('feedback', $feedback->id);
+        $feedback->coursemodule = $cm->id;
+    }
+    $context = get_context_instance(CONTEXT_MODULE, $feedback->coursemodule);
+
+    $editoroptions = feedback_get_editor_options();
+
+    // process the custom wysiwyg editor in page_after_submit
+    if ($draftitemid = $feedback->page_after_submit_editor['itemid']) {
+        $feedback->page_after_submit = file_save_draft_area_files($draftitemid, $context->id,
+                                                    'mod_feedback', 'page_after_submit',
+                                                    0, $editoroptions,
+                                                    $feedback->page_after_submit_editor['text']);
+
+        $feedback->page_after_submitformat = $feedback->page_after_submit_editor['format'];
+    }
+    $DB->update_record('feedback', $feedback);
+
     return $feedbackid;
 }
 
@@ -131,6 +150,21 @@ function feedback_update_instance($feedback) {
     //create or update the new events
     feedback_set_events($feedback);
 
+    $context = get_context_instance(CONTEXT_MODULE, $feedback->coursemodule);
+
+    $editoroptions = feedback_get_editor_options();
+
+    // process the custom wysiwyg editor in page_after_submit
+    if ($draftitemid = $feedback->page_after_submit_editor['itemid']) {
+        $feedback->page_after_submit = file_save_draft_area_files($draftitemid, $context->id,
+                                                    'mod_feedback', 'page_after_submit',
+                                                    0, $editoroptions,
+                                                    $feedback->page_after_submit_editor['text']);
+
+        $feedback->page_after_submitformat = $feedback->page_after_submit_editor['format'];
+    }
+    $DB->update_record('feedback', $feedback);
+
     return true;
 }
 
@@ -153,20 +187,24 @@ function feedback_update_instance($feedback) {
 function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
     global $CFG, $DB;
 
-    $itemid = (int)array_shift($args);
-
-    //get the item what includes the file
-    if (!$item = $DB->get_record('feedback_item', array('id'=>$itemid))) {
-        return false;
+    if ($filearea === 'item' or $filearea === 'template') {
+        $itemid = (int)array_shift($args);
+        //get the item what includes the file
+        if (!$item = $DB->get_record('feedback_item', array('id'=>$itemid))) {
+            return false;
+        }
+        $feedbackid = $item->feedback;
+        $templateid = $item->template;
     }
 
-    //if the filearea is "item" so we check the permissions like view/complete the feedback
-    if ($filearea === 'item') {
-        //get the feedback
-        if (!$feedback = $DB->get_record('feedback', array('id'=>$item->feedback))) {
+    if ($filearea === 'page_after_submit' or $filearea === 'item') {
+        if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
             return false;
         }
 
+        $feedbackid = $feedback->id;
+
+        //if the filearea is "item" so we check the permissions like view/complete the feedback
         $canload = false;
         //first check whether the user has the complete capability
         if (has_capability('mod/feedback:complete', $context)) {
@@ -191,7 +229,7 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
             return false;
         }
     } else if ($filearea === 'template') { //now we check files in templates
-        if (!$template = $DB->get_record('feedback_template', array('id'=>$item->template))) {
+        if (!$template = $DB->get_record('feedback_template', array('id'=>$templateid))) {
             return false;
         }
 
@@ -210,13 +248,7 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
     }
 
     if ($context->contextlevel == CONTEXT_MODULE) {
-        if ($filearea !== 'item') {
-            return false;
-        }
-
-        if ($item->feedback == $cm->instance) {
-            $filecontext = $context;
-        } else {
+        if ($filearea !== 'item' and $filearea !== 'page_after_submit') {
             return false;
         }
     }
@@ -228,9 +260,14 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
     }
 
     $relativepath = implode('/', $args);
-    $fullpath = "/$context->id/mod_feedback/$filearea/$itemid/$relativepath";
+    if ($filearea === 'page_after_submit') {
+        $fullpath = "/{$context->id}/mod_feedback/$filearea/$relativepath";
+    } else {
+        $fullpath = "/{$context->id}/mod_feedback/$filearea/{$item->id}/$relativepath";
+    }
 
     $fs = get_file_storage();
+
     if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
         return false;
     }
@@ -691,6 +728,16 @@ function feedback_reset_course_form($course) {
     }
 }
 
+/**
+ * This gets an array with default options for the editor
+ *
+ * @return array the options
+ */
+function feedback_get_editor_options() {
+    return array('maxfiles' => EDITOR_UNLIMITED_FILES,
+                'trusttext'=>true);
+}
+
 /**
  * This creates new events given as timeopen and closeopen by $feedback.
  *
index 46faea1..6256de7 100644 (file)
@@ -34,6 +34,8 @@ class mod_feedback_mod_form extends moodleform_mod {
     public function definition() {
         global $CFG, $DB;
 
+        $editoroptions = feedback_get_editor_options();
+
         $mform    =& $this->_form;
 
         //-------------------------------------------------------------------------------
@@ -135,12 +137,12 @@ class mod_feedback_mod_form extends moodleform_mod {
         $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
 
         $mform->addElement('editor',
-                           'page_after_submit',
+                           'page_after_submit_editor',
                            get_string("page_after_submit", "feedback"),
                            null,
-                           null);
+                           $editoroptions);
 
-        $mform->setType('page_after_submit', PARAM_RAW);
+        $mform->setType('page_after_submit_editor', PARAM_RAW);
 
         $mform->addElement('text',
                            'site_after_submit',
@@ -167,21 +169,38 @@ class mod_feedback_mod_form extends moodleform_mod {
         } else {
             $default_values['closeenable'] = 1;
         }
-        if (!isset($default_values['page_after_submitformat'])) {
-            $default_values['page_after_submitformat'] = FORMAT_HTML;
-        }
-        if (!isset($default_values['page_after_submit'])) {
-            $default_values['page_after_submit'] = '';
+
+        $editoroptions = feedback_get_editor_options();
+
+        if ($this->current->instance) {
+            // editing an existing feedback - let us prepare the added editor elements (intro done automatically)
+            $draftitemid = file_get_submitted_draft_itemid('page_after_submit');
+            $default_values['page_after_submit_editor']['text'] =
+                                    file_prepare_draft_area($draftitemid, $this->context->id,
+                                    'mod_feedback', 'page_after_submit', false,
+                                    $editoroptions,
+                                    $default_values['page_after_submit']);
+
+            $default_values['page_after_submit_editor']['format'] = $default_values['page_after_submitformat'];
+            $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
+        } else {
+            // adding a new feedback instance
+            $draftitemid = file_get_submitted_draft_itemid('page_after_submit_editor');
+
+            // no context yet, itemid not used
+            file_prepare_draft_area($draftitemid, null, 'mod_feedback', 'page_after_submit', false);
+            $default_values['page_after_submit_editor']['text'] = '';
+            $default_values['page_after_submit_editor']['format'] = editors_get_preferred_format();
+            $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
         }
-        $default_values['page_after_submit'] = array('text'=>$default_values['page_after_submit'],
-                                                    'format'=>$default_values['page_after_submitformat']);
+
     }
 
     public function get_data() {
         $data = parent::get_data();
         if ($data) {
-            $data->page_after_submitformat = $data->page_after_submit['format'];
-            $data->page_after_submit = $data->page_after_submit['text'];
+            $data->page_after_submitformat = $data->page_after_submit_editor['format'];
+            $data->page_after_submit = $data->page_after_submit_editor['text'];
 
             // Turn off completion settings if the checkboxes aren't ticked
             $autocompletion = !empty($data->completion) AND
index 34cfd7f..4997a61 100644 (file)
@@ -203,9 +203,18 @@ echo format_module_intro('feedback', $feedback, $cm->id);
 echo $OUTPUT->box_end();
 
 if (has_capability('mod/feedback:edititems', $context)) {
+    require_once($CFG->libdir . '/filelib.php');
+
+    $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
+                                                            'pluginfile.php',
+                                                            $context->id,
+                                                            'mod_feedback',
+                                                            'page_after_submit',
+                                                            0);
+
     echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
     echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
-    echo format_text($feedback->page_after_submit,
+    echo format_text($page_after_submit_output,
                      $feedback->page_after_submitformat,
                      array('overflowdiv'=>true));