Permalink
Browse files

MDL-37602 Put the overall feedback fields to the bottom of the assess…

…ment form

The assessment form can be displayed as editable or read-only (frozen).
Neither the editor element nor the filemanager element support
displaying frozen content themselves so we need to pre-format and inject
static texts.

The list of attachments should be ideally generated by the renderer and
probably improved a bit - just quick and dirty solution must be enough
for now though (2.5 coding freeze is just behind the corner...).

AMOS BEGIN
 CPY [submissionattachment,mod_workshop],[feedbackauthorattachment,mod_workshop]
AMOS END
  • Loading branch information...
1 parent 3ac58f2 commit c6a793d5a256d979fd4b707d19d7a8e919d8a8b4 @mudrd8mz mudrd8mz committed Mar 25, 2013
@@ -37,6 +37,7 @@
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
+require_once($CFG->libdir.'/filelib.php');
$asid = required_param('asid', PARAM_INT); // assessment id
$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
@@ -135,9 +136,69 @@
$pending = array();
}
// load the assessment form and process the submitted data eventually
- $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable,
- array('editableweight' => $cansetassessmentweight, 'pending' => !empty($pending)));
- $mform->set_data(array('weight' => $assessment->weight)); // other values are set by subplugins
+ $feedbackauthoreditoropts = array(
+ 'maxbytes' => $workshop->overallfeedbackmaxbytes,
+ 'maxfiles' => $workshop->overallfeedbackfiles,
+ 'changeformat' => 1,
+ 'context' => $workshop->context,
+ );
+ $feedbackauthorattachmentopts = array(
+ 'maxbytes' => $workshop->overallfeedbackmaxbytes,
+ 'maxfiles' => $workshop->overallfeedbackfiles,
+ 'return_types' => FILE_INTERNAL,
+ );
+ $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable, array(
+ 'editableweight' => $cansetassessmentweight,
+ 'pending' => !empty($pending),
+ 'feedbackauthoreditoropts' => $feedbackauthoreditoropts,
+ 'feedbackauthorattachmentopts' => $feedbackauthorattachmentopts,
+ ));
+
+ // Set data managed by the workshop core, subplugins set their own data themselves.
+ $currentdata = (object)array(
+ 'weight' => $assessment->weight,
+ 'feedbackauthor' => $assessment->feedbackauthor,
+ 'feedbackauthorformat' => $assessment->feedbackauthorformat,
+ );
+ if (!empty($workshop->overallfeedbackmode)) {
+ if ($assessmenteditable) {
+ $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $feedbackauthoreditoropts,
+ $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
+ if (!empty($workshop->overallfeedbackfiles)) {
+ $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
+ $feedbackauthorattachmentopts, $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id);
+ }
+
+ } else {
+ $currentdata->feedbackauthor = file_rewrite_pluginfile_urls($currentdata->feedbackauthor, 'pluginfile.php',
+ $workshop->context->id, 'mod_workshop', 'overallfeedback_content', $assessment->id);
+ $currentdata->feedbackauthor = format_text($currentdata->feedbackauthor, $currentdata->feedbackauthorformat,
+ array('overflowdiv' => true, 'context' => $workshop->context));
+ $currentdata->feedbackauthorattachment = '-';
+ if (!empty($assessment->feedbackauthorattachment)) {
+ $fs = get_file_storage();
+ $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $assessment->id);
+ $list = '';
+ foreach ($files as $file) {
+ if ($file->is_directory()) {
+ continue;
+ }
+ $filepath = $file->get_filepath();
+ $filename = $file->get_filename();
+ $fileurl = moodle_url::make_pluginfile_url($workshop->context->id, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id, $filepath, $filename, true);
+ $link = html_writer::link($fileurl, s($filename));
+ $list .= html_writer::tag('li', $link);
+ }
+ $list = html_writer::tag('ul', $list, array('class' => 'overallfeedback_attachments'));
+ $currentdata->feedbackauthorattachment = $list;
+ }
+ }
+
+ }
+ $mform->set_data($currentdata);
+
if ($mform->is_cancelled()) {
redirect($workshop->view_url());
} elseif ($assessmenteditable and ($data = $mform->get_data())) {
@@ -146,10 +207,34 @@
} else {
$workshop->log('update assessment', $workshop->assess_url($assessment->id), $assessment->submissionid);
}
+
+ // Let the grading strategy subplugin save its data.
$rawgrade = $strategy->save_assessment($assessment, $data);
+
+ // Store the data managed by the workshop core.
+ $coredata = (object)array('id' => $assessment->id);
+ if (isset($data->feedbackauthor_editor)) {
+ $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
+ $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $feedbackauthoreditoropts,
+ $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
+ unset($coredata->feedbackauthor_editor);
+ }
+ if (isset($data->feedbackauthorattachment_filemanager)) {
+ $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
+ $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
+ $feedbackauthorattachmentopts, $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id);
+ unset($coredata->feedbackauthorattachment_filemanager);
+ if (empty($coredata->feedbackauthorattachment)) {
+ $coredata->feedbackauthorattachment = 0;
+ }
+ }
if (isset($data->weight) and $cansetassessmentweight) {
- $DB->set_field('workshop_assessments', 'weight', $data->weight, array('id' => $assessment->id));
+ $coredata->weight = $data->weight;
}
+ $DB->update_record('workshop_assessments', $coredata);
+
+ // And finally redirect the user's browser.
if (!is_null($rawgrade) and isset($data->saveandclose)) {
redirect($workshop->view_url());
} else if (!is_null($rawgrade) and isset($data->saveandshownext)) {
@@ -68,6 +68,28 @@ public function definition() {
$mform->addElement('hidden', 'strategy', $this->workshop->strategy);
$mform->setType('strategy', PARAM_PLUGIN);
+ if (!empty($this->workshop->overallfeedbackmode)) {
+ $mform->addElement('header', 'overallfeedbacksection', get_string('overallfeedback', 'mod_workshop'));
+ if (!$mform->isFrozen()) {
+ $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_workshop'), null,
+ $this->options['feedbackauthoreditoropts']);
+ if ($this->workshop->overallfeedbackmode == 2) {
+ $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client');
+ }
+ if (!empty($this->workshop->overallfeedbackfiles)) {
+ $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager',
+ get_string('feedbackauthorattachment', 'mod_workshop'), null,
+ $this->options['feedbackauthorattachmentopts']);
+ }
+
+ } else {
+ $mform->addElement('static', 'feedbackauthor', get_string('feedbackauthor', 'mod_workshop'));
+ if (!empty($this->workshop->overallfeedbackfiles)) {
+ $mform->addElement('static', 'feedbackauthorattachment', get_string('feedbackauthorattachment', 'mod_workshop'));
+ }
+ }
+ }
+
if (!empty($this->options['editableweight']) and !$mform->isFrozen()) {
$mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'workshop'));
$mform->addElement('select', 'weight',
@@ -124,6 +124,7 @@
$string['examplesubmissions'] = 'Example submissions';
$string['examplesvoluntary'] = 'Assessment of example submission is voluntary';
$string['feedbackauthor'] = 'Feedback for the author';
+$string['feedbackauthorattachment'] = 'Attachment';
$string['feedbackby'] = 'Feedback by {$a}';
$string['feedbackreviewer'] = 'Feedback for the reviewer';
$string['formataggregatedgrade'] = '{$a->grade}';
@@ -184,6 +185,7 @@
$string['noworkshops'] = 'There are no workshops in this course';
$string['noyoursubmission'] = 'You have not submitted your work yet';
$string['nullgrade'] = '-';
+$string['overallfeedback'] = 'Overall feedback';
$string['overallfeedbackfiles'] = 'Maximum number of overall feedback attachments';
$string['overallfeedbackmaxbytes'] = 'Maximum file size';
$string['overallfeedbackmode'] = 'Overall feedback mode';
View
@@ -155,6 +155,15 @@ class workshop {
/** @var int format of the conclusion text */
public $conclusionformat;
+ /** @var int the mode of the overall feedback */
+ public $overallfeedbackmode;
+
+ /** @var int maximum number of overall feedback attachments */
+ public $overallfeedbackfiles;
+
+ /** @var int maximum size of one file attached to the overall feedback */
+ public $overallfeedbackmaxbytes;
+
/**
* @var workshop_strategy grading strategy instance
* Do not use directly, get the instance using {@link workshop::grading_strategy_instance()}
@@ -1236,7 +1245,7 @@ public function add_allocation(stdclass $submission, $reviewerid, $weight=1, $bu
$assessment->reviewerid = $reviewerid;
$assessment->timecreated = $now; // do not set timemodified here
$assessment->weight = $weight;
- $assessment->generalcommentformat = editors_get_preferred_format();
+ $assessment->feedbackauthorformat = editors_get_preferred_format();
$assessment->feedbackreviewerformat = editors_get_preferred_format();
return $DB->insert_record('workshop_assessments', $assessment, true, $bulk);

0 comments on commit c6a793d

Please sign in to comment.