From 864d1f8c2cb938537ed0ef2214f7261ef7d6779a Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 10 Oct 2007 06:43:23 +0000 Subject: [PATCH] MDL-11667, adding 2 global variables to set default export decimal point and display format. During export there are 2 new settings for decimal points and display format, default to site setting. Removed letter option because it is a format that you can choose now. --- admin/settings/grades.php | 18 +++++++++++++- grade/export/grade_export_form.php | 35 ++++++++++++++++++++++----- grade/export/lib.php | 20 +++++++-------- grade/export/ods/export.php | 14 ++++++----- grade/export/ods/index.php | 2 +- grade/export/txt/export.php | 16 ++++++------ grade/export/txt/grade_export_txt.php | 4 +-- grade/export/txt/index.php | 2 +- grade/export/xls/export.php | 14 ++++++----- grade/export/xls/index.php | 2 +- grade/export/xml/export.php | 13 +++++----- grade/export/xml/grade_export_xml.php | 2 +- grade/export/xml/index.php | 3 ++- lang/en_utf8/grades.php | 6 +++-- 14 files changed, 100 insertions(+), 51 deletions(-) diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 85558dddf5e..69b013add80 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -7,7 +7,7 @@ require_once $CFG->libdir.'/grade/constants.php'; $temp = new admin_settingpage('gradessettings', get_string('gradessettings', 'grades')); -$temp->add(new admin_setting_special_gradeexport()); + // enable outcomes checkbox $temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT)); // enable publishing in exports/imports @@ -33,6 +33,22 @@ $temp->add(new admin_setting_configselect('grade_decimalpoints', get_string('dec '4' => '4', '5' => '5'))); +$temp->add(new admin_setting_configselect('grade_export_displaytype', get_string('gradeexportdisplaytype', 'grades'), + get_string('configgradeexportdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL, + array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), + GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), + GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')))); + +$temp->add(new admin_setting_configselect('grade_export_decimalpoints', get_string('gradeexportdecimalpoints', 'grades'), + get_string('configexportdecimalpoints', 'grades'), 2, + array( '0' => '0', + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '5' => '5'))); + +$temp->add(new admin_setting_special_gradeexport()); $ADMIN->add('grades', $temp); /// Scales and outcomes diff --git a/grade/export/grade_export_form.php b/grade/export/grade_export_form.php index 8ea53cc2c70..210b695c5f4 100755 --- a/grade/export/grade_export_form.php +++ b/grade/export/grade_export_form.php @@ -38,11 +38,6 @@ class grade_export_form extends moodleform { $mform->addElement('header', 'options', get_string('options', 'grades')); - $mform->addElement('advcheckbox', 'export_letters', get_string('exportletters', 'grades')); - $mform->setDefault('export_letters', 0); - $mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'), - false, true, false, get_string("exportlettershelp", 'grades'))); - $mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades')); $mform->setDefault('export_feedback', 0); @@ -52,7 +47,35 @@ class grade_export_form extends moodleform { if (!empty($features['updatedgrades'])) { $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades')); } - + + /// selections for decimal points and format, MDL-11667, defaults to site settings, if set + //$default_gradedisplaytype = $CFG->grade_export_displaytype; + $options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), + GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), + GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')); + + /* + foreach ($options as $key=>$option) { + if ($key == $default_gradedisplaytype) { + $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option); + break; + } + } + */ + $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); + $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options); + $mform->setDefault('decimals', $CFG->grade_export_decimalpoints); + $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER); + /* + if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) { + $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT); + } + */ + if (!empty($features['includeseparator'])) { $radio = array(); $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab'); diff --git a/grade/export/lib.php b/grade/export/lib.php index 39678febbc0..9360820e041 100755 --- a/grade/export/lib.php +++ b/grade/export/lib.php @@ -45,6 +45,8 @@ class grade_export { var $userkey; // export using private user key var $updatedgradesonly; // only export updated grades + var $displaytype; // display type (e.g. real, percentages, letter) for exports + var $decimalpoints; // number of decimal points for exports /** * Constructor should set up all the private variables ready to be pulled * @param object $course @@ -54,7 +56,7 @@ class grade_export { * @param boolean $export_letters * @note Exporting as letters will lead to data loss if that exported set it re-imported. */ - function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $export_letters=false, $updatedgradesonly = false) { + function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2) { $this->course = $course; $this->groupid = $groupid; $this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id)); @@ -79,6 +81,9 @@ class grade_export { $this->userkey = ''; $this->previewrows = false; $this->updatedgradesonly = $updatedgradesonly; + + $this->displaytype = $displaytype; + $this->decimalpoints = $decimalpoints; } /** @@ -148,14 +153,7 @@ class grade_export { * @return string */ function format_grade($grade) { - $displaytype = null; - if ($this->export_letters) { - $displaytype = GRADE_DISPLAY_TYPE_LETTER; - } else { - $displaytype = GRADE_DISPLAY_TYPE_REAL; - } - - return grade_format_gradevalue($grade->finalgrade, $this->grade_items[$grade->itemid], false, $displaytype, null); + return grade_format_gradevalue($grade->finalgrade, $this->grade_items[$grade->itemid], false, $this->displaytype, $this->decimalpoints); } /** @@ -266,7 +264,9 @@ echo "status is $status"; 'itemids' =>implode(',', $itemids), 'export_letters' =>$this->export_letters, 'export_feedback' =>$this->export_feedback, - 'updatedgradesonly' =>$this->updatedgradesonly); + 'updatedgradesonly' =>$this->updatedgradesonly, + 'displaytype' =>$this->displaytype, + 'decimalpoints' =>$this->decimalpoints); return $params; } diff --git a/grade/export/ods/export.php b/grade/export/ods/export.php index bad4edae2e0..3b163b78319 100755 --- a/grade/export/ods/export.php +++ b/grade/export/ods/export.php @@ -27,11 +27,13 @@ require_once '../../../config.php'; require_once $CFG->dirroot.'/grade/export/lib.php'; require_once 'grade_export_ods.php'; -$id = required_param('id', PARAM_INT); // course id -$groupid = optional_param('groupid', 0, PARAM_INT); -$itemids = required_param('itemids', PARAM_RAW); -$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL); -$export_letters = optional_param('export_letters', 0, PARAM_BOOL); +$id = required_param('id', PARAM_INT); // course id +$groupid = optional_param('groupid', 0, PARAM_INT); +$itemids = required_param('itemids', PARAM_RAW); +$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); if (!$course = get_record('course', 'id', $id)) { print_error('nocourseid'); @@ -45,7 +47,7 @@ require_capability('gradeexport/ods:view', $context); // print all the exported data here -$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $export_letters); +$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints); $export->print_grades(); ?> diff --git a/grade/export/ods/index.php b/grade/export/ods/index.php index 36015d13c4e..51c37a34478 100755 --- a/grade/export/ods/index.php +++ b/grade/export/ods/index.php @@ -55,7 +55,7 @@ $mform = new grade_export_form(null, array('publishing' => true)); // process post information if ($data = $mform->get_data()) { - $export = new grade_export_ods($course, groups_get_course_group($course)); + $export = new grade_export_ods($course, groups_get_course_group($course), '', false, $data->updatedgradesonly, $data->display, $data->decimals); // 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 80a5388bf82..37b0bebc727 100755 --- a/grade/export/txt/export.php +++ b/grade/export/txt/export.php @@ -27,12 +27,14 @@ require_once '../../../config.php'; require_once $CFG->dirroot.'/grade/export/lib.php'; require_once 'grade_export_txt.php'; -$id = required_param('id', PARAM_INT); // course id -$groupid = optional_param('groupid', 0, PARAM_INT); -$itemids = required_param('itemids', PARAM_RAW); -$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL); -$export_letters = optional_param('export_letters', 0, PARAM_BOOL); -$separator = optional_param('separator', 'comma', PARAM_ALPHA); +$id = required_param('id', PARAM_INT); // course id +$groupid = optional_param('groupid', 0, PARAM_INT); +$itemids = required_param('itemids', PARAM_RAW); +$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL); +$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); if (!$course = get_record('course', 'id', $id)) { print_error('nocourseid'); @@ -46,7 +48,7 @@ require_capability('gradeexport/txt:view', $context); // print all the exported data here -$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $export_letters, $separator); +$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $separator); $export->print_grades(); ?> diff --git a/grade/export/txt/grade_export_txt.php b/grade/export/txt/grade_export_txt.php index 033c00b1353..4e8ca4c6a72 100755 --- a/grade/export/txt/grade_export_txt.php +++ b/grade/export/txt/grade_export_txt.php @@ -30,8 +30,8 @@ class grade_export_txt extends grade_export { var $separator; // default separator - function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $export_letters=false, $separator='comma') { - $this->grade_export($course, $groupid, $itemlist, $export_feedback, $export_letters); + 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); $this->separator = $separator; } diff --git a/grade/export/txt/index.php b/grade/export/txt/index.php index 0f537d8dc82..007c4a530d1 100755 --- a/grade/export/txt/index.php +++ b/grade/export/txt/index.php @@ -55,7 +55,7 @@ $mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing // process post information if ($data = $mform->get_data()) { - $export = new grade_export_txt($course, groups_get_course_group($course)); + $export = new grade_export_txt($course, groups_get_course_group($course), '', false, $data->updatedgradesonly, $data->display, $data->decimals); // print the grades on screen for feedback diff --git a/grade/export/xls/export.php b/grade/export/xls/export.php index 1fc83506cc7..3774fde9355 100755 --- a/grade/export/xls/export.php +++ b/grade/export/xls/export.php @@ -27,11 +27,13 @@ require_once '../../../config.php'; require_once $CFG->dirroot.'/grade/export/lib.php'; require_once 'grade_export_xls.php'; -$id = required_param('id', PARAM_INT); // course id -$groupid = optional_param('groupid', 0, PARAM_INT); -$itemids = required_param('itemids', PARAM_RAW); -$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL); -$export_letters = optional_param('export_letters', 0, PARAM_BOOL); +$id = required_param('id', PARAM_INT); // course id +$groupid = optional_param('groupid', 0, PARAM_INT); +$itemids = required_param('itemids', PARAM_RAW); +$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); if (!$course = get_record('course', 'id', $id)) { print_error('nocourseid'); @@ -45,7 +47,7 @@ require_capability('gradeexport/xls:view', $context); // print all the exported data here -$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $export_letters); +$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints); $export->print_grades(); ?> diff --git a/grade/export/xls/index.php b/grade/export/xls/index.php index 5c3803d3a9b..35f0f865e69 100755 --- a/grade/export/xls/index.php +++ b/grade/export/xls/index.php @@ -55,7 +55,7 @@ $mform = new grade_export_form(null, array('publishing' => true)); // process post information if ($data = $mform->get_data()) { - $export = new grade_export_xls($course, groups_get_course_group($course)); + $export = new grade_export_xls($course, groups_get_course_group($course), '', false, $data->updatedgradesonly, $data->display, $data->decimals); // 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 a9270efa233..42a7419dd20 100755 --- a/grade/export/xml/export.php +++ b/grade/export/xml/export.php @@ -27,12 +27,13 @@ require_once '../../../config.php'; require_once $CFG->dirroot.'/grade/export/lib.php'; require_once 'grade_export_xml.php'; -$id = required_param('id', PARAM_INT); // course id -$groupid = optional_param('groupid', 0, PARAM_INT); -$itemids = required_param('itemids', PARAM_RAW); -$export_feedback = optional_param('export_feedback', 0, PARAM_BOOL); -$export_letters = optional_param('export_letters', 0, PARAM_BOOL); +$id = required_param('id', PARAM_INT); // course id +$groupid = optional_param('groupid', 0, PARAM_INT); +$itemids = required_param('itemids', PARAM_RAW); +$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); if (!$course = get_record('course', 'id', $id)) { print_error('nocourseid'); @@ -46,7 +47,7 @@ require_capability('gradeexport/xml:view', $context); // print all the exported data here -$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $export_letters, $updatedgradesonly); +$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints); $export->print_grades(); ?> diff --git a/grade/export/xml/grade_export_xml.php b/grade/export/xml/grade_export_xml.php index aa642f168a3..d28bc37b4ab 100755 --- a/grade/export/xml/grade_export_xml.php +++ b/grade/export/xml/grade_export_xml.php @@ -74,7 +74,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 = $grade->finalgrade; // no formating for now + $gradestr = $this->format_grade($grade); // no formating for now // MDL-11669, skip exported grades or bad grades (if setting says so) if ($export_tracking) { diff --git a/grade/export/xml/index.php b/grade/export/xml/index.php index dc8d95f2c41..ee002b40e79 100755 --- a/grade/export/xml/index.php +++ b/grade/export/xml/index.php @@ -55,7 +55,8 @@ $mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing // process post information if ($data = $mform->get_data()) { - $export = new grade_export_xml($course, groups_get_course_group($course), '', false, false, $data->updatedgradesonly); + $export = new grade_export_xml($course, groups_get_course_group($course), '', false, $data->updatedgradesonly, $data->display, $data->decimals); + // print the grades on screen for feedbacks $export->process_form($data); $export->print_continue(); diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 025a285577a..42dd9f36f8e 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -69,6 +69,8 @@ $string['configenableajax'] = 'Adds a layer of AJAX functionality to the grader $string['configenableoutcomes'] = 'Support for Outcomes (also known as Competencies, Goals, Standards or Criteria) means that we can grade things using one or more scales that are tied to outcome statements. Enabling outcomes makes such special grading possible throughout the site.'; $string['configgradeboundary'] = 'A percentage boundary over which grades will be assigned a grade letter (if the Letter grade display type is used). '; $string['configgradedisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..)'; +$string['configgradeexportdisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..) during export. This can be overriden during export.'; +$string['configexportdecimalpoints'] = 'The number of decimal points to display for export. This can be overriden during export.'; $string['configgradeletter'] = 'A letter or other symbol used to represent a range of grades.'; $string['configgradeletterdefault'] = 'A letter or other symbol used to represent a range of grades. Leave this field empty to use the site default (currently $a).'; $string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a moodle site can import grades published by another site). By default only administrators may use this feature, please educate users before adding required capabilities to other roles (dangers of bookmark sharing and download accelerators, IP restrictions, etc.).'; @@ -136,8 +138,6 @@ $string['excludedhelp'] = 'If -excluded- is switched on, this grade will be excl $string['expand'] = 'Expand Category'; $string['export'] = 'Export'; $string['exportfeedback'] = 'Include feedback in export'; -$string['exportletters'] = 'Export letter grades as letters'; -$string['exportlettershelp'] = 'For grade items that use grade letters instead of values, the letters will be exported instead of the actual values.'; $string['exportplugins'] = 'Export plugins'; $string['extracredit'] = 'Extra Credit'; $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'; @@ -169,6 +169,8 @@ $string['gradedisplay'] = 'Grade display'; $string['gradedisplaytype'] = 'Grade display type'; $string['gradeexceptions'] = 'Grade Exceptions'; $string['gradeexceptionshelp'] = 'Grade Exceptions Help'; +$string['gradeexportdisplaytype'] = 'Grade export display type'; +$string['gradeexportdecimalpoints'] = 'Grade export decimal points'; $string['gradehelp'] = 'Grade Help'; $string['gradeitem'] = 'Grade item'; $string['gradeitemislocked'] = 'This activity is locked in the gradebook. Changes that are made to grades in this activity will not be copied to the gradebook until it is unlocked.';