Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…xt user when using "Save and next".

Conflicts:

	mod/assign/feedback/file/locallib.php
  • Loading branch information...
commit 5f845b3e66236de9196ab7f8908ee037023ee076 1 parent f2c33d0
Damyon Wiese authored
17 mod/assign/assignmentplugin.php
@@ -220,8 +220,25 @@ public function save(stdClass $submissionorgrade, stdClass $data) {
220 220 return $this->get_config('enabled');
221 221 }
222 222
  223 +
  224 + /**
  225 + * Get any additional fields for the submission/grading form for this assignment.
  226 + *
  227 + * @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data,
  228 + * for feedback plugins it is the grade data
  229 + * @param MoodleQuickForm $mform - This is the form
  230 + * @param stdClass $data - This is the form data that can be modified for example by a filemanager element
  231 + * @param int $userid - This is the userid for the current submission.
  232 + * This is passed separately as there may not yet be a submission or grade.
  233 + * @return boolean - true if we added anything to the form
  234 + */
  235 + public function get_form_elements_for_user($submissionorgrade, MoodleQuickForm $mform, stdClass $data, $userid) {
  236 + return $this->get_form_elements($submissionorgrade, $mform, $data);
  237 + }
  238 +
223 239 /**
224 240 * Get any additional fields for the submission/grading form for this assignment.
  241 + * This function is retained for backwards compatibility - new plugins should override {@link get_form_elements_for_user()}.
225 242 *
226 243 * @param mixed $submissionorgrade submission|grade - For submission plugins this is the submission data, for feedback plugins it is the grade data
227 244 * @param MoodleQuickForm $mform - This is the form
27 mod/assign/feedback/file/locallib.php
@@ -78,17 +78,24 @@ private function get_file_options() {
78 78 * @param stdClass $grade
79 79 * @param MoodleQuickForm $mform
80 80 * @param stdClass $data
  81 + * @param int $userid The userid we are currently grading
81 82 * @return bool true if elements were added to the form
82 83 */
83   - public function get_form_elements($grade, MoodleQuickForm $mform, stdClass $data) {
  84 + public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
84 85
85 86 $fileoptions = $this->get_file_options();
86 87 $gradeid = $grade ? $grade->id : 0;
  88 + $elementname = 'files_' . $userid;
87 89
  90 + $data = file_prepare_standard_filemanager($data,
  91 + $elementname,
  92 + $fileoptions,
  93 + $this->assignment->get_context(),
  94 + 'assignfeedback_file',
  95 + ASSIGNFEEDBACK_FILE_FILEAREA,
  96 + $gradeid);
88 97
89   - $data = file_prepare_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $gradeid);
90   -
91   - $mform->addElement('filemanager', 'files_filemanager', '', null, $fileoptions);
  98 + $mform->addElement('filemanager', $elementname . '_filemanager', '', null, $fileoptions);
92 99
93 100 return true;
94 101 }
@@ -117,14 +124,20 @@ private function count_files($gradeid, $area) {
117 124 * @return bool
118 125 */
119 126 public function save(stdClass $grade, stdClass $data) {
120   -
121 127 global $DB;
122 128
123 129 $fileoptions = $this->get_file_options();
124 130
  131 + $userid = $grade->userid;
  132 + $elementname = 'files_' . $userid;
125 133
126   - $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id);
127   -
  134 + $data = file_postupdate_standard_filemanager($data,
  135 + $elementname,
  136 + $fileoptions,
  137 + $this->assignment->get_context(),
  138 + 'assignfeedback_file',
  139 + ASSIGNFEEDBACK_FILE_FILEAREA,
  140 + $grade->id);
128 141
129 142 $filefeedback = $this->get_file_feedback($grade->id);
130 143 if ($filefeedback) {
16 mod/assign/locallib.php
@@ -754,13 +754,14 @@ public function update_instance($formdata) {
754 754 * @param mixed $grade stdClass|null
755 755 * @param MoodleQuickForm $mform
756 756 * @param stdClass $data
  757 + * @param int $userid - The userid we are grading
757 758 * @return void
758 759 */
759   - private function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data) {
  760 + private function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
760 761 foreach ($this->feedbackplugins as $plugin) {
761 762 if ($plugin->is_enabled() && $plugin->is_visible()) {
762 763 $mform->addElement('header', 'header_' . $plugin->get_type(), $plugin->get_name());
763   - if (!$plugin->get_form_elements($grade, $mform, $data)) {
  764 + if (!$plugin->get_form_elements_for_user($grade, $mform, $data, $userid)) {
764 765 $mform->removeElement('header_' . $plugin->get_type());
765 766 }
766 767 }
@@ -3013,8 +3014,8 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
3013 3014
3014 3015 $mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist))));
3015 3016
3016   - // plugins
3017   - $this->add_plugin_grade_elements($grade, $mform, $data);
  3017 + // Let feedback plugins add elements to the grading form.
  3018 + $this->add_plugin_grade_elements($grade, $mform, $data, $userid);
3018 3019
3019 3020 // hidden params
3020 3021 $mform->addElement('hidden', 'id', $this->get_course_module()->id);
@@ -3058,13 +3059,14 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
3058 3059 * @param mixed $submission stdClass|null
3059 3060 * @param MoodleQuickForm $mform
3060 3061 * @param stdClass $data
  3062 + * @param int $userid The current userid (same as $USER->id)
3061 3063 * @return void
3062 3064 */
3063   - private function add_plugin_submission_elements($submission, MoodleQuickForm $mform, stdClass $data) {
  3065 + private function add_plugin_submission_elements($submission, MoodleQuickForm $mform, stdClass $data, $userid) {
3064 3066 foreach ($this->submissionplugins as $plugin) {
3065 3067 if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
3066 3068 $mform->addElement('header', 'header_' . $plugin->get_type(), $plugin->get_name());
3067   - if (!$plugin->get_form_elements($submission, $mform, $data)) {
  3069 + if (!$plugin->get_form_elements_for_user($submission, $mform, $data, $userid)) {
3068 3070 $mform->removeElement('header_' . $plugin->get_type());
3069 3071 }
3070 3072 }
@@ -3124,7 +3126,7 @@ public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $d
3124 3126
3125 3127 $submission = $this->get_user_submission($USER->id, false);
3126 3128
3127   - $this->add_plugin_submission_elements($submission, $mform, $data);
  3129 + $this->add_plugin_submission_elements($submission, $mform, $data, $USER->id);
3128 3130
3129 3131 // hidden params
3130 3132 $mform->addElement('hidden', 'id', $this->get_course_module()->id);

0 comments on commit 5f845b3

Please sign in to comment.
Something went wrong with that request. Please try again.