Merge branch 'MDL-46548-master' of git://github.com/damyon/moodle

This commit is contained in:
Dan Poltawski
2014-08-05 19:24:32 +01:00
18 changed files with 314 additions and 165 deletions
+63 -37
View File
@@ -25,6 +25,8 @@ class grade_export_form extends moodleform {
function definition() {
global $CFG, $COURSE, $USER, $DB;
$isdeprecatedui = false;
$mform =& $this->_form;
if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
$features = $this->_customdata;
@@ -32,7 +34,52 @@ class grade_export_form extends moodleform {
$features = array();
}
$mform->addElement('header', 'options', get_string('options', 'grades'));
if (empty($features['simpleui'])) {
debugging('Grade export plugin needs updating to support one step exports.', DEBUG_DEVELOPER);
}
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
$mform->setExpanded('gradeitems', true);
if (!empty($features['idnumberrequired'])) {
$mform->addElement('static', 'idnumberwarning', get_string('useridnumberwarning', 'grades'));
}
$switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
// Grab the grade_seq for this course
$gseq = new grade_seq($COURSE->id, $switch);
if ($grade_items = $gseq->items) {
$needs_multiselect = false;
$canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
foreach ($grade_items as $grade_item) {
// Is the grade_item hidden? If so, can the user see hidden grade_items?
if ($grade_item->is_hidden() && !$canviewhidden) {
continue;
}
if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
$mform->hardFreeze('itemids['.$grade_item->id.']');
} else {
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
$mform->setDefault('itemids['.$grade_item->id.']', 1);
$needs_multiselect = true;
}
}
if ($needs_multiselect) {
$this->add_checkbox_controller(1, null, null, 1); // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
}
}
$mform->addElement('header', 'options', get_string('exportformatoptions', 'grades'));
if (!empty($features['simpleui'])) {
$mform->setExpanded('options', false);
}
$mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
$mform->setDefault('export_feedback', 0);
@@ -48,8 +95,12 @@ class grade_export_form extends moodleform {
$mform->setConstant('export_onlyactive', 1);
}
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
if (empty($features['simpleui'])) {
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
}
if (!empty($features['updategradesonly'])) {
$mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
@@ -93,7 +144,10 @@ class grade_export_form extends moodleform {
}
if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
$mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
$mform->addElement('header', 'publishing', get_string('publishingoptions', 'grades'));
if (!empty($features['simpleui'])) {
$mform->setExpanded('publishing', false);
}
$options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
$keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
array($COURSE->id, $USER->id));
@@ -121,42 +175,14 @@ class grade_export_form extends moodleform {
$mform->disabledIf('validuntil', 'key', 'noteq', 1);
}
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
$switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
// Grab the grade_seq for this course
$gseq = new grade_seq($COURSE->id, $switch);
if ($grade_items = $gseq->items) {
$needs_multiselect = false;
$canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
foreach ($grade_items as $grade_item) {
// Is the grade_item hidden? If so, can the user see hidden grade_items?
if ($grade_item->is_hidden() && !$canviewhidden) {
continue;
}
if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
$mform->hardFreeze('itemids['.$grade_item->id.']');
} else {
$mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
$mform->setDefault('itemids['.$grade_item->id.']', 1);
$needs_multiselect = true;
}
}
if ($needs_multiselect) {
$this->add_checkbox_controller(1, null, null, 1); // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
}
}
$mform->addElement('hidden', 'id', $COURSE->id);
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(false, get_string('submit'));
$submitstring = get_string('download');
if (empty($features['simpleui'])) {
$submitstring = get_string('submit');
}
$this->add_action_buttons(false, $submitstring);
}
}
+64 -13
View File
@@ -31,7 +31,6 @@ abstract class grade_export {
public $course; // course object
public $columns; // array of grade_items selected for export
public $previewrows; // number of rows in preview
public $export_letters; // export letters
public $export_feedback; // export feedback
public $userkey; // export using private user key
@@ -43,24 +42,61 @@ abstract class grade_export {
public $usercustomfields; // include users custom fields
/**
* Constructor should set up all the private variables ready to be pulled
* @deprecated since Moodle 2.8
* @var $previewrows Number of rows in preview.
*/
public $previewrows;
/**
* Constructor should set up all the private variables ready to be pulled.
*
* This constructor used to accept the individual parameters as separate arguments, in
* 2.8 this was simplified to just accept the data from the moodle form.
*
* @access public
* @param object $course
* @param int $groupid id of selected group, 0 means all
* @param string $itemlist comma separated list of item ids, empty means all
* @param boolean $export_feedback
* @param boolean $updatedgradesonly
* @param string $displaytype
* @param int $decimalpoints
* @param boolean $onlyactive
* @param boolean $usercustomfields include user custom field in export
* @param int $groupid
* @param stdClass|null $formdata
* @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, $onlyactive = false, $usercustomfields = false) {
public function __construct($course, $groupid, $formdata) {
if (func_num_args() != 3 || ($formdata != null && get_class($formdata) != "stdClass")) {
$args = func_get_args();
return call_user_func_array(array($this, "deprecated_constructor"), $args);
}
$this->course = $course;
$this->groupid = $groupid;
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id));
$this->process_form($formdata);
}
/**
* Old deprecated constructor.
*
* This deprecated constructor accepts the individual parameters as separate arguments, in
* 2.8 this was simplified to just accept the data from the moodle form.
*
* @deprecated since 2.8 MDL-46548. Instead call the shortened constructor which accepts the data
* directly from the grade_export_form.
*/
protected function deprecated_constructor($course,
$groupid=0,
$itemlist='',
$export_feedback=false,
$updatedgradesonly = false,
$displaytype = GRADE_DISPLAY_TYPE_REAL,
$decimalpoints = 2,
$onlyactive = false,
$usercustomfields = false) {
debugging('Many argument constructor for class "grade_export" is deprecated. Call the 3 argument version instead.', DEBUG_DEVELOPER);
$this->course = $course;
$this->groupid = $groupid;
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id));
//Populating the columns here is required by /grade/export/(whatever)/export.php
//however index.php, when the form is submitted, will construct the collection here
//with an empty $itemlist then reconstruct it in process_form() using $formdata
@@ -126,6 +162,10 @@ abstract class grade_export {
$this->userkey = $formdata->key;
}
if (isset($formdata->decimals)) {
$this->decimalpoints = $formdata->decimals;
}
if (isset($formdata->export_letters)) {
$this->export_letters = $formdata->export_letters;
}
@@ -209,10 +249,13 @@ abstract class grade_export {
/**
* Prints preview of exported grades on screen as a feedback mechanism
* @param bool $require_user_idnumber true means skip users without idnumber
* @deprecated since 2.8 MDL-46548. Previews are not useful on export.
*/
public function display_preview($require_user_idnumber=false) {
global $OUTPUT;
debugging('function grade_export::display_preview is deprecated.', DEBUG_DEVELOPER);
$userprofilefields = grade_helper::get_user_profile_fields($this->course->id, $this->usercustomfields);
$formatoptions = new stdClass();
$formatoptions->para = false;
@@ -327,19 +370,25 @@ abstract class grade_export {
/**
* Either prints a "Export" box, which will redirect the user to the download page,
* or prints the URL for the published data.
*
* @deprecated since 2.8 MDL-46548. Call get_export_url and set the
* action of the grade_export_form instead.
* @return void
*/
public function print_continue() {
global $CFG, $OUTPUT;
debugging('function grade_export::print_continue is deprecated.', DEBUG_DEVELOPER);
$params = $this->get_export_params();
echo $OUTPUT->heading(get_string('export', 'grades'));
echo $OUTPUT->container_start('gradeexportlink');
if (!$this->userkey) { // this button should trigger a download prompt
echo $OUTPUT->single_button(new moodle_url('/grade/export/'.$this->plugin.'/export.php', $params), get_string('download', 'admin'));
if (!$this->userkey) {
// This button should trigger a download prompt.
$url = new moodle_url('/grade/export/'.$this->plugin.'/export.php', $params);
echo $OUTPUT->single_button($url, get_string('download', 'admin'));
} else {
$paramstr = '';
@@ -354,6 +403,8 @@ abstract class grade_export {
echo get_string('download', 'admin').': ' . html_writer::link($link, $link);
}
echo $OUTPUT->container_end();
return;
}
}
+4 -8
View File
@@ -20,13 +20,6 @@ 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);
$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');
@@ -34,6 +27,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
require_login($course);
$context = context_course::instance($id);
$groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context);
@@ -43,9 +37,11 @@ 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));
$data = $mform->get_data();
// print all the exported data here
$export = new grade_export_ods($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive, true);
$export = new grade_export_ods($course, $groupid, $data);
$export->print_grades();
+12 -16
View File
@@ -40,29 +40,25 @@ if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/ods:publish', $context);
}
$mform = new grade_export_form(null, array('publishing' => true));
$actionurl = new moodle_url('/grade/export/ods/export.php');
$formoptions = array(
'publishing' => true,
'simpleui' => true
);
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$mform = new grade_export_form($actionurl, $formoptions);
$groupmode = groups_get_course_groupmode($course); // Groups are being used.
$currentgroup = groups_get_course_group($course, true);
if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/site:accessallgroups', $context)) {
if (($groupmode == SEPARATEGROUPS) &&
(!$currentgroup) &&
(!has_capability('moodle/site:accessallgroups', $context))) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
die;
}
// process post information
if ($data = $mform->get_data()) {
$onlyactive = $data->export_onlyactive || !has_capability('moodle/course:viewsuspendedusers', $context);
$export = new grade_export_ods($course, $currentgroup, '', false, false, $data->display, $data->decimals, $onlyactive, true);
// print the grades on screen for feedbacks
$export->process_form($data);
$export->print_continue();
$export->display_preview();
echo $OUTPUT->footer();
exit;
}
groups_print_course_menu($course, 'index.php?id='.$id);
echo '<div class="clearer"></div>';
+11 -11
View File
@@ -20,14 +20,6 @@ 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);
$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);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@@ -35,6 +27,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
require_login($course);
$context = context_course::instance($id);
$groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context);
@@ -45,8 +38,15 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
}
// print all the exported data here
$export = new grade_export_txt($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $separator, $onlyactive, true);
$params = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true
);
$mform = new grade_export_form(null, $params);
$data = $mform->get_data();
// Print all the exported data here.
$export = new grade_export_txt($course, $groupid, $data);
$export->print_grades();
+4 -10
View File
@@ -28,17 +28,11 @@ class grade_export_txt extends grade_export {
* Constructor should set up all the private variables ready to be pulled
* @param object $course
* @param int $groupid id of selected group, 0 means all
* @param string $itemlist comma separated list of item ids, empty means all
* @param boolean $export_feedback
* @param boolean $updatedgradesonly
* @param string $displaytype
* @param int $decimalpoints
* @param boolean $onlyactive
* @param boolean $usercustomfields include user custom field in export
* @param stdClass $formdata The validated data from the grade export form.
*/
public function __construct($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator = 'comma', $onlyactive = false, $usercustomfields = false) {
parent::__construct($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive, $usercustomfields);
$this->separator = $separator;
public function __construct($course, $groupid, $formdata) {
parent::__construct($course, $groupid, $formdata);
$this->separator = $formdata->separator;
}
public function get_export_params() {
+13 -17
View File
@@ -40,30 +40,26 @@ if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context);
}
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => true));
$actionurl = new moodle_url('/grade/export/txt/export.php');
$formoptions = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true
);
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$mform = new grade_export_form($actionurl, $formoptions);
$groupmode = groups_get_course_groupmode($course); // Groups are being used.
$currentgroup = groups_get_course_group($course, true);
if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/site:accessallgroups', $context)) {
if (($groupmode == SEPARATEGROUPS) &&
(!$currentgroup) &&
(!has_capability('moodle/site:accessallgroups', $context))) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
die;
}
// process post information
if ($data = $mform->get_data()) {
$onlyactive = $data->export_onlyactive || !has_capability('moodle/course:viewsuspendedusers', $context);
$export = new grade_export_txt($course, $currentgroup, '', false, false, $data->display, $data->decimals, $data->separator, $onlyactive, true);
// print the grades on screen for feedback
$export->process_form($data);
$export->print_continue();
$export->display_preview();
echo $OUTPUT->footer();
exit;
}
groups_print_course_menu($course, 'index.php?id='.$id);
echo '<div class="clearer"></div>';
@@ -0,0 +1,53 @@
@gradeexport @gradeexport_txt
Feature: I need to export grades as text
In order to easily review marks
As a teacher
I need to have a export grades as text
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment name |
| Description | Submit your online text |
| assignsubmission_onlinetext_enabled | 1 |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Test assignment name"
When I press "Add submission"
And I set the following fields to these values:
| Online text | This is a submission |
And I press "Save changes"
Then I should see "Submitted for grading"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment name"
And I press "Update"
@javascript
Scenario: Export grades as text
When I set the field "Grade report" to "Plain text file"
And I expand all fieldsets
And I click on "Course total" "checkbox"
And I set the field "Grade export decimal points" to "1"
And I press "Download"
Then I should see "Student,1"
And I should see "80.0"
And I should not see "Course total"
And I should not see "80.00"
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /grade/export/* - plugins,
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.
+4 -8
View File
@@ -20,13 +20,6 @@ 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);
$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');
@@ -34,6 +27,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
require_login($course);
$context = context_course::instance($id);
$groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context);
@@ -43,9 +37,11 @@ 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));
$formdata = $mform->get_data();
// print all the exported data here
$export = new grade_export_xls($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive, true);
$export = new grade_export_xls($course, $groupid, $formdata);
$export->print_grades();
+7 -14
View File
@@ -40,7 +40,13 @@ if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/xls:publish', $context);
}
$mform = new grade_export_form(null, array('publishing' => true));
$actionurl = new moodle_url('/grade/export/xls/export.php');
$formoptions = array(
'publishing' => true,
'simpleui' => true
);
$mform = new grade_export_form($actionurl, $formoptions);
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$currentgroup = groups_get_course_group($course, true);
@@ -50,19 +56,6 @@ if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/
die;
}
// process post information
if ($data = $mform->get_data()) {
$onlyactive = $data->export_onlyactive || !has_capability('moodle/course:viewsuspendedusers', $context);
$export = new grade_export_xls($course, $currentgroup, '', false, false, $data->display, $data->decimals, $onlyactive, true);
// print the grades on screen for feedbacks
$export->process_form($data);
$export->print_continue();
$export->display_preview();
echo $OUTPUT->footer();
exit;
}
groups_print_course_menu($course, 'index.php?id='.$id);
echo '<div class="clearer"></div>';
+4 -8
View File
@@ -20,13 +20,6 @@ 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);
$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');
@@ -34,6 +27,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
require_login($course);
$context = context_course::instance($id);
$groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:view', $context);
@@ -43,9 +37,11 @@ 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));
$formdata = $mform->get_data();
// print all the exported data here
$export = new grade_export_xml($course, $groupid, $itemids, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints, $onlyactive);
$export = new grade_export_xml($course, $groupid, $formdata);
$export->print_grades();
+7 -2
View File
@@ -101,8 +101,13 @@ class grade_export_xml extends grade_export {
$gui->close();
$geub->close();
@header("Content-type: text/xml; charset=UTF-8");
send_temp_file($tempfilename, $downloadfilename, false);
if (defined('BEHAT_SITE_RUNNING')) {
// If behat is running, we cannot test the output if we force a file download.
include($tempfilename);
} else {
@header("Content-type: text/xml; charset=UTF-8");
send_temp_file($tempfilename, $downloadfilename, false);
}
}
}
+14 -20
View File
@@ -40,33 +40,27 @@ if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/xml:publish', $context);
}
//'idnumberrequired'=>true excludes grade items that dont have an ID to use during import
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing'=>true, 'updategradesonly'=>true));
$actionurl = new moodle_url('/grade/export/xml/export.php');
// The option 'idnumberrequired' excludes grade items that dont have an ID to use during import.
$formoptions = array(
'idnumberrequired' => true,
'updategradesonly' => true,
'publishing' => true,
'simpleui' => true
);
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$mform = new grade_export_form($actionurl, $formoptions);
$groupmode = groups_get_course_groupmode($course); // Groups are being used.
$currentgroup = groups_get_course_group($course, true);
if ($groupmode == SEPARATEGROUPS and !$currentgroup and !has_capability('moodle/site:accessallgroups', $context)) {
if (($groupmode == SEPARATEGROUPS) &&
(!$currentgroup) &&
(!has_capability('moodle/site:accessallgroups', $context))) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
die;
}
// process post information
if ($data = $mform->get_data()) {
$onlyactive = $data->export_onlyactive || !has_capability('moodle/course:viewsuspendedusers', $context);
$export = new grade_export_xml($course, $currentgroup, '', false, $data->updatedgradesonly, $data->display, $data->decimals, $onlyactive);
// print the grades on screen for feedbacks
$export->process_form($data);
$export->print_continue();
$export->display_preview(true); //true == skip users without idnumber as they cannot be identified when importing
echo $OUTPUT->container(get_string('useridnumberwarning','gradeexport_xml'), 'useridnumberwarning mdl-align');
echo $OUTPUT->footer();
exit;
}
groups_print_course_menu($course, 'index.php?id='.$id);
echo '<div class="clearer"></div>';
@@ -26,4 +26,3 @@
$string['pluginname'] = 'XML file';
$string['xml:publish'] = 'Publish XML grade export';
$string['xml:view'] = 'Use XML grade export';
$string['useridnumberwarning'] = 'User\'s without an ID number are excluded from the XML export as they cannot be imported';
@@ -0,0 +1,38 @@
@gradeexport @gradeexport_xml
Feature: I need to export grades as xml
In order to easily review marks
As a teacher
I need to have a export grades as xml
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | t1 |
| student1 | Student | 1 | student1@asd.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | intro |
| assign | C1 | a1 | Test assignment name | Submit something! |
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment name"
And I press "Update"
@javascript
Scenario: Export grades as text
When I navigate to "XML file" node in "Grade administration > Export"
And I expand all fieldsets
And I set the field "Grade export decimal points" to "1"
And I press "Download"
Then I should see "s1"
And I should see "a1"
And I should see "80.0"
And I should not see "80.00"
+4
View File
@@ -194,6 +194,7 @@ $string['expand'] = 'Expand category';
$string['export'] = 'Export';
$string['exportalloutcomes'] = 'Export all outcomes';
$string['exportfeedback'] = 'Include feedback in export';
$string['exportformatoptions'] = 'Export format options';
$string['exportplugins'] = 'Export plugins';
$string['exportsettings'] = 'Export settings';
$string['exportonlyactive'] = 'Exclude suspended users';
@@ -526,6 +527,7 @@ $string['previewrows'] = 'Preview rows';
$string['profilereport'] = 'User profile report';
$string['profilereport_help'] = 'Grade report used on user profile page.';
$string['publishing'] = 'Publishing';
$string['publishingoptions'] = 'Grade publishing options';
$string['quickfeedback'] = 'Quick feedback';
$string['quickgrading'] = 'Quick grading';
$string['quickgrading_help'] = 'If enabled, when editing is turned on, a text input box appears for each grade, allowing many grades to be edited at the same time. Changes are saved and highlighted when the update button is clicked.
@@ -543,6 +545,7 @@ $string['realletter'] = 'Real (letter)';
$string['realpercentage'] = 'Real (percentage)';
$string['recovergradesdefault'] = 'Recover grades default';
$string['recovergradesdefault_help'] = 'By default recover old grades when re-enrolling a user in a course.';
$string['refreshpreview'] = 'Refresh preview';
$string['regradeanyway'] = 'Regrade anyway';
$string['removeallcoursegrades'] = 'Delete all grades';
$string['removeallcourseitems'] = 'Delete all items and categories';
@@ -680,6 +683,7 @@ $string['usepercent'] = 'Use percent';
$string['user'] = 'User';
$string['usergrade'] = 'User {$a->fullname} ({$a->useridnumber}) on item {$a->gradeidnumber}';
$string['userid'] = 'User ID';
$string['useridnumberwarning'] = 'Users without an ID number are excluded from the export as they cannot be imported';
$string['usermappingerror'] = 'User mapping error: Could not find user with {$a->field} of "{$a->value}".';
$string['usermappingerrorusernotfound'] = 'User mapping error. Could not find user.';
$string['usermappingerrorcurrentgroup'] = 'User is not a member of current group.';
+5
View File
@@ -471,6 +471,11 @@ class csv_export_writer {
*/
protected function send_header() {
global $CFG;
if (defined('BEHAT_SITE_RUNNING')) {
// For text based formats - we cannot test the output with behat if we force a file download.
return;
}
if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431
header('Cache-Control: max-age=10');
header('Pragma: ');