MDL-11034 Implemented the global enablepublishing and refactored the handling of userkey for each export plugin. Also added a dump.php file in each plugin directory, although this could easily be refactored into 1 file in the parent folder, pointing to each plugin's export.php file for output differences.

This commit is contained in:
nicolasconnault 2007-08-31 05:55:30 +00:00
parent 9133f939e8
commit 0e2d708efc
8 changed files with 117 additions and 101 deletions

View File

@ -40,8 +40,9 @@ class grade_export {
var $columnidnumbers = array(); // Collect all gradeitem id numbers
var $students = array();
var $course; // course
var $publish; // Whether to publish this data via URL, or dump it to browser as usual
var $userkey; // Optional MD5 string used to publish this export data via a URL
var $export_letters;
var $itemidsurl; // A string of itemids to add to the URL for the export
// common strings
var $strgrades;
@ -51,15 +52,25 @@ class grade_export {
* Constructor should set up all the private variables ready to be pulled
* @param int $courseid course id
* @param array $itemids array of grade item ids, empty means all
* @param boolean $export_letters Whether to export letter grade_items as literal letters, or as numerical values
* @param boolean $publish published using private user key
* @param stdClass $formdata Optional object of formdata.
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
*/
function grade_export($courseid, $itemids=null, $export_letters=false, $publish=false) {
global $CFG;
function grade_export($courseid, $itemids=null, $formdata=null) {
global $CFG, $USER, $COURSE;
$this->export_letters = false;
if (isset($formdata->export_letters)) {
$this->export_letters = $formdata->export_letters;
}
$this->userkey = false;
if (isset($formdata->key)) {
if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) { // Create a new key
$formdata->key = create_user_key('grade/export', $USER->id, $COURSE->id, $formdata->iprestriction, $formdata->validuntil);
}
$this->userkey = $formdata->key;
}
$this->publish = $publish;
$this->export_letters = $export_letters;
$this->strgrades = get_string("grades");
$this->strgrade = get_string("grade");
@ -121,9 +132,27 @@ class grade_export {
$this->comments[$student->id] = array(); // Collect all comments in tihs array
}
}
if (isset($formdata->itemids)) {
// Build itemidsurl for links
$itemids = array();
if ($formdata->itemids) {
foreach ($formdata->itemids as $itemid=>$selected) {
if ($selected) {
$itemids[] = $itemid;
}
}
$this->itemidsurl = implode(",", $itemids);
} else {
//error?
$this->itemidsurl = '';
}
}
}
function load_grades() {
global $CFG;
// first make sure we have all final grades
// TODO: check that no grade_item has needsupdate set
grade_regrade_final_grades($this->id);
@ -155,8 +184,7 @@ class grade_export {
$grade_item_displaytype = $report->get_pref('gradedisplaytype', $gradeitem->id);
// TODO Convert final grade to letter if export option is on, and grade_item is set to letter type MDL-10490
if ($grade_item_displaytype == GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER) {
$finalgrade = grade_grade::get_letter($letters, $finalgrade,
$gradeitem->grademin, $gradeitem->grademax);
$finalgrade = grade_grade::get_letter($letters, $finalgrade, $gradeitem->grademin, $gradeitem->grademax);
}
}
@ -169,7 +197,7 @@ class grade_export {
}
/**
* To be implemented by child classe
* To be implemented by child class
* TODO finish PHPdocs
*/
function print_grades() { }
@ -225,6 +253,31 @@ class grade_export {
}
echo '</table>';
}
/**
* Either prints a "continue" box, which will redirect the user to the download page, or prints the URL for the published data.
* @note exit() at the end of the method
* @param string $plugin Required: name of the plugin calling this method. Used for building the URL.
* @return void
*/
function print_continue($plugin) {
global $CFG;
// this redirect should trigger a download prompt
if (!$this->userkey) {
print_continue('export.php?id='.$this->id.'&amp;itemids='.$this->itemidsurl.'&amp;export_letters='.$this->export_letters);
} else {
$link = $CFG->wwwroot.'/grade/export/'.$plugin.'/dump.php?id='.$this->id.'&amp;itemids='
. $this->itemidsurl.'&amp;export_letters='.$this->export_letters.'&amp;key='.$this->userkey;
echo '<p>';
echo '<a href="'.$link.'">'.$link.'</a>';
echo '</p>';
print_footer();
}
exit();
}
}
?>

13
grade/export/ods/dump.php Normal file
View File

@ -0,0 +1,13 @@
<?php //$Id$
$nomoodlecookie = true; // session not used here
require '../../../config.php';
$id = required_param('id', PARAM_INT); // course id
require_user_key_login('grade/export', $id); // we want different keys for each course
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
?>

