MDL-48679 gradebook: fix grade publishing feature

This commit is contained in:
Simey Lameze 2015-02-10 12:47:34 +08:00
parent 58ccdcd2ac
commit e82aa04399
11 changed files with 166 additions and 26 deletions

View File

@ -196,6 +196,8 @@ class grade_export_form extends moodleform {
$submitstring = get_string('download');
if (empty($features['simpleui'])) {
$submitstring = get_string('submit');
} else if (!empty($CFG->gradepublishing)) {
$submitstring = get_string('export', 'grades');
}
$this->add_action_buttons(false, $submitstring);

View File

@ -390,12 +390,18 @@ abstract class grade_export {
// Implode the grade display types array as moodle_url function doesn't accept arrays.
$displaytypes = implode(',', $this->displaytype);
}
if (!empty($this->updatedgradesonly)) {
$updatedgradesonly = $this->updatedgradesonly;
} else {
$updatedgradesonly = 0;
}
$params = array('id' => $this->course->id,
'groupid' => $this->groupid,
'itemids' => $itemidsparam,
'export_letters' => $this->export_letters,
'export_feedback' => $this->export_feedback,
'updatedgradesonly' => $this->updatedgradesonly,
'updatedgradesonly' => $updatedgradesonly,
'decimalpoints' => $this->decimalpoints,
'export_onlyactive' => $this->onlyactive,
'usercustomfields' => $this->usercustomfields,

View File

@ -17,8 +17,16 @@
define('NO_MOODLE_COOKIES', true); // session not used here
require_once '../../../config.php';
require_once($CFG->dirroot.'/grade/export/ods/grade_export_ods.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$itemids = required_param('itemids', PARAM_RAW);
$exportfeedback = optional_param('export_feedback', 0, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_RAW);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
$id = required_param('id', PARAM_INT); // course id
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
}
@ -30,9 +38,19 @@ if (empty($CFG->gradepublishing)) {
}
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context);
require_capability('gradeexport/ods:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
if (!groups_group_visible($groupid, $COURSE)) {
print_error('cannotaccessgroup', 'grades');
}
// Get all url parameters and create an object to simulate a form submission.
$formdata = grade_export::export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype,
$decimalpoints);
$export = new grade_export_ods($course, $groupid, $formdata);
$export->print_grades();

View File

@ -20,6 +20,7 @@ require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_ods.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/ods/export.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -32,6 +33,13 @@ $groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context);
// We need to call this method here before any output otherwise the menu won't display.
// If you use this method without this check, will break the direct grade exporting (without publishing).
$key = optional_param('key', '', PARAM_RAW);
if (!empty($CFG->gradepublishing) && !empty($key)) {
print_grade_page_head($COURSE->id, 'export', 'ods', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_ods'));
}
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (!groups_is_member($groupid, $USER->id)) {
print_error('cannotaccessgroup', 'grades');
@ -39,9 +47,16 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => true));
$data = $mform->get_data();
// print all the exported data here
$export = new grade_export_ods($course, $groupid, $data);
$export->print_grades();
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
if (!empty($CFG->gradepublishing) && !empty($key)) {
groups_print_course_menu($course, 'index.php?id='.$id);
echo $export->get_grade_publishing_url();
echo $OUTPUT->footer();
} else {
$export->print_grades();
}

View File

@ -17,8 +17,17 @@
define('NO_MOODLE_COOKIES', true); // session not used here
require_once '../../../config.php';
require_once($CFG->dirroot.'/grade/export/txt/grade_export_txt.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$itemids = required_param('itemids', PARAM_RAW);
$exportfeedback = optional_param('export_feedback', 0, PARAM_BOOL);
$separator = optional_param('separator', 'comma', PARAM_ALPHA);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_RAW);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
$id = required_param('id', PARAM_INT); // course id
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
}
@ -30,9 +39,19 @@ if (empty($CFG->gradepublishing)) {
}
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:publish', $context);
require_capability('gradeexport/txt:view', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
if (!groups_group_visible($groupid, $COURSE)) {
print_error('cannotaccessgroup', 'grades');
}
// Get all url parameters and create an object to simulate a form submission.
$formdata = grade_export::export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype,
$decimalpoints, null, $separator);
$export = new grade_export_txt($course, $groupid, $formdata);
$export->print_grades();

View File

