Skip to content

Commit

Permalink
MDL-36289: Assignment - Prevent feedback files being copied to the ne…
Browse files Browse the repository at this point in the history
…xt user when using "Save and next".

Conflicts:

	mod/assign/feedback/file/locallib.php
  • Loading branch information
Damyon Wiese committed Oct 31, 2012
1 parent f2c33d0 commit 5f845b3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
17 changes: 17 additions & 0 deletions mod/assign/assignmentplugin.php
Expand Up @@ -220,8 +220,25 @@ public final 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
Expand Down
27 changes: 20 additions & 7 deletions mod/assign/feedback/file/locallib.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions mod/assign/locallib.php
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5f845b3

Please sign in to comment.