Skip to content

Commit

Permalink
new grade book export plugins development
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed May 16, 2007
1 parent b6b354e commit 985d1ee
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 53 deletions.
51 changes: 26 additions & 25 deletions grade/export/lib.php
Expand Up @@ -143,18 +143,19 @@ function grade_export($id, $itemids = '') {

foreach ($gradeitems as $gradeitem) {

$this->columns[] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";
$this->columnidnumbers[] = $gradeitem->idnumber; // this might be needed for some export plugins

if (!empty($gradeitem->maxgrade)) {
$maxgrade = "$strmax: $gradeitem->maxgrade";
} else {
$maxgrade = "";
}

// load as an array of grade_final objects
if ($itemgrades = $gradeitem -> load_final()) {

$this->columns[$itemgrades->id] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";

$this->columnidnumbers[$itemgrades->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)) {
foreach ($this->students as $student) {

Expand All @@ -164,7 +165,7 @@ function grade_export($id, $itemids = '') {
if (!empty($studentgrade->gradevalue)) {
$this->grades[$student->id][$itemgrades->id] = $currentstudentgrade = $studentgrade->gradevalue;
} else {
$this->grades[$student->id][] = $currentstudentgrade = "";
$this->grades[$student->id][$itemgrades->id] = $currentstudentgrade = "";
$this->gradeshtml[$student->id][$itemgrades->id] = "";
}
if (!empty($maxgrade)) {
Expand Down Expand Up @@ -198,41 +199,41 @@ function print_grades() { }
/**
* Displays all the grades on screen as a feedback mechanism
*/
function display_grades() {
echo get_string("firstname")."\t".
get_string("lastname")."\t".
get_string("idnumber")."\t".
get_string("institution")."\t".
get_string("department")."\t".
function display_grades($feedback=false) {
echo get_string("firstname").",".
get_string("lastname").",".
get_string("idnumber").",".
get_string("institution").",".
get_string("department").",".
get_string("email");
foreach ($this->columns as $column) {
$column = strip_tags($column);
echo "\t$column";
echo ",$column";

/// add a column_feedback column
if ($feedback) {
echo "\t{$column}_feedback";
echo ",{$column}_feedback";
}
}
echo "\t".get_string("total")."\n";
echo ",".get_string("total")."<br/>";

/// Print all the lines of data.
foreach ($this->grades as $studentid => $studentgrades) {
$student = $students[$studentid];
$student = $this->students[$studentid];
if (empty($this->totals[$student->id])) {
$this->totals[$student->id] = '';
}
echo "$student->firstname\t$student->lastname\t$student->idnumber\t$student->institution\t$student->department\t$student->email";
echo "$student->firstname,$student->lastname,$student->idnumber,$student->institution,$student->department,$student->email";
foreach ($studentgrades as $grade) {
$grade = strip_tags($grade);
echo "\t$grade";
echo ",$grade";

if ($feedback) {
echo "\t".array_shift($this->comments[$student->id]);
echo ",".array_shift($this->comments[$student->id]);
}
}
echo "\t".$this->totals[$student->id];
echo "\n";
echo ",".$this->totals[$student->id];
echo "<br/>";
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions grade/export/ods/export.php
@@ -0,0 +1,15 @@
<?php

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 = required_param('itemids', PARAM_NOTAGS);
$feedback = optional_param('feedback', '', PARAM_ALPHA);

// print all the exported data here
$export = new grade_export_ods($id, $itemids);
$export->print_grades($feedback);

?>
10 changes: 7 additions & 3 deletions grade/export/ods/grade_export_ods.php
Expand Up @@ -41,9 +41,13 @@ function print_grades($feedback = false) {
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
$export = true;
}
} else {
$export = false;
}
} else {
$export = false;
}

/// Calculate file name
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
/// Creating a workbook
Expand Down Expand Up @@ -88,7 +92,7 @@ function print_grades($feedback = false) {
$myxls->write_string($i,4,$student->department);
$myxls->write_string($i,5,$student->email);
$j=6;
foreach ($studentgrades as $grade) {
foreach ($studentgrades as $gradeitemid => $grade) {
if (is_numeric($grade)) {
$myxls->write_number($i,$j++,strip_tags($grade));
}
Expand Down
51 changes: 51 additions & 0 deletions grade/export/ods/index.php
@@ -0,0 +1,51 @@
<?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("../../../config.php");
require_once($CFG->dirroot.'/grade/export/lib.php');
require_once('grade_export_ods.php');

$id = required_param('id', PARAM_INT); // course id
$feedback = optional_param('feedback', '', PARAM_ALPHA);

// process post information
if ($data = data_submitted() && confirm_sesskey()) {

if (!is_array($data->itemids)) {
$itemidsurl = $data->itemids;
} else {
$itemidsurl = implode(",",$data->itemids);
}

// print the grades on screen for feedbacks
print_header(get_string('grade'),get_string('grade'),get_string('grade'));
$export = new grade_export($id, $data->itemids);
$export->display_grades($feedback);
print_footer();
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl);
exit;
}

print_gradeitem_selections($id);
?>
6 changes: 5 additions & 1 deletion grade/export/txt/grade_export_txt.php
Expand Up @@ -39,7 +39,11 @@ function print_grades($feedback = false) {
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
$export = true;
}
} else {
$export = false;
}
} else {
$export = false;
}

/// Print header to force download
Expand Down
18 changes: 12 additions & 6 deletions grade/export/txt/index.php
Expand Up @@ -30,15 +30,21 @@

// process post information
if ($data = data_submitted() && confirm_sesskey()) {
$itemids = implode(",", $data->itemids);
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemids);


if (!is_array($data->itemids)) {
$itemidsurl = $data->itemids;
} else {
$itemidsurl = implode(",",$data->itemids);
}

// print the grades on screen for feedbacks
print_header();
$export = new grade_export($id, $itemids);
print_header(get_string('grade'),get_string('grade'),get_string('grade'));
$export = new grade_export($id, $data->itemids);
$export->display_grades($feedback);
print_footer();

// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl);
exit;
}

Expand Down
15 changes: 15 additions & 0 deletions grade/export/xls/export.php
@@ -0,0 +1,15 @@
<?php

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 = required_param('itemids', PARAM_NOTAGS);
$feedback = optional_param('feedback', '', PARAM_ALPHA);

// print all the exported data here
$export = new grade_export_xls($id, $itemids);
$export->print_grades($feedback);

?>
8 changes: 6 additions & 2 deletions grade/export/xls/grade_export_xls.php
Expand Up @@ -39,7 +39,11 @@ function print_grades($feedback = false) {
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
$export = true;
}
} else {
$export = false;
}
} else {
$export = false;
}

require_once($CFG->dirroot.'/lib/excellib.class.php');
Expand Down Expand Up @@ -87,7 +91,7 @@ function print_grades($feedback = false) {
$myxls->write_string($i,4,$student->department);
$myxls->write_string($i,5,$student->email);
$j=6;
foreach ($studentgrades as $grade) {
foreach ($studentgrades as $gradeitemid => $grade) {
if (is_numeric($grade)) {
$myxls->write_number($i,$j++,strip_tags($grade));
}
Expand Down
52 changes: 52 additions & 0 deletions grade/export/xls/index.php
@@ -0,0 +1,52 @@
<?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("../../../config.php");
require_once($CFG->dirroot.'/grade/export/lib.php');
require_once('grade_export_xls.php');

$id = required_param('id', PARAM_INT); // course id
$feedback = optional_param('feedback', '', PARAM_ALPHA);

// process post information
if ($data = data_submitted() && confirm_sesskey()) {

if (!is_array($data->itemids)) {
$itemidsurl = $data->itemids;
} else {
$itemidsurl = implode(",",$data->itemids);
}

// print the grades on screen for feedbacks
print_header(get_string('grade'),get_string('grade'),get_string('grade'));
$export = new grade_export($id, $data->itemids);
$export->display_grades($feedback);
print_footer();

// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl);
exit;
}

print_gradeitem_selections($id);
?>
23 changes: 13 additions & 10 deletions grade/export/xml/grade_export_xml.php
Expand Up @@ -39,7 +39,11 @@ function print_grades($feedback = false) {
if ($expplugins = explode(",", $CFG->gradeexport)) {
if (in_array($this->format, $expplugins)) {
$export = true;
}
} else {
$export = false;
}
} else {
$export = false;
}

require_once($CFG->dirroot.'/lib/excellib.class.php');
Expand Down Expand Up @@ -68,18 +72,17 @@ function print_grades($feedback = false) {

// 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 (!empty($gradeitem->exported)) {

// get the grade_grades_final for this user
unset($params);
$params->itemid = $gradeitem->id;
$params->userid = $studentid;
// 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);
$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)) {
// if exported, check grade_history, if modified after export, set state to regrade
if (!empty($grade_grades_final->exported)) {
if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grades_final->exported)) {
$status = 'regrade';
} else {
$status = 'new';
Expand Down
18 changes: 12 additions & 6 deletions grade/export/xml/index.php
Expand Up @@ -30,15 +30,21 @@

// process post information
if ($data = data_submitted() && confirm_sesskey()) {
$itemids = implode(",", $data->itemids);
// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemids);


if (!is_array($data->itemids)) {
$itemidsurl = $data->itemids;
} else {
$itemidsurl = implode(",",$data->itemids);
}

// print the grades on screen for feedbacks
print_header();
$export = new grade_export($id, $itemids);
print_header(get_string('grade'),get_string('grade'),get_string('grade'));
$export = new grade_export($id, $data->itemids);
$export->display_grades($feedback);
print_footer();

// this redirect should trigger a download prompt
redirect('export.php?id='.$id.'&amp;itemids='.$itemidsurl);
exit;
}

Expand Down

0 comments on commit 985d1ee

Please sign in to comment.