grade export plugins

This commit is contained in:
toyomoyo
2007-05-10 09:29:58 +00:00
parent f744267a28
commit a216f661d6
5 changed files with 137 additions and 6 deletions
+2
View File
@@ -34,6 +34,7 @@ class grade_export {
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 $columnidnumbers = array(); // Collect all gradeitem id numbers
var $course; // course
// common strings
@@ -109,6 +110,7 @@ class grade_export {
foreach ($gradeitems as $gradeitem) {
$this->columns[] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->maxgrade";
$this->columnidnumbers[] = $gradeitem->idnumber; // this might be needed for some export plugins
if (!empty($gradeitem->maxgrade)) {
$maxgrade = "$strmax: $gradeitem->maxgrade";
+11 -1
View File
@@ -31,7 +31,7 @@ class grade_export_ods extends grade_export {
/**
* To be implemented by child classes
*/
function print_grades() {
function print_grades($feedback = false) {
require_once($CFG->dirroot.'/lib/odslib.class.php');
@@ -54,6 +54,11 @@ 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
if ($feedback) {
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
}
}
$myxls->write_string(0,$pos,get_string("total"));
@@ -81,6 +86,11 @@ 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]));
}
}
$myxls->write_number($i,$j,$this->totals[$student->id]);
}
+11 -2
View File
@@ -31,7 +31,7 @@ class grade_export_txt extends grade_export {
/**
* To be implemented by child classes
*/
function print_grades() {
function print_grades($feedback = false;) {
/// Print header to force download
@@ -50,6 +50,11 @@ class grade_export_txt extends grade_export {
foreach ($this->columns as $column) {
$column = strip_tags($column);
echo "\t$column";
/// add a column_feedback column
if ($feedback) {
echo "\t{$column}_feedback";
}
}
echo "\t".get_string("total")."\n";
@@ -62,7 +67,11 @@ class grade_export_txt extends grade_export {
echo "$student->firstname\t$student->lastname\t$student->idnumber\t$student->institution\t$student->department\t$student->email";
foreach ($studentgrades as $grade) {
$grade = strip_tags($grade);
echo "\t$grade";
echo "\t$grade";
if ($feedback) {
echo "\t".array_shift($this->comments[$student->id]);
}
}
echo "\t".$this->totals[$student->id];
echo "\n";
+12 -3
View File
@@ -31,14 +31,14 @@ class grade_export_xls extends grade_export {
/**
* To be implemented by child classes
*/
function print_grades() {
function print_grades($feedback = false) {
global $CFG;
require_once($CFG->dirroot.'/lib/excellib.class.php');
/// Calculate file name
$downloadfilename = clean_filename("$course->shortname $this->strgrades.xls");
$downloadfilename = clean_filename("$this->course->shortname $this->strgrades.xls");
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
@@ -56,6 +56,10 @@ 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
if ($feedback) {
$myxls->write_string(0,$pos++,strip_tags($column."_feedback"));
}
}
$myxls->write_string(0,$pos,get_string("total"));
@@ -82,7 +86,12 @@ 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]));
}
}
$myxls->write_number($i,$j,$this->totals[$student->id]);
}
+101
View File
@@ -0,0 +1,101 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
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) {
global $CFG;
require_once($CFG->dirroot.'/lib/excellib.class.php');
/// Calculate file name
$downloadfilename = clean_filename("$this->course->shortname $this->strgrades.xml");
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
foreach ($this->grades as $studentid => $studentgrades) {
echo '<result>';
// state can be new, or regrade
// require comparing of timestamps in db
$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
if ($gradeitem->exported) {
// get the grade_grades_final for this user
unset($params);
$params->itemid = $gradeitem->id;
$params->userid = $studentid;
$grade_grades_final = new grade_grades_final($params);
// if exported, check grade_history, if modified after export, set state to regrade
if (record_exists_select('grade_hitory', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades_final->exported)) {
$status = 'regrade';
} else {
$status = 'new';
}
} else {
// never exported
$status = 'new';
}
echo '<state>'.$status.'</state>';
// only need id number
echo '<assignment>'.$idnumber.'</assignment>';
// this column should be customizable to use either student id, idnumber, uesrname or email.
echo '<student>'.$studentid.'</student>';
echo '<score>'.$studentgrades[$index].'</score>';
if ($feedback) {
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
}
echo '</result>';
}
}
echo '</results>';
exit;
}
}
?>