diff --git a/grade/export/grade_export_form.php b/grade/export/grade_export_form.php index a5c02c6ce81..daccfa8b664 100644 --- a/grade/export/grade_export_form.php +++ b/grade/export/grade_export_form.php @@ -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); diff --git a/grade/export/lib.php b/grade/export/lib.php index b71a7b30c09..1530d2cdf85 100644 --- a/grade/export/lib.php +++ b/grade/export/lib.php @@ -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; } diff --git a/grade/export/ods/export.php b/grade/export/ods/export.php index f81f1d65304..04a00e8f764 100644 --- a/grade/export/ods/export.php +++ b/grade/export/ods/export.php @@ -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(); diff --git a/grade/export/ods/grade_export_ods.php b/grade/export/ods/grade_export_ods.php index e9ff0950756..e3661315a40 100644 --- a/grade/export/ods/grade_export_ods.php +++ b/grade/export/ods/grade_export_ods.php @@ -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++; diff --git a/grade/export/ods/index.php b/grade/export/ods/index.php index f0d4b3c9330..78cd1160b6b 100644 --- a/grade/export/ods/index.php +++ b/grade/export/ods/index.php @@ -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); diff --git a/grade/export/txt/export.php b/grade/export/txt/export.php index ab7a03b96dd..e5e572c4294 100644 --- a/grade/export/txt/export.php +++ b/grade/export/txt/export.php @@ -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(); diff --git a/grade/export/txt/grade_export_txt.php b/grade/export/txt/grade_export_txt.php index 77f804bb515..6ca697ad607 100644 --- a/grade/export/txt/grade_export_txt.php +++ b/grade/export/txt/grade_export_txt.php @@ -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()) { diff --git a/grade/export/txt/index.php b/grade/export/txt/index.php index 47de3e7c8bd..7f5f842a880 100644 --- a/grade/export/txt/index.php +++ b/grade/export/txt/index.php @@ -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 diff --git a/grade/export/xls/export.php b/grade/export/xls/export.php index 4df1fec85e2..8526f3c0745 100644 --- a/grade/export/xls/export.php +++ b/grade/export/xls/export.php @@ -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(); diff --git a/grade/export/xls/grade_export_xls.php b/grade/export/xls/grade_export_xls.php index f1efc6ee306..a89c91081fa 100644 --- a/grade/export/xls/grade_export_xls.php +++ b/grade/export/xls/grade_export_xls.php @@ -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++; diff --git a/grade/export/xls/index.php b/grade/export/xls/index.php index fc509bc78a8..68d7f678a43 100644 --- a/grade/export/xls/index.php +++ b/grade/export/xls/index.php @@ -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); diff --git a/grade/export/xml/export.php b/grade/export/xml/export.php index 7807993d525..1424fe87079 100644 --- a/grade/export/xml/export.php +++ b/grade/export/xml/export.php @@ -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(); diff --git a/grade/export/xml/grade_export_xml.php b/grade/export/xml/grade_export_xml.php index b349b894b77..396a044fced 100644 --- a/grade/export/xml/grade_export_xml.php +++ b/grade/export/xml/grade_export_xml.php @@ -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; diff --git a/grade/export/xml/index.php b/grade/export/xml/index.php index bc4d9251375..3903846d652 100644 --- a/grade/export/xml/index.php +++ b/grade/export/xml/index.php @@ -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); diff --git a/grade/lib.php b/grade/lib.php index 8c969f28994..7173c8930ad 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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 diff --git a/lang/en/grades.php b/lang/en/grades.php index f79ae7fe6c7..5443b079226 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -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';