Permalink
Browse files

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...
1 parent f2c33d0 commit 5f845b3e66236de9196ab7f8908ee037023ee076 Damyon Wiese committed Oct 31, 2012
Showing with 46 additions and 14 deletions.
  1. +17 −0 mod/assign/assignmentplugin.php
  2. +20 −7 mod/assign/feedback/file/locallib.php
  3. +9 −7 mod/assign/locallib.php
View
17 mod/assign/assignmentplugin.php
@@ -220,8 +220,25 @@ public function save(stdClass $submissionorgrade, stdClass $data) {
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
View
27 mod/assign/feedback/file/locallib.php
@@ -78,17 +78,24 @@ private function get_file_options() {
* @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;
}
@@ -117,14 +124,20 @@ private function count_files($gradeid, $area) {
* @return bool
*/
public function save(stdClass $grade, stdClass $data) {
-
global $DB;
$fileoptions = $this->get_file_options();
+ $userid = $grade->userid;
+ $elementname = 'files_' . $userid;
- $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id);
-
+ $data = file_postupdate_standard_filemanager($data,
+ $elementname,
+ $fileoptions,
+ $this->assignment->get_context(),
+ 'assignfeedback_file',
+ ASSIGNFEEDBACK_FILE_FILEAREA,
+ $grade->id);
$filefeedback = $this->get_file_feedback($grade->id);
if ($filefeedback) {
View
16 mod/assign/locallib.php
@@ -754,13 +754,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());
}
}
@@ -3013,8 +3014,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);
@@ -3058,13 +3059,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());
}
}
@@ -3124,7 +3126,7 @@ public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $d
$submission = $this->get_user_submission($USER->id, false);
- $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 5f845b3

Please sign in to comment.