Permalink
Browse files

MDL-37602 Clean up and improve the overall feedback rendering

In order to use the overall feedback in assessments of example
submissions and in the assessment form preview, significant improvements
in the rendering machinery were done.

Workshop class provides two new methods overall_feedback_content_options()
and overall_feedback_attachment_options() as they are needed at various
scripts and libraries.

Overall feedback is displayed as a part of the workshop_assessment_form
only if the form is in editable mode (not frozen). If the form is
displayed in read-only (frozen) mode, the caller is expected to render
the overall feedback and list of attachments (the editor and filemanager
elements do not support frozen mode). To do so, the renderable
workshop_assessment now loads overall feedback data and provides two new
methods get_overall_feedback_content() and
get_overall_feedback_attachments() to be used by the renderer.

Renderable workshop_submission, workshop_assessment and related classes
now accept the workshop instance as the first parameter in their
constructors. This way, these renderable classes have access to the
workshop API.

In the future, the rendering of submission files should be improved in
the same way as is done in this patch (i.e. moving the logic and data
preparation out of the renderer into the renderable classes).
  • Loading branch information...
mudrd8mz committed Mar 26, 2013
1 parent 88e79d8 commit 77d746a2f51c9a5cd2b5e593698654e7cd57904b
@@ -37,7 +37,6 @@
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);
@@ -136,66 +135,23 @@
$pending = array();
}
// load the assessment form and process the submitted data eventually
- $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,
- ));
+ $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable,
+ array('editableweight' => $cansetassessmentweight, 'pending' => !empty($pending)));
// 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;
- }
+ if ($assessmenteditable and $workshop->overallfeedbackmode) {
+ $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
+ $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
+ if ($workshop->overallfeedbackfiles) {
+ $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
+ $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id);
}
-
}
$mform->set_data($currentdata);
@@ -215,14 +171,14 @@
$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,
+ $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
$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',
+ $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
$assessment->id);
unset($coredata->feedbackauthorattachment_filemanager);
if (empty($coredata->feedbackauthorattachment)) {
@@ -67,6 +67,23 @@
// load the assessment form and process the submitted data eventually
$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
+
+// Set data managed by the workshop core, subplugins set their own data themselves.
+$currentdata = (object)array(
+ 'feedbackauthor' => $assessment->feedbackauthor,
+ 'feedbackauthorformat' => $assessment->feedbackauthorformat,
+);
+if ($assessmenteditable and $workshop->overallfeedbackmode) {
+ $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
+ $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
+ if ($workshop->overallfeedbackfiles) {
+ $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
+ $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id);
+ }
+}
+$mform->set_data($currentdata);
+
if ($mform->is_cancelled()) {
redirect($workshop->view_url());
} elseif ($assessmenteditable and ($data = $mform->get_data())) {
@@ -83,11 +100,34 @@
$workshop->log('update example assessment', $workshop->exassess_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', $workshop->overall_feedback_content_options(),
+ $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',
+ $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
+ $assessment->id);
+ unset($coredata->feedbackauthorattachment_filemanager);
+ if (empty($coredata->feedbackauthorattachment)) {
+ $coredata->feedbackauthorattachment = 0;
+ }
+ }
if ($canmanage) {
- // remember the last one who edited the reference assessment
- $DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
+ // Remember the last one who edited the reference assessment.
+ $coredata->reviewerid = $USER->id;
}
+ $DB->update_record('workshop_assessments', $coredata);
+
if (!is_null($rawgrade) and isset($data->saveandclose)) {
if ($canmanage) {
redirect($workshop->view_url());
@@ -68,29 +68,21 @@ public function definition() {
$mform->addElement('hidden', 'strategy', $this->workshop->strategy);
$mform->setType('strategy', PARAM_PLUGIN);
- if (!empty($this->workshop->overallfeedbackmode)) {
+ if ($this->workshop->overallfeedbackmode and $this->is_editable()) {
$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'));
- }
+ $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_workshop'), null,
+ $this->workshop->overall_feedback_content_options());
+ if ($this->workshop->overallfeedbackmode == 2) {
+ $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client');
+ }
+ if ($this->workshop->overallfeedbackfiles) {
+ $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager',
+ get_string('feedbackauthorattachment', 'mod_workshop'), null,
+ $this->workshop->overall_feedback_attachment_options());
}
}
- if (!empty($this->options['editableweight']) and !$mform->isFrozen()) {
+ if (!empty($this->options['editableweight']) and $this->is_editable()) {
$mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'workshop'));
$mform->addElement('select', 'weight',
get_string('assessmentweight', 'workshop'), workshop::available_assessment_weights_list());
@@ -122,4 +114,12 @@ protected function definition_inner(&$mform) {
// By default, do nothing.
}
+ /**
+ * Is the form frozen (read-only)?
+ *
+ * @return boolean
+ */
+ public function is_editable() {
+ return !$this->_form->isFrozen();
+ }
}
Oops, something went wrong.

0 comments on commit 77d746a

Please sign in to comment.