MDL-27322 grade: added the ability to not have suspended students included in a grade export

This commit is contained in:
Andrew Davis 2012-05-02 18:15:53 +07:00
parent e16e2300c5
commit 78ab98bc5e
16 changed files with 54 additions and 17 deletions

View File

@ -37,6 +37,10 @@ class grade_export_form extends moodleform {
$mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
$mform->setDefault('export_feedback', 0);
$mform->addElement('advcheckbox', 'export_onlyactive', get_string('exportonlyactive', 'grades'));
$mform->setDefault('export_onlyactive', 0);
$mform->addHelpButton('export_onlyactive', 'exportonlyactive', 'grades');
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);

View File

@ -39,6 +39,7 @@ abstract class grade_export {
public $updatedgradesonly; // only export updated grades
public $displaytype; // display type (e.g. real, percentages, letter) for exports
public $decimalpoints; // number of decimal points for exports
public $onlyactive; // only include users with an active enrolment
/**
* Constructor should set up all the private variables ready to be pulled
* @access public
@ -49,7 +50,7 @@ abstract class grade_export {
* @param boolean $export_letters
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
*/
public function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2) {
public function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $onlyactive = false) {
$this->course = $course;
$this->groupid = $groupid;
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id));
@ -83,6 +84,7 @@ abstract class grade_export {
$this->displaytype = $displaytype;
$this->decimalpoints = $decimalpoints;
$this->onlyactive = $onlyactive;
}
/**
@ -125,6 +127,10 @@ abstract class grade_export {
$this->export_feedback = $formdata->export_feedback;
}
if (isset($formdata->export_onlyactive)) {
$this->onlyactive = $formdata->export_onlyactive;
}
if (isset($formdata->previewrows)) {
$this->previewrows = $formdata->previewrows;
}
@ -222,6 +228,7 @@ abstract class grade_export {
$i = 0;
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {
// number of preview rows
@ -290,7 +297,8 @@ abstract class grade_export {
'export_feedback' =>$this->export_feedback,
'updatedgradesonly' =>$this->updatedgradesonly,
'displaytype' =>$this->displaytype,
'decimalpoints' =>$this->decimalpoints);
'decimalpoints' =>$this->decimalpoints,
'export_onlyactive' =>$this->onlyactive);
return $params;
}

View File

@ -26,6 +26,7 @@ $export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
$updatedgradesonly = optional_param('updatedgradesonly', false, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_INT);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -44,7 +45,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
// print all the exported data here
$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$export->print_grades();

View File

@ -64,6 +64,7 @@ class grade_export_ods extends grade_export {
$i = 0;
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {
$i++;

View File

@ -51,7 +51,7 @@ if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/
// process post information
if ($data = $mform->get_data()) {
$export = new grade_export_ods($course, $currentgroup, '', false, false, $data->display, $data->decimals);
$export = new grade_export_ods($course, $currentgroup, '', false, false, $data->display, $data->decimals, $data->export_onlyactive);
// print the grades on screen for feedbacks
$export->process_form($data);

View File

@ -27,6 +27,7 @@ $separator = optional_param('separator', 'comma', PARAM_ALPHA);
$updatedgradesonly = optional_param('updatedgradesonly', false, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_INT);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -45,7 +46,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
// print all the exported data here
$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $separator);
$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $separator, $onlyactive);
$export->print_grades();

View File

@ -23,13 +23,13 @@ class grade_export_txt extends grade_export {
public $separator; // default separator
public function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') {
$this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
public function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma', $onlyactive = false) {
$this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$this->separator = $separator;
}
public function __construct($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') {
parent::__construct($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
public function __construct($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator = 'comma', $onlyactive = false) {
parent::__construct($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$this->separator = $separator;
}
@ -91,6 +91,7 @@ class grade_export_txt extends grade_export {
/// Print all the lines of data.
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {

View File

@ -51,7 +51,7 @@ if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/
// process post information
if ($data = $mform->get_data()) {
$export = new grade_export_txt($course, $currentgroup, '', false, false, $data->display, $data->decimals, $data->separator);
$export = new grade_export_txt($course, $currentgroup, '', false, false, $data->display, $data->decimals, $data->separator, $data->export_onlyactive);
// print the grades on screen for feedback

View File

@ -26,6 +26,7 @@ $export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
$updatedgradesonly = optional_param('updatedgradesonly', false, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_INT);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -44,7 +45,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
// print all the exported data here
$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$export->print_grades();

View File

@ -63,6 +63,7 @@ class grade_export_xls extends grade_export {
$i = 0;
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {
$i++;

View File

@ -51,7 +51,7 @@ if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/
// process post information
if ($data = $mform->get_data()) {
$export = new grade_export_xls($course, $currentgroup, '', false, false, $data->display, $data->decimals);
$export = new grade_export_xls($course, $currentgroup, '', false, false, $data->display, $data->decimals, $data->export_onlyactive);
// print the grades on screen for feedbacks
$export->process_form($data);

View File

@ -26,6 +26,7 @@ $export_feedback = optional_param('export_feedback', 0, PARAM_BOOL);
$updatedgradesonly = optional_param('updatedgradesonly', false, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_INT);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -44,7 +45,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
// print all the exported data here
$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$export->print_grades();

View File

@ -54,6 +54,7 @@ class grade_export_xml extends grade_export {
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {
$user = $userdata->user;

View File

@ -52,7 +52,7 @@ if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/
// process post information
if ($data = $mform->get_data()) {
$export = new grade_export_xml($course, $currentgroup, '', false, $data->updatedgradesonly, $data->display, $data->decimals);
$export = new grade_export_xml($course, $currentgroup, '', false, $data->updatedgradesonly, $data->display, $data->decimals, $data->export_onlyactive);
// print the grades on screen for feedbacks
$export->process_form($data);

View File

@ -43,6 +43,11 @@ class graded_users_iterator {
public $sortfield2;
public $sortorder2;
/**
* Should users whose enrolment has been suspended be ignored?
*/
protected $onlyactive = false;
/**
* Constructor
*
@ -89,9 +94,7 @@ class graded_users_iterator {
list($gradebookroles_sql, $params) =
$DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr');
//limit to users with an active enrolment
list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext);
list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, '', 0, $this->onlyactive);
$params = array_merge($params, $enrolledparams);
@ -253,6 +256,18 @@ class graded_users_iterator {
$this->gradestack = array();
}
/**
* Should all enrolled users be exported or just those with an active enrolment?
*
* @param bool $onlyactive True to limit the export to users with an active enrolment
*/
public function require_active_enrolment($onlyactive = true) {
if (!empty($this->users_rs)) {
debugging('Calling require_active_enrolment() has no effect unless you call init() again', DEBUG_DEVELOPER);
}
$this->onlyactive = $onlyactive;
}
/**
* _push

View File

@ -190,6 +190,8 @@ $string['exportalloutcomes'] = 'Export all outcomes';
$string['exportfeedback'] = 'Include feedback in export';
$string['exportplugins'] = 'Export plugins';
$string['exportsettings'] = 'Export settings';
$string['exportonlyactive'] = 'Require active enrolment';
$string['exportonlyactive_help'] = 'Only include students in the export whose enrolment has not been suspended';
$string['exportto'] = 'Export to';
$string['extracreditwarning'] = 'Note: Setting all items for a category to extra credit will effectively remove them from the grade calculation. Since there will be no point total';
$string['feedback'] = 'Feedback';