Permalink
Browse files

MDL-36289: Assignment - Prevent feedback files being copied to the ne…

…xt user when using "Save and next".
  • Loading branch information...
Damyon Wiese
Damyon Wiese committed Oct 31, 2012
1 parent eecddb8 commit fc7b7d52de19c1aa052e35b5d696d5c9af036015
Showing with 41 additions and 12 deletions.
  1. +17 −0 mod/assign/assignmentplugin.php
  2. +15 −5 mod/assign/feedback/file/locallib.php
  3. +9 −7 mod/assign/locallib.php
@@ -220,8 +220,25 @@ public function is_enabled() {
return $this->get_config('enabled');
}
+
+ /**
+ * Get any additional fields for the submission/grading form for this assignment.
+ *
+ * @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data,
+ * for feedback plugins it is the grade data
+ * @param MoodleQuickForm $mform - This is the form
+ * @param stdClass $data - This is the form data that can be modified for example by a filemanager element
+ * @param int $userid - This is the userid for the current submission.
+ * This is passed separately as there may not yet be a submission or grade.
+ * @return boolean - true if we added anything to the form
+ */
+ public function get_form_elements_for_user($submissionorgrade, MoodleQuickForm $mform, stdClass $data, $userid) {
+ return $this->get_form_elements($submissionorgrade, $mform, $data);
+ }
+
/**
* Get any additional fields for the submission/grading form for this assignment.
+ * This function is retained for backwards compatibility - new plugins should override {@link get_form_elements_for_user()}.
*
* @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data, for feedback plugins it is the grade data
* @param MoodleQuickForm $mform - This is the form
@@ -125,17 +125,24 @@ private function copy_area_files(file_storage $fs,
* @param stdClass $grade
* @param MoodleQuickForm $mform
* @param stdClass $data
+ * @param int $userid The userid we are currently grading
* @return bool true if elements were added to the form
*/
- public function get_form_elements($grade, MoodleQuickForm $mform, stdClass $data) {
+ public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
$fileoptions = $this->get_file_options();
$gradeid = $grade ? $grade->id : 0;
+ $elementname = 'files_' . $userid;
+ $data = file_prepare_standard_filemanager($data,
+ $elementname,
+ $fileoptions,
+ $this->assignment->get_context(),
+ 'assignfeedback_file',
+ ASSIGNFEEDBACK_FILE_FILEAREA,
+ $gradeid);
- $data = file_prepare_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $gradeid);
-
- $mform->addElement('filemanager', 'files_filemanager', '', null, $fileoptions);
+ $mform->addElement('filemanager', $elementname . '_filemanager', '', null, $fileoptions);
return true;
}
@@ -187,8 +194,11 @@ public function update_file_count($grade) {
public function save(stdClass $grade, stdClass $data) {
$fileoptions = $this->get_file_options();
+ $userid = $grade->userid;
+ $elementname = 'files_' . $userid;
+
$data = file_postupdate_standard_filemanager($data,
- 'files',
+ $elementname,
$fileoptions,
$this->assignment->get_context(),
'assignfeedback_file',
View
@@ -808,13 +808,14 @@ public function update_instance($formdata) {
* @param mixed $grade stdClass|null
* @param MoodleQuickForm $mform
* @param stdClass $data
+ * @param int $userid - The userid we are grading
* @return void
*/
- private function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data) {
+ private function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
foreach ($this->feedbackplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
$mform->addElement('header', 'header_' . $plugin->get_type(), $plugin->get_name());
- if (!$plugin->get_form_elements($grade, $mform, $data)) {
+ if (!$plugin->get_form_elements_for_user($grade, $mform, $data, $userid)) {
$mform->removeElement('header_' . $plugin->get_type());
}
}
@@ -3919,8 +3920,8 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
$mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist))));
- // plugins
- $this->add_plugin_grade_elements($grade, $mform, $data);
+ // Let feedback plugins add elements to the grading form.
+ $this->add_plugin_grade_elements($grade, $mform, $data, $userid);
// hidden params
$mform->addElement('hidden', 'id', $this->get_course_module()->id);
@@ -3969,13 +3970,14 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
* @param mixed $submission stdClass|null
* @param MoodleQuickForm $mform
* @param stdClass $data
+ * @param int $userid The current userid (same as $USER->id)
* @return void
*/
- private function add_plugin_submission_elements($submission, MoodleQuickForm $mform, stdClass $data) {
+ private function add_plugin_submission_elements($submission, MoodleQuickForm $mform, stdClass $data, $userid) {
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
$mform->addElement('header', 'header_' . $plugin->get_type(), $plugin->get_name());
- if (!$plugin->get_form_elements($submission, $mform, $data)) {
+ if (!$plugin->get_form_elements_for_user($submission, $mform, $data, $userid)) {
$mform->removeElement('header_' . $plugin->get_type());
}
}
@@ -4057,7 +4059,7 @@ public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $d
$mform->addRule('submissionstatement', get_string('required'), 'required', null, 'client');
}
- $this->add_plugin_submission_elements($submission, $mform, $data);
+ $this->add_plugin_submission_elements($submission, $mform, $data, $USER->id);
// hidden params
$mform->addElement('hidden', 'id', $this->get_course_module()->id);

0 comments on commit fc7b7d5

Please sign in to comment.