@ -20,6 +20,7 @@ require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_txt.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/txt/export.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -32,6 +33,13 @@ $groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context);
// We need to call this method here before any print otherwise the menu won't display.
// If you use this method without this check, will break the direct grade exporting (without publishing).
$key = optional_param('key', '', PARAM_RAW);
if (!empty($CFG->gradepublishing) && !empty($key)) {
print_grade_page_head($COURSE->id, 'export', 'txt', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'));
}
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (!groups_is_member($groupid, $USER->id)) {
print_error('cannotaccessgroup', 'grades');
@ -46,8 +54,15 @@ $params = array(
);
$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();
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
if (!empty($CFG->gradepublishing) && !empty($key)) {
groups_print_course_menu($course, 'index.php?id='.$id);
echo $export->get_grade_publishing_url();
echo $OUTPUT->footer();
} else {
$export->print_grades();
}

View File

@ -17,8 +17,16 @@
define('NO_MOODLE_COOKIES', true); // session not used here
require_once '../../../config.php';
require_once($CFG->dirroot.'/grade/export/xls/grade_export_xls.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$itemids = required_param('itemids', PARAM_RAW);
$exportfeedback = optional_param('export_feedback', 0, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_RAW);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
$id = required_param('id', PARAM_INT); // course id
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
}
@ -30,9 +38,19 @@ if (empty($CFG->gradepublishing)) {
}
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context);
require_capability('gradeexport/xls:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
if (!groups_group_visible($groupid, $COURSE)) {
print_error('cannotaccessgroup', 'grades');
}
// Get all url parameters and create an object to simulate a form submission.
$formdata = grade_export::export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype,
$decimalpoints);
$export = new grade_export_xls($course, $groupid, $formdata);
$export->print_grades();

View File

@ -20,6 +20,7 @@ require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_xls.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/xls/export.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -32,6 +33,13 @@ $groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context);
// We need to call this method here before any print otherwise the menu won't display.
// If you use this method without this check, will break the direct grade exporting (without publishing).
$key = optional_param('key', '', PARAM_RAW);
if (!empty($CFG->gradepublishing) && !empty($key)) {
print_grade_page_head($COURSE->id, 'export', 'xls', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xls'));
}
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (!groups_is_member($groupid, $USER->id)) {
print_error('cannotaccessgroup', 'grades');
@ -39,9 +47,14 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
}
$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => true));
$formdata = $mform->get_data();
// print all the exported data here
$export = new grade_export_xls($course, $groupid, $formdata);
$export->print_grades();
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
if (!empty($CFG->gradepublishing) && !empty($key)) {
groups_print_course_menu($course, 'index.php?id='.$id);
echo $export->get_grade_publishing_url();
echo $OUTPUT->footer();
} else {
$export->print_grades();
}

View File

@ -17,8 +17,17 @@
define('NO_MOODLE_COOKIES', true); // session not used here
require_once '../../../config.php';
require_once($CFG->dirroot.'/grade/export/xml/grade_export_xml.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$itemids = required_param('itemids', PARAM_RAW);
$exportfeedback = optional_param('export_feedback', 0, PARAM_BOOL);
$updatedgradesonly = optional_param('updatedgradesonly', false, PARAM_BOOL);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_RAW);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
$id = required_param('id', PARAM_INT); // course id
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
}
@ -30,9 +39,19 @@ if (empty($CFG->gradepublishing)) {
}
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:publish', $context);
require_capability('gradeexport/xml:view', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
if (!groups_group_visible($groupid, $COURSE)) {
print_error('cannotaccessgroup', 'grades');
}
// Get all url parameters and create an object to simulate a form submission.
$formdata = grade_export::export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype,
$decimalpoints, $updatedgradesonly, null);
$export = new grade_export_xml($course, $groupid, $formdata);
$export->print_grades();

View File

@ -20,6 +20,7 @@ require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_xml.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/xml/export.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
@ -32,17 +33,30 @@ $groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:view', $context);
// We need to call this method here before any print otherwise the menu won't display.
// If you use this method without this check, will break the direct grade exporting (without publishing).
$key = optional_param('key', '', PARAM_RAW);
if (!empty($CFG->gradepublishing) && !empty($key)) {
print_grade_page_head($COURSE->id, 'export', 'xml', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xml'));
}
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (!groups_is_member($groupid, $USER->id)) {
print_error('cannotaccessgroup', 'grades');
}
}
$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => false,
'idnumberrequired' => true));
'idnumberrequired' => true, 'updategradesonly' => true));
$formdata = $mform->get_data();
// print all the exported data here
$export = new grade_export_xml($course, $groupid, $formdata);
$export->print_grades();
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
if (!empty($CFG->gradepublishing) && !empty($key)) {
groups_print_course_menu($course, 'index.php?id='.$id);
echo $export->get_grade_publishing_url();
echo $OUTPUT->footer();
} else {
$export->print_grades();
}

View File

@ -305,6 +305,7 @@ $string['gradepointmax_validateerror'] = 'This setting must be an integer betwee
$string['gradepreferences'] = 'Grade preferences';
$string['gradepreferenceshelp'] = 'Grade preferences Help';
$string['gradepublishing'] = 'Enable publishing';
$string['gradepublishinglink'] = 'Download: {$a}';
$string['gradepublishing_help'] = '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.).';
$string['gradereport'] = 'Grade report';
$string['graderreport'] = 'Grader report';