mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
regular whitespace cleanup in grade code
This commit is contained in:
parent
e1d2692a73
commit
ba74762bda
21 changed files with 297 additions and 297 deletions
|
@ -16,7 +16,7 @@ class grade_export_form extends moodleform {
|
|||
$mform->addElement($element);
|
||||
}
|
||||
}
|
||||
$this->add_action_buttons(false, get_string('submit'));
|
||||
$this->add_action_buttons(false, get_string('submit'));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -42,7 +42,7 @@ function print_gradeitem_selections($id, $params = NULL) {
|
|||
* Base export class
|
||||
*/
|
||||
class grade_export {
|
||||
|
||||
|
||||
var $format = ''; // export format
|
||||
var $id; // course id
|
||||
var $itemids; // comma separated grade_item ids;
|
||||
|
@ -51,34 +51,34 @@ class grade_export {
|
|||
var $comments = array(); // Collect all comments for each grade
|
||||
var $totals = array(); // Collect all totals in this array
|
||||
var $columns = array(); // Accumulate column names in this array.
|
||||
var $columnhtml = array(); // Accumulate column html in this array.
|
||||
var $columnhtml = array(); // Accumulate column html in this array.
|
||||
var $columnidnumbers = array(); // Collect all gradeitem id numbers
|
||||
var $students = array();
|
||||
var $course; // course
|
||||
|
||||
|
||||
// common strings
|
||||
var $strgrades;
|
||||
var $strgrade;
|
||||
|
||||
var $strgrades;
|
||||
var $strgrade;
|
||||
|
||||
/**
|
||||
* Constructor should set up all the private variables ready to be pulled
|
||||
* @input int id - course id
|
||||
* @input string itemids - comma separated value of itemids to process for this export
|
||||
*/
|
||||
function grade_export($id, $itemids = '') {
|
||||
|
||||
|
||||
$this->strgrades = get_string("grades");
|
||||
$this->strgrade = get_string("grade");
|
||||
$this->itemids = $itemids;
|
||||
|
||||
$strmax = get_string("maximumshort");
|
||||
|
||||
|
||||
$strmax = get_string("maximumshort");
|
||||
|
||||
if (! $course = get_record("course", "id", $id)) {
|
||||
error("Course ID was incorrect");
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_COURSE, $id);
|
||||
require_capability('moodle/course:viewcoursegrades', $context);
|
||||
|
||||
|
||||
$this->id = $id;
|
||||
$this->course = $course;
|
||||
|
||||
|
@ -88,7 +88,7 @@ class grade_export {
|
|||
|
||||
/// Check to see if groups are being used in this course
|
||||
if ($groupmode = groupmode($course)) { // Groups are being used
|
||||
|
||||
|
||||
if (isset($_GET['group'])) {
|
||||
$changegroup = $_GET['group']; /// 0 or higher
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ class grade_export {
|
|||
}
|
||||
|
||||
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
||||
|
||||
|
||||
} else {
|
||||
$currentgroup = false;
|
||||
}
|
||||
|
@ -119,44 +119,44 @@ class grade_export {
|
|||
// if grade_item ids are specified
|
||||
if ($itemids) {
|
||||
foreach ($itemids as $iid) {
|
||||
|
||||
|
||||
if ($iid) {
|
||||
$params->id = clean_param($iid, PARAM_INT);
|
||||
$gradeitems[] = new grade_item($params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// else we get all items for this course
|
||||
$gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
|
||||
}
|
||||
|
||||
|
||||
if ($gradeitems) {
|
||||
foreach ($gradeitems as $gradeitem) {
|
||||
|
||||
|
||||
// load as an array of grade_final objects
|
||||
if ($itemgrades = $gradeitem -> get_final()) {
|
||||
|
||||
if ($itemgrades = $gradeitem -> get_final()) {
|
||||
|
||||
$this->columns[$gradeitem->id] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";
|
||||
|
||||
$this->columnidnumbers[$gradeitem->id] = $gradeitem->idnumber; // this might be needed for some export plugins
|
||||
|
||||
|
||||
$this->columnidnumbers[$gradeitem->id] = $gradeitem->idnumber; // this might be needed for some export plugins
|
||||
|
||||
if (!empty($gradeitem->grademax)) {
|
||||
$maxgrade = "$strmax: $gradeitem->grademax";
|
||||
} else {
|
||||
$maxgrade = "";
|
||||
}
|
||||
|
||||
if (!empty($this->students)) {
|
||||
}
|
||||
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
unset($studentgrade);
|
||||
// add support for comment here MDL-9634
|
||||
|
||||
|
||||
if (!empty($itemgrades[$student->id])) {
|
||||
$studentgrade = $itemgrades[$student->id];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($studentgrade->finalgrade)) {
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
||||
} else {
|
||||
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
|
||||
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
||||
|
@ -166,8 +166,8 @@ class grade_export {
|
|||
} else {
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
||||
}
|
||||
|
||||
if (!empty($comment)) {
|
||||
|
||||
if (!empty($comment)) {
|
||||
// load comments here
|
||||
if ($studentgrade) {
|
||||
$studentgrade->load_text();
|
||||
|
@ -176,20 +176,20 @@ class grade_export {
|
|||
$this->comments[$student->id][$gradeitem->id] = $comment;
|
||||
}
|
||||
} else {
|
||||
$this->comments[$student->id][$gradeitem->id] = '';
|
||||
$this->comments[$student->id][$gradeitem->id] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades() { }
|
||||
|
||||
|
||||
/**
|
||||
* Displays all the grades on screen as a feedback mechanism
|
||||
*/
|
||||
|
@ -205,34 +205,34 @@ class grade_export {
|
|||
foreach ($this->columns as $column) {
|
||||
$column = strip_tags($column);
|
||||
echo "<th>$column</th>";
|
||||
|
||||
/// add a column_feedback column
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
echo "<th>{$column}_feedback</th>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '<th>'.get_string("total")."</th>";
|
||||
echo '</tr>';
|
||||
/// Print all the lines of data.
|
||||
|
||||
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
|
||||
|
||||
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
|
||||
echo '<tr>';
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
echo "<td>$student->firstname</td><td>$student->lastname</td><td>$student->idnumber</td><td>$student->institution</td><td>$student->department</td><td>$student->email</td>";
|
||||
foreach ($studentgrades as $grade) {
|
||||
$grade = strip_tags($grade);
|
||||
echo "<td>$grade</td>";
|
||||
|
||||
echo "<td>$grade</td>";
|
||||
|
||||
if ($feedback) {
|
||||
echo '<td>'.array_shift($this->comments[$student->id]).'</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '<td>'.$this->totals[$student->id].'</td>';
|
||||
echo "</tr>";
|
||||
|
|
|
@ -3,13 +3,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
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_ods($id, $itemids);
|
||||
$export->print_grades($feedback);
|
||||
|
||||
|
||||
?>
|
|
@ -25,29 +25,29 @@
|
|||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_ods extends grade_export {
|
||||
|
||||
|
||||
var $format = 'ods'; // export format
|
||||
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot.'/lib/odslib.class.php');
|
||||
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
|
||||
/// Creating a workbook
|
||||
|
@ -56,7 +56,7 @@ class grade_export_ods extends grade_export {
|
|||
$workbook->send($downloadfilename);
|
||||
/// Adding the worksheet
|
||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||
|
||||
|
||||
/// Print names of all the fields
|
||||
$myxls->write_string(0,0,get_string("firstname"));
|
||||
$myxls->write_string(0,1,get_string("lastname"));
|
||||
|
@ -67,14 +67,14 @@ class grade_export_ods extends grade_export {
|
|||
$pos=6;
|
||||
foreach ($this->columns as $column) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||
|
||||
/// add a column_feedback column
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||
}
|
||||
}
|
||||
$myxls->write_string(0,$pos,get_string("total"));
|
||||
|
||||
|
||||
/// Print all the lines of data.
|
||||
$i = 0;
|
||||
if (!empty($this->grades)) {
|
||||
|
@ -84,7 +84,7 @@ class grade_export_ods extends grade_export {
|
|||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
}
|
||||
|
||||
|
||||
$myxls->write_string($i,0,$student->firstname);
|
||||
$myxls->write_string($i,1,$student->lastname);
|
||||
$myxls->write_string($i,2,$student->idnumber);
|
||||
|
@ -99,20 +99,20 @@ class grade_export_ods extends grade_export {
|
|||
else {
|
||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||
}
|
||||
|
||||
|
||||
// writing comment if requested
|
||||
if ($feedback) {
|
||||
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||
|
||||
|
||||
if ($export) {
|
||||
$params= new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
|
||||
$grade_grades = new grade_grades($params);
|
||||
$grade_grades->exported = time();
|
||||
// update the time stamp;
|
||||
|
@ -125,7 +125,7 @@ class grade_export_ods extends grade_export {
|
|||
|
||||
/// Close the workbook
|
||||
$workbook->close();
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,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
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
|
||||
require_login($id);
|
||||
require_capability('moodle/course:downloadallgrades', get_context_instance(CONTEXT_COURSE, $id));
|
||||
|
||||
$course = get_record('course', 'id', $id);
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
$strgrades = get_string('grades', 'grades');
|
||||
$actionstr = get_string('exportods', 'grades');
|
||||
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||
|
@ -46,15 +46,15 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
|||
} else {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
}
|
||||
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id);
|
||||
|
|
|
@ -3,14 +3,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
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_txt($id, $itemids);
|
||||
$export->set_separator(optional_param('separator'));
|
||||
$export->print_grades($feedback);
|
||||
|
||||
|
||||
?>
|
|
@ -25,22 +25,22 @@
|
|||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_txt extends grade_export {
|
||||
|
||||
|
||||
var $format = 'txt'; // export format
|
||||
var $separator = "\t"; // default separator
|
||||
|
||||
|
||||
function set_separator($separator) {
|
||||
if ($separator == 'comma') {
|
||||
$this->separator = ",";
|
||||
} else if ($separator == 'tab') {
|
||||
$this->separator = "\t";
|
||||
}
|
||||
$this->separator = "\t";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
@ -49,14 +49,14 @@ class grade_export_txt extends grade_export {
|
|||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
|
||||
/// Print header to force download
|
||||
header("Content-Type: application/download\n");
|
||||
|
||||
/// Print header to force download
|
||||
header("Content-Type: application/download\n");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades");
|
||||
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
|
||||
|
||||
|
@ -71,17 +71,17 @@ class grade_export_txt extends grade_export {
|
|||
foreach ($this->columns as $column) {
|
||||
$column = strip_tags($column);
|
||||
echo "{$this->separator}$column";
|
||||
|
||||
/// add a column_feedback column
|
||||
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
echo "{$this->separator}{$column}_feedback";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "{$this->separator}".get_string("total")."\n";
|
||||
|
||||
|
||||
/// Print all the lines of data.
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
|
||||
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
|
@ -90,12 +90,12 @@ class grade_export_txt extends grade_export {
|
|||
|
||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||
$grade = strip_tags($grade);
|
||||
echo "{$this->separator}$grade";
|
||||
|
||||
echo "{$this->separator}$grade";
|
||||
|
||||
if ($feedback) {
|
||||
echo "{$this->separator}".array_shift($this->comments[$student->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||
|
||||
|
@ -103,7 +103,7 @@ class grade_export_txt extends grade_export {
|
|||
$params = new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
|
||||
$grade_grades = new grade_grades($params);
|
||||
$grade_grades->exported = time();
|
||||
// update the time stamp;
|
||||
|
@ -113,7 +113,7 @@ class grade_export_txt extends grade_export {
|
|||
echo "{$this->separator}".$this->totals[$student->id];
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,15 @@ class grade_export_txt_form extends moodleform {
|
|||
$mform->addElement($element);
|
||||
}
|
||||
}
|
||||
|
||||
include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
|
||||
|
||||
include_once($CFG->libdir.'/pear/HTML/QuickForm/radio.php');
|
||||
$radio = array();
|
||||
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
|
||||
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
|
||||
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
|
||||
$mform->setDefault('separator', 'comma');
|
||||
$mform->setDefault('separator', 'comma');
|
||||
|
||||
$this->add_action_buttons(false, get_string('submit'));
|
||||
$this->add_action_buttons(false, get_string('submit'));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -48,13 +48,13 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
|||
} else {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
}
|
||||
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl.'&separator='.$data->separator);
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
// print the form to choose what grade_items to export
|
||||
|
|
|
@ -3,13 +3,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
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_xls($id, $itemids);
|
||||
$export->print_grades($feedback);
|
||||
|
||||
|
||||
?>
|
|
@ -25,27 +25,27 @@
|
|||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xls extends grade_export {
|
||||
|
||||
|
||||
var $format = 'xls'; // export format
|
||||
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||
|
||||
/// Calculate file name
|
||||
|
@ -56,7 +56,7 @@ class grade_export_xls extends grade_export {
|
|||
$workbook->send($downloadfilename);
|
||||
/// Adding the worksheet
|
||||
$myxls =& $workbook->add_worksheet($this->strgrades);
|
||||
|
||||
|
||||
/// Print names of all the fields
|
||||
$myxls->write_string(0,0,get_string("firstname"));
|
||||
$myxls->write_string(0,1,get_string("lastname"));
|
||||
|
@ -67,13 +67,13 @@ class grade_export_xls extends grade_export {
|
|||
$pos=6;
|
||||
foreach ($this->columns as $column) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column));
|
||||
/// add a column_feedback column
|
||||
/// add a column_feedback column
|
||||
if ($feedback) {
|
||||
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
|
||||
}
|
||||
}
|
||||
$myxls->write_string(0,$pos,get_string("total"));
|
||||
|
||||
|
||||
/// Print all the lines of data.
|
||||
$i = 0;
|
||||
if (!empty($this->grades)) {
|
||||
|
@ -83,7 +83,7 @@ class grade_export_xls extends grade_export {
|
|||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
}
|
||||
|
||||
|
||||
$myxls->write_string($i,0,$student->firstname);
|
||||
$myxls->write_string($i,1,$student->lastname);
|
||||
$myxls->write_string($i,2,$student->idnumber);
|
||||
|
@ -97,8 +97,8 @@ class grade_export_xls extends grade_export {
|
|||
}
|
||||
else {
|
||||
$myxls->write_string($i,$j++,strip_tags($grade));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// writing comment if requested
|
||||
if ($feedback) {
|
||||
$myxls->write_string($i,$j++,array_shift($this->comments[$student->id]));
|
||||
|
@ -106,12 +106,12 @@ class grade_export_xls extends grade_export {
|
|||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades object and update timestamp if CFG flag is set
|
||||
|
||||
|
||||
if ($export) {
|
||||
$params = new object();
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
|
||||
$grade_grades = new grade_grades($params);
|
||||
$grade_grades->exported = time();
|
||||
// update the time stamp;
|
||||
|
@ -124,7 +124,7 @@ class grade_export_xls extends grade_export {
|
|||
|
||||
/// Close the workbook
|
||||
$workbook->close();
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,15 +48,15 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
|||
} else {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
}
|
||||
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id);
|
||||
|
|
|
@ -3,13 +3,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
|
||||
$itemids = explode(",", required_param('itemids', PARAM_RAW));
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_xml($id, $itemids);
|
||||
$export->print_grades($feedback);
|
||||
|
||||
|
||||
?>
|
|
@ -25,14 +25,14 @@
|
|||
require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xml extends grade_export {
|
||||
|
||||
|
||||
var $format = 'xml'; // export format
|
||||
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
|
@ -40,60 +40,60 @@ class grade_export_xml extends grade_export {
|
|||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
} else {
|
||||
$export = false;
|
||||
$export = false;
|
||||
}
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml");
|
||||
|
||||
header("Content-type: text/xml; charset=UTF-8");
|
||||
header("Content-type: text/xml; charset=UTF-8");
|
||||
header("Content-Disposition: attachment; filename=\"$downloadfilename\"");
|
||||
|
||||
|
||||
/// time stamp to ensure uniqueness of batch export
|
||||
echo '<results batch="xml_export_'.time().'">';
|
||||
|
||||
|
||||
foreach ($this->columnidnumbers as $index => $idnumber) {
|
||||
|
||||
// studentgrades[] index should match with corresponding $index
|
||||
|
||||
// studentgrades[] index should match with corresponding $index
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
echo '<result>';
|
||||
|
||||
|
||||
// state can be new, or regrade
|
||||
// require comparing of timestamps in db
|
||||
|
||||
|
||||
$params = new object();
|
||||
$params->idnumber = $idnumber;
|
||||
// get the grade item
|
||||
$gradeitem = new grade_item($params);
|
||||
|
||||
|
||||
// we are trying to figure out if this is a new grade, or a regraded grade
|
||||
// only relevant if this grade for this user is already exported
|
||||
|
||||
|
||||
// get the grade_grades for this user
|
||||
$params = new object();
|
||||
$params->itemid = $gradeitem->id;
|
||||
$params->userid = $studentid;
|
||||
|
||||
|
||||
$grade_grades = new grade_grades($params);
|
||||
|
||||
|
||||
// if exported, check grade_history, if modified after export, set state to regrade
|
||||
if (!empty($grade_grades->exported)) {
|
||||
//TODO: use timemodified or something else instead
|
||||
/* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades->exported)) {
|
||||
$status = 'regrade';
|
||||
$status = 'regrade';
|
||||
} else {
|
||||
$status = 'new';
|
||||
$status = 'new';
|
||||
}*/
|
||||
} else {
|
||||
} else {
|
||||
// never exported
|
||||
$status = 'new';
|
||||
$status = 'new';
|
||||
}
|
||||
|
||||
|
||||
echo '<state>'.$status.'</state>';
|
||||
// only need id number
|
||||
echo '<assignment>'.$idnumber.'</assignment>';
|
||||
|
@ -101,7 +101,7 @@ class grade_export_xml extends grade_export {
|
|||
echo '<student>'.$studentid.'</student>';
|
||||
echo '<score>'.$studentgrades[$index].'</score>';
|
||||
if ($feedback) {
|
||||
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
|
||||
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
|
||||
}
|
||||
echo '</result>';
|
||||
|
||||
|
@ -114,7 +114,7 @@ class grade_export_xml extends grade_export {
|
|||
}
|
||||
}
|
||||
echo '</results>';
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ require_capability('moodle/course:downloadallgrades', get_context_instance(CONTE
|
|||
|
||||
$course = get_record('course', 'id', $id);
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
|
||||
$strgrades = get_string('grades', 'grades');
|
||||
$actionstr = get_string('exportxml', 'grades');
|
||||
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||
|
@ -48,12 +48,12 @@ if (($data = data_submitted()) && confirm_sesskey()) {
|
|||
} else {
|
||||
$itemidsurl = implode(",",$data->itemids);
|
||||
}
|
||||
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
|
||||
$export = new grade_export($id, $data->itemids);
|
||||
$export->display_grades($feedback);
|
||||
|
||||
|
||||
// this redirect should trigger a download prompt
|
||||
redirect('export.php?id='.$id.'&itemids='.$itemidsurl);
|
||||
exit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue