Skip to content

Commit

Permalink
Merge branch 'MDL-36289' of git://github.com/netspotau/moodle-mod_assign
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 21, 2012
2 parents 31112f3 + fc7b7d5 commit 77f948a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
17 changes: 17 additions & 0 deletions mod/assign/assignmentplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions mod/assign/feedback/file/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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',
Expand Down
16 changes: 9 additions & 7 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -3926,8 +3927,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 @@ -3978,13 +3979,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 @@ -4066,7 +4068,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);
Expand Down

0 comments on commit 77f948a

Please sign in to comment.