Skip to content
Browse files

MDL-27322 grade: added the ability to not have suspended students inc…

…luded in a grade export
  • Loading branch information...
1 parent e16e230 commit 78ab98bc5e27d2a23a4227e1e065f35fe3088150 @andyjdavis andyjdavis committed May 2, 2012
View
4 grade/export/grade_export_form.php
@@ -37,6 +37,10 @@ function definition() {
$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
12 grade/export/lib.php
@@ -39,6 +39,7 @@
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 @@
* @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 @@ public function grade_export($course, $groupid=0, $itemlist='', $export_feedback
$this->displaytype = $displaytype;
$this->decimalpoints = $decimalpoints;
+ $this->onlyactive = $onlyactive;
}
/**
@@ -125,6 +127,10 @@ function process_form($formdata) {
$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 @@ public function display_preview($require_user_idnumber=false) {
$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 @@ public function get_export_params() {
'export_feedback' =>$this->export_feedback,
'updatedgradesonly' =>$this->updatedgradesonly,
'displaytype' =>$this->displaytype,
- 'decimalpoints' =>$this->decimalpoints);
+ 'decimalpoints' =>$this->decimalpoints,
+ 'export_onlyactive' =>$this->onlyactive);
return $params;
}
View
3 grade/export/ods/export.php
@@ -26,6 +26,7 @@
$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 @@
}
// 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
1 grade/export/ods/grade_export_ods.php
@@ -64,6 +64,7 @@ function print_grades() {
$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
2 grade/export/ods/index.php
@@ -51,7 +51,7 @@
// 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
3 grade/export/txt/export.php
@@ -27,6 +27,7 @@
$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 @@
}
// 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
9 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 @@ public function print_grades() {
/// 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
2 grade/export/txt/index.php
@@ -51,7 +51,7 @@
// 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
3 grade/export/xls/export.php
@@ -26,6 +26,7 @@
$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 @@
}
// 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
1 grade/export/xls/grade_export_xls.php
@@ -63,6 +63,7 @@ public function print_grades() {
$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
2 grade/export/xls/index.php
@@ -51,7 +51,7 @@
// 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
3 grade/export/xml/export.php
@@ -26,6 +26,7 @@
$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 @@
}
// 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
1 grade/export/xml/grade_export_xml.php
@@ -54,6 +54,7 @@ public function print_grades($feedback = false) {
$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
2 grade/export/xml/index.php
@@ -52,7 +52,7 @@
// 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
21 grade/lib.php
@@ -44,6 +44,11 @@ class graded_users_iterator {
public $sortorder2;
/**
+ * Should users whose enrolment has been suspended be ignored?
+ */
+ protected $onlyactive = false;
+
+ /**
* Constructor
*
* @param object $course A course object
@@ -89,9 +94,7 @@ public function init() {
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 @@ function close() {
$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
2 lang/en/grades.php
@@ -190,6 +190,8 @@
$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';

0 comments on commit 78ab98b

Please sign in to comment.
Something went wrong with that request. Please try again.