Merge branch 'MDL-36289' of git://github.com/netspotau/moodle-mod_assign

This commit is contained in:
Dan Poltawski 2012-11-21 12:00:28 +08:00
commit 77f948a2f7
3 changed files with 41 additions and 12 deletions

View File

@ -220,9 +220,26 @@ abstract class assign_plugin {
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
* @param stdClass $data - This is the form data that can be modified for example by a filemanager element

View File

@ -125,17 +125,24 @@ class assign_feedback_file extends assign_feedback_plugin {
* @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 @@ class assign_feedback_file extends assign_feedback_plugin {
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 File

@ -808,13 +808,14 @@ class assign {
* @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());
}
}
@ -3926,8 +3927,8 @@ class assign {
$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);
@ -3978,13 +3979,14 @@ class assign {
* @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());
}
}
@ -4066,7 +4068,7 @@ class assign {
$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);