View File

@ -48,29 +48,14 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
print_grade_plugin_selector($id, 'export', 'ods');
$mform = new grade_export_form(null, array('publishing' => true));
$mform = new grade_export_form(null, array('publishing' => $CFG->enablepublishing));
// process post information
if ($data = $mform->get_data()) {
$itemids = array();
if ($data->itemids) {
foreach ($data->itemids as $itemid=>$selected) {
if ($selected) {
$itemids[] = $itemid;
}
}
$itemidsurl = implode(",", $itemids);
} else {
//error?
$itemidsurl = '';
}
$export = new grade_export($id, $itemids, $data->export_letters);
// print the grades on screen for feedbacks
$export = new grade_export($id, $itemids, $data);
$export->display_grades($feedback, $data->previewrows);
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters);
exit;
$export->print_continue('ods');
}
$mform->display();

13
grade/export/txt/dump.php Normal file
View File

@ -0,0 +1,13 @@
<?php //$Id$
$nomoodlecookie = true; // session not used here
require '../../../config.php';
$id = required_param('id', PARAM_INT); // course id
require_user_key_login('grade/export', $id); // we want different keys for each course
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
?>

View File

@ -48,29 +48,14 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
print_grade_plugin_selector($id, 'export', 'txt');
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => true));
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => $CFG->enablepublishing));
// process post information
if ($data = $mform->get_data()) {
$itemids = array();
if ($data->itemids) {
foreach ($data->itemids as $itemid=>$selected) {
if ($selected) {
$itemids[] = $itemid;
}
}
$itemidsurl = implode(",", $itemids);
} else {
//error?
$itemidsurl = '';
}
$export = new grade_export($id, $itemids, $data->export_letters);
// print the grades on screen for feedbacks
$export = new grade_export($id, $itemids, $data);
$export->display_grades($feedback, $data->previewrows);
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;separator='.$data->separator.'&amp;export_letters='.$data->export_letters);
exit;
$export->print_continue('txt');
}
// print the form to choose what grade_items to export

13
grade/export/xls/dump.php Normal file
View File

@ -0,0 +1,13 @@
<?php //$Id$
$nomoodlecookie = true; // session not used here
require '../../../config.php';
$id = required_param('id', PARAM_INT); // course id
require_user_key_login('grade/export', $id); // we want different keys for each course
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa
require 'export.php';
?>

View File

@ -48,29 +48,14 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
print_grade_plugin_selector($id, 'export', 'xls');
$mform = new grade_export_form();
$mform = new grade_export_form(null, array('publishing' => $CFG->enablepublishing));
// process post information
if ($data = $mform->get_data()) {
$itemids = array();
if ($data->itemids) {
foreach ($data->itemids as $itemid=>$selected) {
if ($selected) {
$itemids[] = $itemid;
}
}
$itemidsurl = implode(",", $itemids);
} else {
//error?
$itemidsurl = '';
}
$export = new grade_export($id, $itemids, $data->export_letters);
// print the grades on screen for feedbacks
$export = new grade_export($id, $itemids, $data);
$export->display_grades($feedback, $data->previewrows);
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters);
exit;
$export->print_continue('xls');
}
$mform->display();

View File

@ -48,45 +48,14 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course-
print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
print_grade_plugin_selector($id, 'export', 'xml');
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing'=>true));
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing'=>$CFG->enablepublishing));
// process post information
if ($data = $mform->get_data()) {
$itemids = array();
if ($data->itemids) {
foreach ($data->itemids as $itemid=>$selected) {
if ($selected) {
$itemids[] = $itemid;
}
}
$itemidsurl = implode(",", $itemids);
} else {
//error?
$itemidsurl = '';
}
// print the grades on screen for feedbacks
$export = new grade_export($id, $itemids, $data->export_letters, !empty($data->key));
$export = new grade_export($id, $itemids, $data);
$export->display_grades($feedback, $data->previewrows);
// this redirect should trigger a download prompt
if (empty($data->key)) {
print_continue('export.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters);
} else {
if ($data->key == 1) {
$data->key = create_user_key('grade/export', $USER->id, $COURSE->id, $data->iprestriction, $data->validuntil);
}
$link = $CFG->wwwroot.'/grade/export/xml/dump.php?id='.$id.'&amp;itemids='.$itemidsurl.'&amp;export_letters='.$data->export_letters.'&amp;key='.$data->key;
echo '<p>';
echo '<a href="'.$link.'">'.$link.'</a>';
echo '</p>';
print_footer();
}
exit;
$export->print_continue('xml');
}
$mform->display();