Skip to content

Commit

Permalink
MDL-27322 grade: added the ability to not have suspended students inc…
Browse files Browse the repository at this point in the history
…luded in a grade export
  • Loading branch information
andyjdavis committed May 10, 2012
1 parent e16e230 commit 78ab98b
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 17 deletions.
4 changes: 4 additions & 0 deletions grade/export/grade_export_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions grade/export/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -83,6 +84,7 @@ public function grade_export($course, $groupid=0, $itemlist='', $export_feedback

$this->displaytype = $displaytype;
$this->decimalpoints = $decimalpoints;
$this->onlyactive = $onlyactive;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion grade/export/ods/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();


1 change: 1 addition & 0 deletions grade/export/ods/grade_export_ods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion grade/export/ods/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion grade/export/txt/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();


9 changes: 5 additions & 4 deletions grade/export/txt/grade_export_txt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()) {

Expand Down
2 changes: 1 addition & 1 deletion grade/export/txt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion grade/export/xls/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();


1 change: 1 addition & 0 deletions grade/export/xls/grade_export_xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion grade/export/xls/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion grade/export/xml/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();


1 change: 1 addition & 0 deletions grade/export/xml/grade_export_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion grade/export/xml/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 18 additions & 3 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lang/en/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 78ab98b

Please sign in to comment.