Skip to content

Commit

Permalink
MDL-35421 Make the new conclusion field editable via mod_form
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 1, 2012
1 parent d898206 commit 5a49f82
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mod/workshop/lang/en/workshop.php
Expand Up @@ -35,6 +35,7 @@
$string['allocationconfigured'] = 'Allocation configured';
$string['allsubmissions'] = 'All submissions ({$a})';
$string['alreadygraded'] = 'Already graded';
$string['areaconclusion'] = 'Conclusion text';
$string['areainstructauthors'] = 'Instructions for submission';
$string['areainstructreviewers'] = 'Instructions for assessment';
$string['areasubmissionattachment'] = 'Submission attachments';
Expand Down Expand Up @@ -77,6 +78,8 @@
$string['clearassessments_help'] = 'The calculated grades for submission and grades for assessment will be reset. The information how the assessment forms are filled is still kept, but all the reviewers must open the assessment form again and re-save it to get the given grades calculated again.';
$string['clearassessmentsconfirm'] = 'Are you sure you want to clear all assessment grades? You will not be able to get the information back on your own, reviewers will have to re-assess the allocated submissions.';
$string['clearaggregatedgradesconfirm'] = 'Are you sure you want to clear the calculated grades for submissions and grades for assessment?';
$string['conclusion'] = 'Conclusion';
$string['conclusion_help'] = 'Conclusion is a text displayed to participants at the end of the activity. You may want to provide an overall feedback, summary or suggestions on what should be done next (e.g. writing a blog post reflecting the new experience).';
$string['configexamplesmode'] = 'Default mode of examples assessment in workshops';
$string['configgrade'] = 'Default maximum grade for submission in workshops';
$string['configgradedecimals'] = 'Default number of digits that should be shown after the decimal point when displaying grades.';
Expand Down Expand Up @@ -157,6 +160,7 @@
$string['latesubmissions_help'] = 'If enabled, an author may submit their work after the submissions deadline or during the assessment phase. Late submissions cannot be edited though.';
$string['latesubmissionsallowed'] = 'Late submissions are allowed';
$string['maxbytes'] = 'Maximum file size';
$string['miscellaneoussettings'] = 'Miscellaneous settings';
$string['modulename'] = 'Workshop';
$string['modulename_help'] = 'The workshop activity module enables the collection, review and peer assessment of students\' work.
Expand Down
38 changes: 32 additions & 6 deletions mod/workshop/lib.php
Expand Up @@ -104,6 +104,12 @@ function workshop_add_instance(stdclass $workshop) {
$workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
}

if ($draftitemid = $workshop->conclusioneditor['itemid']) {
$workshop->conclusion = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'conclusion',
0, workshop::instruction_editors_options($context), $workshop->conclusioneditor['text']);
$workshop->conclusionformat = $workshop->conclusioneditor['format'];
}

// re-save the record with the replaced URLs in editor fields
$DB->update_record('workshop', $workshop);

Expand Down Expand Up @@ -137,8 +143,7 @@ function workshop_update_instance(stdclass $workshop) {
$workshop->latesubmissions = (int)!empty($workshop->latesubmissions);
$workshop->phaseswitchassessment = (int)!empty($workshop->phaseswitchassessment);

// todo - if the grading strategy is being changed, we must replace all aggregated peer grades with nulls
// todo - if maximum grades are being changed, we should probably recalculate or invalidate them
// todo - if the grading strategy is being changed, we may want to replace all aggregated peer grades with nulls

$DB->update_record('workshop', $workshop);
$context = context_module::instance($workshop->coursemodule);
Expand All @@ -156,6 +161,12 @@ function workshop_update_instance(stdclass $workshop) {
$workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
}

if ($draftitemid = $workshop->conclusioneditor['itemid']) {
$workshop->conclusion = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'conclusion',
0, workshop::instruction_editors_options($context), $workshop->conclusioneditor['text']);
$workshop->conclusionformat = $workshop->conclusioneditor['format'];
}

// re-save the record with the replaced URLs in editor fields
$DB->update_record('workshop', $workshop);

Expand Down Expand Up @@ -1172,6 +1183,7 @@ function workshop_get_file_areas($course, $cm, $context) {
$areas['instructreviewers'] = get_string('areainstructreviewers', 'workshop');
$areas['submission_content'] = get_string('areasubmissioncontent', 'workshop');
$areas['submission_attachment'] = get_string('areasubmissionattachment', 'workshop');
$areas['conclusion'] = get_string('areaconclusion', 'workshop');

return $areas;
}
Expand All @@ -1182,7 +1194,7 @@ function workshop_get_file_areas($course, $cm, $context) {
* Apart from module intro (handled by pluginfile.php automatically), workshop files may be
* media inserted into submission content (like images) and submission attachments. For these two,
* the fileareas submission_content and submission_attachment are used.
* Besides that, areas instructauthors and instructreviewers contain the media
* Besides that, areas instructauthors, instructreviewers and conclusion contain the media
* embedded using the mod_form.php.
*
* @package mod_workshop
Expand Down Expand Up @@ -1220,9 +1232,23 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo

// finally send the file
send_stored_file($file, $lifetime, 0, $forcedownload, $options);
}

if ($filearea === 'instructreviewers') {
} else if ($filearea === 'instructreviewers') {
array_shift($args); // itemid is ignored here
$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath";

$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, $forcedownload, $options);

} else if ($filearea === 'conclusion') {
array_shift($args); // itemid is ignored here
$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath";
Expand Down Expand Up @@ -1397,7 +1423,7 @@ function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filea
return new file_info_stored($browser, $context, $storedfile, $urlbase, $topvisiblename, true, true, false, false);
}

if ($filearea == 'instructauthors' or $filearea == 'instructreviewers') {
if ($filearea == 'instructauthors' or $filearea == 'instructreviewers' or $filearea == 'conclusion') {
// always only itemid 0

$filepath = is_null($filepath) ? '/' : $filepath;
Expand Down
20 changes: 20 additions & 0 deletions mod/workshop/mod_form.php
Expand Up @@ -172,6 +172,14 @@ public function definition() {
$mform->disabledIf('examplesmode', 'useexamples');
$mform->setAdvanced('examplesmode');

// Miscellaneous settings
$mform->addElement('header', 'miscellaneoussettings', get_string('miscellaneoussettings', 'workshop'));

$label = get_string('conclusion', 'workshop');
$mform->addElement('editor', 'conclusioneditor', $label, null,
workshop::instruction_editors_options($this->context));
$mform->addHelpButton('conclusioneditor', 'conclusion', 'workshop');

// Access control -------------------------------------------------------------
$mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));

Expand Down Expand Up @@ -237,6 +245,14 @@ public function data_preprocessing(&$data) {
$data['instructreviewers']);
$data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
$data['instructreviewerseditor']['itemid'] = $draftitemid;

$draftitemid = file_get_submitted_draft_itemid('conclusion');
$data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'conclusion', 0,
workshop::instruction_editors_options($this->context),
$data['conclusion']);
$data['conclusioneditor']['format'] = $data['conclusionformat'];
$data['conclusioneditor']['itemid'] = $draftitemid;
} else {
// adding a new workshop instance
$draftitemid = file_get_submitted_draft_itemid('instructauthors');
Expand All @@ -246,6 +262,10 @@ public function data_preprocessing(&$data) {
$draftitemid = file_get_submitted_draft_itemid('instructreviewers');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
$data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);

$draftitemid = file_get_submitted_draft_itemid('conclusion');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0); // no context yet, itemid not used
$data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
}
}

Expand Down

0 comments on commit 5a49f82

Please sign in to comment.