Skip to content

Commit

Permalink
grade export plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed May 10, 2007
1 parent f744267 commit a216f66
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 6 deletions.
2 changes: 2 additions & 0 deletions grade/export/lib.php
Expand Up @@ -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
Expand Down Expand Up @@ -109,6 +110,7 @@ function grade_export($id, $itemids = '') {
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";
Expand Down
12 changes: 11 additions & 1 deletion grade/export/ods/grade_export_ods.php
Expand Up @@ -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');

Expand All @@ -54,6 +54,11 @@ function print_grades() {
$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"));

Expand Down Expand Up @@ -81,6 +86,11 @@ function print_grades() {
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]);
}
Expand Down
13 changes: 11 additions & 2 deletions grade/export/txt/grade_export_txt.php
Expand Up @@ -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

Expand All @@ -50,6 +50,11 @@ function print_grades() {
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";

Expand All @@ -62,7 +67,11 @@ function print_grades() {
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";
Expand Down
15 changes: 12 additions & 3 deletions grade/export/xls/grade_export_xls.php
Expand Up @@ -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
Expand All @@ -56,6 +56,10 @@ function print_grades() {
$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"));

Expand All @@ -82,7 +86,12 @@ function print_grades() {
}
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]);
}
Expand Down
101 changes: 101 additions & 0 deletions grade/export/xml/grade_export_xml.php
@@ -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;
}
}

?>

0 comments on commit a216f66

Please sign in to comment.