}
}
*/
- $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
- $mform->setDefault('display', $CFG->grade_export_displaytype);
+ if ($features['multipledisplaytypes']) {
+ /*
+ * Using advcheckbox because we need the grade display type (name) as key and grade display type (constant) as value.
+ * The method format_column_name requires the lang file string and the format_grade method requires the constant.
+ */
+ $checkboxes = array();
+ $checkboxes[] = $mform->createElement('advcheckbox', 'display[real]', null, get_string('real', 'grades'), null, array(0, GRADE_DISPLAY_TYPE_REAL));
+ $checkboxes[] = $mform->createElement('advcheckbox', 'display[percentage]', null, get_string('percentage', 'grades'), null, array(0, GRADE_DISPLAY_TYPE_PERCENTAGE));
+ $checkboxes[] = $mform->createElement('advcheckbox', 'display[letter]', null, get_string('letter', 'grades'), null, array(0, GRADE_DISPLAY_TYPE_LETTER));
+ $mform->addGroup($checkboxes, 'displaytypes', get_string('gradeexportdisplaytypes', 'grades'), ' ', false);
+ $mform->setDefault('display[real]', $CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_REAL);
+ $mform->setDefault('display[percentage]', $CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE);
+ $mform->setDefault('display[letter]', $CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_LETTER);
+ } else {
+ // Only used by XML grade export format.
+ $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
+ $mform->setDefault('display', $CFG->grade_export_displaytype);
+ }
//$default_gradedecimals = $CFG->grade_export_decimalpoints;
$options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
$this->add_action_buttons(false, $submitstring);
}
+
+ /**
+ * Overrides the mform get_data method.
+ *
+ * Created to force a value since the validation method does not work with multiple checkbox.
+ *
+ * @return stdClass form data object.
+ */
+ public function get_data() {
+ global $CFG;
+ $data = parent::get_data();
+ if ($data && $this->_customdata['multipledisplaytypes']) {
+ if (count(array_filter($data->display)) == 0) {
+ // Ensure that a value was selected as the export plugins expect at least one value.
+ if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_LETTER) {
+ $data->display['letter'] = GRADE_DISPLAY_TYPE_LETTER;
+ } else if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) {
+ $data->display['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
+ } else {
+ $data->display['real'] = GRADE_DISPLAY_TYPE_REAL;
+ }
+ }
+ }
+ return $data;
+ }
}
public $userkey; // export using private user key
public $updatedgradesonly; // only export updated grades
- public $displaytype; // display type (e.g. real, percentages, letter) for exports
+
+ /**
+ * Grade display type (real, percentages or letter).
+ *
+ * This attribute is an integer for XML file export. Otherwise is an array for all other formats (ODS, XLS and TXT).
+ *
+ * @var $displaytype Grade display type constant (1, 2 or 3) or an array of display types where the key is the name
+ * and the value is the grade display type constant or 0 for unchecked display types.
+ * @access public.
+ */
+ public $displaytype;
public $decimalpoints; // number of decimal points for exports
public $onlyactive; // only include users with an active enrolment
public $usercustomfields; // include users custom fields
if (isset($formdata->display)) {
$this->displaytype = $formdata->display;
+
+ // Used by grade exports which accept multiple display types.
+ // If the checkbox value is 0 (unchecked) then remove it.
+ if (is_array($formdata->display)) {
+ $this->displaytype = array_filter($formdata->display);
+ }
}
if (isset($formdata->updatedgradesonly)) {
/**
* Returns string representation of final grade
- * @param $object $grade instance of grade_grade class
+ * @param object $grade instance of grade_grade class
+ * @param integer $gradedisplayconst grade display type constant.
* @return string
*/
- public function format_grade($grade) {
- return grade_format_gradevalue($grade->finalgrade, $this->grade_items[$grade->itemid], false, $this->displaytype, $this->decimalpoints);
+ public function format_grade($grade, $gradedisplayconst = null) {
+ $displaytype = $this->displaytype;
+ if (is_array($this->displaytype) && !is_null($gradedisplayconst)) {
+ $displaytype = $gradedisplayconst;
+ }
+ return grade_format_gradevalue($grade->finalgrade, $this->grade_items[$grade->itemid], false, $displaytype, $this->decimalpoints);
}
/**
* Returns the name of column in export
* @param object $grade_item
- * @param boolena $feedback feedback colum
- * &return string
+ * @param boolean $feedback feedback colum
+ * @param string $gradedisplayname grade display name.
+ * @return string
*/
- public function format_column_name($grade_item, $feedback=false) {
+ public function format_column_name($grade_item, $feedback=false, $gradedisplayname = null) {
+ $column = new stdClass();
+
if ($grade_item->itemtype == 'mod') {
- $name = get_string('modulename', $grade_item->itemmodule).get_string('labelsep', 'langconfig').$grade_item->get_name();
+ $column->name = get_string('modulename', $grade_item->itemmodule).get_string('labelsep', 'langconfig').$grade_item->get_name();
} else {
- $name = $grade_item->get_name();
+ $column->name = $grade_item->get_name();
}
- if ($feedback) {
- $name .= ' ('.get_string('feedback').')';
- }
+ // We can't have feedback and display type at the same time.
+ $column->extra = ($feedback) ? get_string('feedback') : get_string($gradedisplayname, 'grades');
- return html_to_text($name, 0, false);
+ return html_to_text(get_string('gradeexportcolumntype', 'grades', $column), 0, false);
}
/**
print_error('cannotaccessgroup', 'grades');
}
}
-$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true));
+$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => true));
$data = $mform->get_data();
// print all the exported data here
$myxls->write_string(0, $pos++, get_string("suspended"));
}
foreach ($this->columns as $grade_item) {
- $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
+ foreach ($this->displaytype as $gradedisplayname => $gradedisplayconst) {
+ $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, false, $gradedisplayname));
+ }
// Add a column_feedback column.
if ($this->export_feedback) {
$status = $geub->track($grade);
}
- $gradestr = $this->format_grade($grade);
- if (is_numeric($gradestr)) {
- $myxls->write_number($i,$j++,$gradestr);
- }
- else {
- $myxls->write_string($i,$j++,$gradestr);
+ foreach ($this->displaytype as $gradedisplayconst) {
+ $gradestr = $this->format_grade($grade, $gradedisplayconst);
+ if (is_numeric($gradestr)) {
+ $myxls->write_number($i, $j++, $gradestr);
+ } else {
+ $myxls->write_string($i, $j++, $gradestr);
+ }
}
// writing feedback if requested
$actionurl = new moodle_url('/grade/export/ods/export.php');
$formoptions = array(
'publishing' => true,
- 'simpleui' => true
+ 'simpleui' => true,
+ 'multipledisplaytypes' => true
);
$mform = new grade_export_form($actionurl, $formoptions);
$params = array(
'includeseparator'=>true,
'publishing' => true,
- 'simpleui' => true
+ 'simpleui' => true,
+ 'multipledisplaytypes' => true
);
$mform = new grade_export_form(null, $params);
$data = $mform->get_data();
$exporttitle[] = get_string("suspended");
}
- // Add a feedback column.
+ // Add grades and feedback columns.
foreach ($this->columns as $grade_item) {
- $exporttitle[] = $this->format_column_name($grade_item);
+ foreach ($this->displaytype as $gradedisplayname => $gradedisplayconst) {
+ $exporttitle[] = $this->format_column_name($grade_item, false, $gradedisplayname);
+ }
if ($this->export_feedback) {
$exporttitle[] = $this->format_column_name($grade_item, true);
}
$status = $geub->track($grade);
}
- $exportdata[] = $this->format_grade($grade);
+ foreach ($this->displaytype as $gradedisplayconst) {
+ $exportdata[] = $this->format_grade($grade, $gradedisplayconst);
+ }
if ($this->export_feedback) {
$exportdata[] = $this->format_feedback($userdata->feedbacks[$itemid]);
$formoptions = array(
'includeseparator'=>true,
'publishing' => true,
- 'simpleui' => true
+ 'simpleui' => true,
+ 'multipledisplaytypes' => true
);
$mform = new grade_export_form($actionurl, $formoptions);
And I should not see "80.00"
@javascript
- Scenario: Export grades as text using percentages
+ Scenario: Export grades as text using real
When I set the field "Grade report" to "Plain text file"
And I expand all fieldsets
- And I set the field "Grade export display type" to "Percent"
+ And I set the following fields to these values:
+ | Real | 1 |
And I click on "Course total" "checkbox"
And I press "Download"
Then I should see "Student,1"
+ And I should see "80.00"
+
+ @javascript
+ Scenario: Export grades as text using percentages and letters
+ When I set the field "Grade report" to "Plain text file"
+ And I set the following fields to these values:
+ | Percentage | 1 |
+ | Letter | 1 |
+ And I press "Download"
+ Then I should see "Student,1"
+ And I should see "80.00 %"
+ And I should see "B-"
+
+ @javascript
+ Scenario: Export grades as text using real, percentages and letters
+ When I set the field "Grade report" to "Plain text file"
+ And I set the following fields to these values:
+ | Real | 1 |
+ | Percentage | 1 |
+ | Letter | 1 |
+ And I press "Download"
+ Then I should see "Student,1"
+ And I should see "80.00"
And I should see "80.00 %"
+ And I should see "B-"
\ No newline at end of file
=== 2.8 ===
The UI for the grade export form was simplified down so it's all on one page. The export preview was removed because it was not useful (more useful on import than on export). To update your export plugins you must pass 'simpleui' => true as an option to the grade_export_form, and make your grade_export_form submit directly to your export script. It's easiest to look at a complete example - see "git show 1cc43058" for a complete example of updating the ods exporter.
-
+Also the grade export UI form was changed to support multiples display types. The combo box was removed from (Open Document, Plain Text, Excel) and for each selected display type a column is generated. We didn't extended this solution to XML export which remains with a combo and can only select a single display type.
\ No newline at end of file
print_error('cannotaccessgroup', 'grades');
}
}
-$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true));
+$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => true));
$formdata = $mform->get_data();
// print all the exported data here
$myxls->write_string(0, $pos++, get_string("suspended"));
}
foreach ($this->columns as $grade_item) {
- $myxls->write_string(0, $pos++, $this->format_column_name($grade_item));
-
+ foreach ($this->displaytype as $gradedisplayname => $gradedisplayconst) {
+ $myxls->write_string(0, $pos++, $this->format_column_name($grade_item, false, $gradedisplayname));
+ }
// Add a column_feedback column
if ($this->export_feedback) {
$myxls->write_string(0, $pos++, $this->format_column_name($grade_item, true));
if ($export_tracking) {
$status = $geub->track($grade);
}
-
- $gradestr = $this->format_grade($grade);
- if (is_numeric($gradestr)) {
- $myxls->write_number($i,$j++,$gradestr);
+ foreach ($this->displaytype as $gradedisplayconst) {
+ $gradestr = $this->format_grade($grade, $gradedisplayconst);
+ if (is_numeric($gradestr)) {
+ $myxls->write_number($i, $j++, $gradestr);
+ } else {
+ $myxls->write_string($i, $j++, $gradestr);
+ }
}
- else {
- $myxls->write_string($i,$j++,$gradestr);
- }
-
// writing feedback if requested
if ($this->export_feedback) {
$myxls->write_string($i, $j++, $this->format_feedback($userdata->feedbacks[$itemid]));
$actionurl = new moodle_url('/grade/export/xls/export.php');
$formoptions = array(
'publishing' => true,
- 'simpleui' => true
+ 'simpleui' => true,
+ 'multipledisplaytypes' => true
);
$mform = new grade_export_form($actionurl, $formoptions);
print_error('cannotaccessgroup', 'grades');
}
}
-$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true));
+$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => false));
$formdata = $mform->get_data();
// print all the exported data here
foreach ($userdata->grades as $itemid => $grade) {
$grade_item = $this->grade_items[$itemid];
$grade->grade_item =& $grade_item;
- $gradestr = $this->format_grade($grade); // no formating for now
+ $gradestr = $this->format_grade($grade, $this->displaytype); // no formating for now
// MDL-11669, skip exported grades or bad grades (if setting says so)
if ($export_tracking) {
'idnumberrequired' => true,
'updategradesonly' => true,
'publishing' => true,
- 'simpleui' => true
+ 'simpleui' => true,
+ 'multipledisplaytypes' => false
);
$mform = new grade_export_form($actionurl, $formoptions);
$string['xml'] = 'XML';
$string['yes'] = 'Yes';
$string['yourgrade'] = 'Your grade';
+$string['gradeexportdisplaytypes'] = 'Grade export display types';
+$string['gradeexportcolumntype'] = '{$a->name} ({$a->extra})';
\ No newline at end of file