From 6516b9e9e477b6b75c83b260ae85a52d91695320 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:02:27 +0000 Subject: [PATCH] Added instructions for submitting File API seems to be broken right now so I can't test properly. The new mod/page code was re-used here. --- mod/workshop/db/install.xml | 10 ++- mod/workshop/lang/en_utf8/workshop.php | 4 +- mod/workshop/lib.php | 103 +++++++++++++++++++++---- mod/workshop/locallib.php | 14 ++++ mod/workshop/mod_form.php | 63 ++++++++++++--- mod/workshop/version.php | 2 +- mod/workshop/view.php | 5 ++ 7 files changed, 170 insertions(+), 31 deletions(-) diff --git a/mod/workshop/db/install.xml b/mod/workshop/db/install.xml index 18f4f0f4dc..1efdff25ee 100644 --- a/mod/workshop/db/install.xml +++ b/mod/workshop/db/install.xml @@ -1,5 +1,5 @@ - @@ -10,8 +10,12 @@ - - + + + + + + diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 15f2f12f2d..42a93803b2 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -142,8 +142,10 @@ $string['switchphase50info'] = 'You are going to close the Workshop. (TODO: expl $string['taskassesspeers'] = 'Assess peers'; $string['taskassesspeersdetails'] = 'total: $a->total
pending: $a->todo'; $string['taskassessself'] = 'Assess yourself'; +$string['instructauthors'] = 'Instructions for submitting'; $string['taskinstructauthors'] = 'Provide instructions for submitting'; -$string['taskinstructreviewers'] = 'Provide instructions for grading'; +$string['taskinstructreviewers'] = 'Provide instructions for assessing'; +$string['instructreviewers'] = 'Instructions for assessing'; $string['taskintro'] = 'Set the workshop introduction'; $string['tasksubmit'] = 'Submit your work'; $string['teacherweight'] = 'Weight of the teacher\'s assessments'; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index c212f37102..94edbd1e32 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -69,7 +69,6 @@ function workshop_supports($feature) { } } - /** * Saves a new instance of the workshop into the database * @@ -89,7 +88,25 @@ function workshop_add_instance($data) { $data->timecreated = time(); $data->timemodified = $data->timecreated; - return $DB->insert_record('workshop', $data); + // insert the new record so we get the id + $data->id = $DB->insert_record('workshop', $data); + + // we need to use context now, so we need to make sure all needed info is already in db + $cmid = $data->coursemodule; + $DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid)); + $context = get_context_instance(CONTEXT_MODULE, $cmid); + + // process the custom wysiwyg editors + if ($draftitemid = $data->instructauthorseditor['itemid']) { + $data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', + false, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); + $data->instructauthorsformat = $data->instructauthorseditor['format']; + } + + // re-save the record with the replaced URLs in editor fields + $DB->update_record('workshop', $data); + + return $data->id; } /** @@ -97,16 +114,28 @@ function workshop_add_instance($data) { * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * - * @param stdClass $workshop An object from the form in mod_form.php - * @return boolean Success/Fail + * @param stdClass $data An object from the form in mod_form.php + * @return bool success */ -function workshop_update_instance($workshop) { - global $DB; +function workshop_update_instance($data) { + global $CFG, $DB; + require_once(dirname(__FILE__) . '/locallib.php'); + + $data->timemodified = time(); + $data->id = $data->instance; - $workshop->timemodified = time(); - $workshop->id = $workshop->instance; + $DB->update_record('workshop', $data); + $context = get_context_instance(CONTEXT_MODULE, $data->coursemodule); - return $DB->update_record('workshop', $workshop); + // process the custom wysiwyg editors + if ($draftitemid = $data->instructauthorseditor['itemid']) { + $data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', + false, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); + $data->instructauthorsformat = $data->instructauthorseditor['format']; + } + + // re-save the record with the replaced URLs in editor fields + return $DB->update_record('workshop', $data); } /** @@ -275,6 +304,7 @@ function workshop_get_extra_capabilities() { function workshop_get_file_areas($course, $cm, $context) { $areas = array(); if (has_capability('moodle/course:managefiles', $context)) { + $areas['workshop_instructauthors'] = get_string('areainstructauthors', 'workshop'); $areas['workshop_dimension_description'] = get_string('areadimensiondescription', 'workshop'); $areas['workshop_submission_content'] = get_string('areasubmissioncontent', 'workshop'); $areas['workshop_submission_attachment'] = get_string('areasubmissionattachment', 'workshop'); @@ -290,6 +320,8 @@ function workshop_get_file_areas($course, $cm, $context) { * the fileareas workshop_submission_content and workshop_submission_attachment are used. * The access rights to the files are checked here. The user must be either a peer-reviewer * of the submission or have capability ... (todo) to access the submission files. + * Besides that, areas workshop_instructauthors and workshop_instructreviewers contain the media + * embedded using the mod_form.php. * * @param stdClass $course * @param stdClass $cminfo @@ -297,18 +329,39 @@ function workshop_get_file_areas($course, $cm, $context) { * @param string $filearea * @param array $args * @param bool $forcedownload - * @return bool false if file not found, does not return if found - justsend the file + * @return void this should never return to the caller */ -function workshop_pluginfile($course, $cminfo, $context, $filearea, $args, $forcedownload) { +function workshop_pluginfile($course, $cminfo, $context, $filearea, array $args, $forcedownload) { global $DB; if (!$cminfo->uservisible) { - return false; + send_file_not_found(); } if (!$cm = get_coursemodule_from_instance('workshop', $cminfo->instance, $course->id)) { - return false; + send_file_not_found(); + } + require_login($course, true, $cm); + + if ($filearea === 'workshop_instructauthors') { + // submission instructions may contain sensitive data + if (!has_any_capability(array('moodle/course:manageactivities', 'mod/workshop:submit'), $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); } - require_course_login($course, true, $cm); if ($filearea === 'workshop_dimension_description') { $itemid = (int)array_shift($args); @@ -417,6 +470,24 @@ function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filea } if ($filearea === 'workshop_dimension_description') { + // always only itemid 0 - TODO not true, review + + $filepath = is_null($filepath) ? '/' : $filepath; + $filename = is_null($filename) ? '.' : $filename; + + $urlbase = $CFG->wwwroot.'/pluginfile.php'; + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if ($filepath === '/' and $filename === '.') { + $storedfile = new virtual_root_file($context->id, $filearea, 0); + } else { + // not found + return null; + } + } + return new file_info_stored($browser, $context, $storedfile, $urlbase, $areas[$filearea], false, true, true, false); + } + + if ($filearea === 'workshop_instructauthors') { // always only itemid 0 $filepath = is_null($filepath) ? '/' : $filepath; @@ -435,6 +506,10 @@ function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filea } } +//////////////////////////////////////////////////////////////////////////////// +// Navigation API // +//////////////////////////////////////////////////////////////////////////////// + /** * Extends the global navigation tree by adding workshop nodes if there is a relevant content * diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 85feaba270..8581a98cd6 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -940,4 +940,18 @@ class workshop { $DB->update_record('workshop_assessments', $data); return $grade; } + +// Static methods + + /** + * Returns an array of options for the editors that are used for submitting and assessing instructions + * + * @param stdClass $context + * @return array + */ + public static function instruction_editors_options(stdClass $context) { + return array('subdirs' => 1, 'maxbytes' => 0, 'maxfiles' => EDITOR_UNLIMITED_FILES, + 'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => 0); + } + } diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index 44a4bc4095..dc11faf6db 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -29,20 +29,27 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/course/moodleform_mod.php'); +require_once($CFG->dirroot . '/course/moodleform_mod.php'); +require_once(dirname(__FILE__) . '/locallib.php'); +require_once($CFG->libdir . '/filelib.php'); class mod_workshop_mod_form extends moodleform_mod { + /** + * Defines the workshop instance configuration form + * + * @return void + */ function definition() { global $CFG, $COURSE; $workshopconfig = get_config('workshop'); $mform = $this->_form; -/// General -------------------------------------------------------------------- + // General -------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); - /// Workshop name + // Workshop name $label = get_string('workshopname', 'workshop'); $mform->addElement('text', 'name', $label, array('size'=>'64')); if (!empty($CFG->formatstringstriptags)) { @@ -54,10 +61,10 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->setHelpButton('name', array('workshopname', $label, 'workshop')); - /// Introduction + // Introduction $this->add_intro_editor(false, get_string('introduction', 'workshop')); -/// Workshop features ---------------------------------------------------------- + // Workshop features ---------------------------------------------------------- $mform->addElement('header', 'workshopfeatures', get_string('workshopfeatures', 'workshop')); $label = get_string('useexamples', 'workshop'); @@ -75,7 +82,7 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->addElement('advcheckbox', 'useselfassessment', $label, $text); $mform->setHelpButton('useselfassessment', array('useselfassessment', $label, 'workshop')); -/// Grading settings ----------------------------------------------------------- + // Grading settings ----------------------------------------------------------- $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop')); $grades = workshop_get_maxgrades(); @@ -95,9 +102,13 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setDefault('strategy', $workshopconfig->strategy); $mform->setHelpButton('strategy', array('strategy', $label, 'workshop')); -/// Submission settings -------------------------------------------------------- + // Submission settings -------------------------------------------------------- $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop')); + $label = get_string('instructauthors', 'workshop'); + $mform->addElement('editor', 'instructauthorseditor', $label, null, + workshop::instruction_editors_options($this->context)); + $options = array(); for ($i=7; $i>=0; $i--) { $options[$i] = $i; @@ -118,9 +129,13 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setDefault('maxbytes', $workshopconfig->maxbytes); $mform->setHelpButton('maxbytes', array('maxbytes', $label, 'workshop')); -/// Assessment settings + // 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('nexassessments', 'workshop'); $options = workshop_get_numbers_of_assessments(); $options[0] = get_string('assessallexamples', 'workshop'); @@ -158,7 +173,7 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setDefault('assessmentcomps', $workshopconfig->assessmentcomps); $mform->setHelpButton('assessmentcomps', array('assessmentcomps', $label, 'workshop')); -/// Access control + // Access control ------------------------------------------------------------- $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop')); $label = get_string('submissionstart', 'workshop'); @@ -186,15 +201,39 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setHelpButton('releasegrades', array('releasegrades', $label, 'workshop')); $mform->setAdvanced('releasegrades'); -/// Common module settinga, Restrict availability, Activity completion etc. ---- + // Common module settinga, Restrict availability, Activity completion etc. ---- $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true, 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false); $this->standard_coursemodule_elements(); -/// Save and close, Save, Cancel ----------------------------------------------- - // add standard buttons, common to all modules + // Standard buttons, common to all modules ------------------------------------ $this->add_action_buttons(); + } + /** + * Prepares the form before data are set + * + * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core + * + * @param array $data to be set + * @return void + */ + function data_preprocessing(&$data) { + if ($this->current->instance) { + // editing an existing workshop - let us prepare the added editor elements (intro done automatically) + $draftitemid = file_get_submitted_draft_itemid('instructauthors'); + $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, + 'workshop_instructauthors', false, + workshop::instruction_editors_options($this->context), + $data['instructauthors']); + $data['instructauthorseditor']['format'] = $data['instructauthorsformat']; + $data['instructauthorseditor']['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); + } } } diff --git a/mod/workshop/version.php b/mod/workshop/version.php index 386ad8fb25..5e4dee5375 100644 --- a/mod/workshop/version.php +++ b/mod/workshop/version.php @@ -28,6 +28,6 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2009090400; +$module->version = 2009090700; $module->requires = 2009090400; // Requires this Moodle version $module->cron = 60; diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 0483d8c1a8..d04fc15336 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -85,6 +85,11 @@ case workshop::PHASE_SETUP: } break; case workshop::PHASE_SUBMISSION: + if (trim(strip_tags($workshop->instructauthors))) { + $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, + 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); + echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions')); + } if (has_capability('mod/workshop:submit', $PAGE->context)) { if ($submission = $workshop->get_submission_by_author($USER->id)) { echo $OUTPUT->box_start('generalbox mysubmission'); -- 2.39.5