From 15d12b54f06ea0a743ddbc4867c614606334e646 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:07:17 +0000 Subject: [PATCH] Instructions for reviewers work --- mod/workshop/lib.php | 33 +++++++++++++++++++++++++++++++++ mod/workshop/mod_form.php | 18 +++++++++++++++--- mod/workshop/view.php | 5 +++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index ae24537b93..1ea2bef1f3 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -103,6 +103,12 @@ function workshop_add_instance($data) { $data->instructauthorsformat = $data->instructauthorseditor['format']; } + if ($draftitemid = $data->instructreviewerseditor['itemid']) { + $data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', + 0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); + $data->instructreviewersformat = $data->instructreviewerseditor['format']; + } + // re-save the record with the replaced URLs in editor fields $DB->update_record('workshop', $data); @@ -137,6 +143,12 @@ function workshop_update_instance($data) { $data->instructauthorsformat = $data->instructauthorseditor['format']; } + if ($draftitemid = $data->instructreviewerseditor['itemid']) { + $data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', + 0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); + $data->instructreviewersformat = $data->instructreviewerseditor['format']; + } + // re-save the record with the replaced URLs in editor fields return $DB->update_record('workshop', $data); } @@ -365,6 +377,27 @@ function workshop_pluginfile($course, $cminfo, $context, $filearea, array $args, send_stored_file($file, $lifetime, 0); } + if ($filearea === 'workshop_instructreviewers') { + // submission instructions may contain sensitive data + if (!has_any_capability(array('moodle/course:manageactivities', 'mod/workshop:peerassess'), $context)) { + send_file_not_found(); + } + + array_shift($args); // we do not use itemids here + $relativepath = '/' . implode('/', $args); + $fullpath = $context->id . $filearea . '0' . $relativepath; // beware, slashes are not used here! + + $fs = get_file_storage(); + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + send_file_not_found(); + } + + $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; + + // finally send the file + send_stored_file($file, $lifetime, 0); + } + // the following file areas are for the files embedded into the assessment forms if (in_array($filearea, array( 'workshopform_comments_description', diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index dc11faf6db..75f187e374 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -132,9 +132,9 @@ class mod_workshop_mod_form extends moodleform_mod { // Assessment settings -------------------------------------------------------- $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop')); -// $label = get_string('instructreviewers', 'workshop'); -// $mform->addElement('editor', 'instructreviewerseditor', $label, null, -// workshop::instruction_editors_options($this->context)); + $label = get_string('instructreviewers', 'workshop'); + $mform->addElement('editor', 'instructreviewerseditor', $label, null, + workshop::instruction_editors_options($this->context)); $label = get_string('nexassessments', 'workshop'); $options = workshop_get_numbers_of_assessments(); @@ -229,11 +229,23 @@ class mod_workshop_mod_form extends moodleform_mod { $data['instructauthors']); $data['instructauthorseditor']['format'] = $data['instructauthorsformat']; $data['instructauthorseditor']['itemid'] = $draftitemid; + + $draftitemid = file_get_submitted_draft_itemid('instructreviewers'); + $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, + 'workshop_instructreviewers', false, + workshop::instruction_editors_options($this->context), + $data['instructreviewers']); + $data['instructreviewerseditor']['format'] = $data['instructreviewersformat']; + $data['instructreviewerseditor']['itemid'] = $draftitemid; } else { // adding a new workshop instance $draftitemid = file_get_submitted_draft_itemid('instructauthors'); file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet $data['instructauthorseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid); + + $draftitemid = file_get_submitted_draft_itemid('instructreviewers'); + file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet + $data['instructreviewerseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid); } } } diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 803f3df28f..cf3e356130 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -117,6 +117,11 @@ case workshop::PHASE_SUBMISSION: } break; case workshop::PHASE_ASSESSMENT: + if (trim(strip_tags($workshop->instructreviewers))) { + $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, + 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); + echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions')); + } if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) { echo $OUTPUT->heading(get_string('assignedassessmentsnone', 'workshop'), 3); } else { -- 2.39.5