Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-31768 - it is not possible to add a picture to the thanks page in…

… feedback
  • Loading branch information...
commit abd2899cad47050b5b111ee6cb409fc437c63d33 1 parent 0111871
@grabs grabs authored danpoltawski committed
View
1  mod/feedback/backup/moodle2/backup_feedback_stepslib.php
@@ -130,6 +130,7 @@ protected function define_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');
View
1  mod/feedback/backup/moodle2/restore_feedback_stepslib.php
@@ -120,6 +120,7 @@ protected function process_feedback_tracking($data) {
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');
}
}
View
12 mod/feedback/complete.php
@@ -375,8 +375,18 @@
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();
View
11 mod/feedback/complete_guest.php
@@ -329,8 +329,17 @@
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();
View
83 mod/feedback/lib.php
@@ -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;
}
@@ -692,6 +729,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.
*
* @global object
View
43 mod/feedback/mod_form.php
@@ -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 @@ public function definition() {
$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 @@ public function data_preprocessing(&$default_values) {
} 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
View
11 mod/feedback/view.php
@@ -203,9 +203,18 @@
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));
Please sign in to comment.
Something went wrong with that request. Please try again.