Merge branch 'MDL-44447-master' of git://github.com/lameze/moodle

This commit is contained in:
Damyon Wiese 2014-09-15 16:44:41 +08:00
commit 20a2e554f9
17 changed files with 150 additions and 47 deletions

View file

@ -119,8 +119,24 @@ class grade_export_form extends moodleform {
}
}
*/
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);
@ -184,5 +200,30 @@ class grade_export_form extends moodleform {
$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;
}
}

View file

@ -36,7 +36,17 @@ abstract class grade_export {
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
@ -184,6 +194,12 @@ abstract class grade_export {
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)) {
@ -212,31 +228,38 @@ abstract class grade_export {
/**
* 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);
}
/**

View file

@ -37,7 +37,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
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

View file

@ -67,7 +67,9 @@ class grade_export_ods extends grade_export {
$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) {
@ -101,12 +103,13 @@ class grade_export_ods extends grade_export {
$status = $geub->track($grade);
}
$gradestr = $this->format_grade($grade);
foreach ($this->displaytype as $gradedisplayconst) {
$gradestr = $this->format_grade($grade, $gradedisplayconst);
if (is_numeric($gradestr)) {
$myxls->write_number($i,$j++,$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

View file

@ -43,7 +43,8 @@ if (!empty($CFG->gradepublishing)) {
$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);

View file

@ -41,7 +41,8 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
$params = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true
'simpleui' => true,
'multipledisplaytypes' => true
);
$mform = new grade_export_form(null, $params);
$data = $mform->get_data();

View file

@ -67,9 +67,11 @@ class grade_export_txt extends grade_export {
$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);
}
@ -100,7 +102,9 @@ class grade_export_txt extends grade_export {
$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]);

View file

@ -44,7 +44,8 @@ $actionurl = new moodle_url('/grade/export/txt/export.php');
$formoptions = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true
'simpleui' => true,
'multipledisplaytypes' => true
);
$mform = new grade_export_form($actionurl, $formoptions);

View file

@ -39,11 +39,36 @@ Feature: I need to export grades as text
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-"

View file

@ -4,4 +4,4 @@ information provided here is intended especially for developers.
=== 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.

View file

@ -37,7 +37,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
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

View file

@ -65,8 +65,9 @@ class grade_export_xls extends grade_export {
$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));
@ -97,15 +98,14 @@ class grade_export_xls extends grade_export {
if ($export_tracking) {
$status = $geub->track($grade);
}
$gradestr = $this->format_grade($grade);
foreach ($this->displaytype as $gradedisplayconst) {
$gradestr = $this->format_grade($grade, $gradedisplayconst);
if (is_numeric($gradestr)) {
$myxls->write_number($i,$j++,$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]));

View file

@ -43,7 +43,8 @@ if (!empty($CFG->gradepublishing)) {
$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);

View file

@ -37,7 +37,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
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

View file

@ -68,7 +68,7 @@ class grade_export_xml extends grade_export {
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) {

View file

@ -46,7 +46,8 @@ $formoptions = array(
'idnumberrequired' => true,
'updategradesonly' => true,
'publishing' => true,
'simpleui' => true
'simpleui' => true,
'multipledisplaytypes' => false
);
$mform = new grade_export_form($actionurl, $formoptions);

View file

@ -708,3 +708,5 @@ $string['writinggradebookinfo'] = 'Writing gradebook settings';
$string['xml'] = 'XML';
$string['yes'] = 'Yes';
$string['yourgrade'] = 'Your grade';
$string['gradeexportdisplaytypes'] = 'Grade export display types';
$string['gradeexportcolumntype'] = '{$a->name} ({$a->extra})';