fixing grade exports
This commit is contained in:
+19
-16
@@ -24,6 +24,7 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
include_once('../../../config.php');
|
||||
include_once($CFG->dirroot.'/lib/gradelib.php');
|
||||
include_once($CFG->dirroot.'/grade/lib.php');
|
||||
/**
|
||||
* Prints all grade items for selection
|
||||
* @input int id - course id
|
||||
@@ -46,6 +47,8 @@ function print_gradeitem_selections($id) {
|
||||
echo $grade_item->itemname;
|
||||
}
|
||||
}
|
||||
echo '<input type="hidden" name="id" value="'.$id.'"/>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'"/>';
|
||||
echo '<input type="submit" value="'.get_string('submit').'" />';
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
@@ -66,6 +69,7 @@ class grade_export {
|
||||
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 $students = array();
|
||||
var $course; // course
|
||||
|
||||
// common strings
|
||||
@@ -110,13 +114,13 @@ class grade_export {
|
||||
}
|
||||
|
||||
if ($currentgroup) {
|
||||
$students = get_group_students($currentgroup, "u.lastname ASC");
|
||||
$this->students = get_group_students($currentgroup, "u.lastname ASC");
|
||||
} else {
|
||||
$students = grade_get_course_students($course->id);
|
||||
$this->students = grade_get_course_students($course->id);
|
||||
}
|
||||
|
||||
if (!empty($students)) {
|
||||
foreach ($students as $student) {
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
$this->grades[$student->id] = array(); // Collect all grades in this array
|
||||
$this->gradeshtml[$student->id] = array(); // Collect all grades html formatted in this array
|
||||
$this->totals[$student->id] = array(); // Collect all totals in this array
|
||||
@@ -133,14 +137,13 @@ class grade_export {
|
||||
} else {
|
||||
// else we get all items for this course
|
||||
$gradeitems = grade_get_items($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($gradeitems) {
|
||||
|
||||
foreach ($gradeitems as $gradeitem) {
|
||||
|
||||
$this->columns[] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->maxgrade";
|
||||
$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)) {
|
||||
@@ -150,24 +153,24 @@ class grade_export {
|
||||
}
|
||||
|
||||
// load as an array of grade_final objects
|
||||
if ($itemgrades = $gradeitem -> load_final()) {
|
||||
if ($itemgrades = $gradeitem -> load_final()) {
|
||||
|
||||
if (!empty($students)) {
|
||||
foreach ($students as $student) {
|
||||
if (!empty($this->students)) {
|
||||
foreach ($this->students as $student) {
|
||||
|
||||
// add support for comment here MDL-9634
|
||||
$studentgrade = $itemgrades[$student->id];
|
||||
|
||||
if (!empty($studentgrade->gradevalue)) {
|
||||
$this->grades[$student->id][] = $currentstudentgrade = $studentgrade->gradevalue;
|
||||
$this->grades[$student->id][$itemgrades->id] = $currentstudentgrade = $studentgrade->gradevalue;
|
||||
} else {
|
||||
$this->grades[$student->id][] = $currentstudentgrade = "";
|
||||
$this->gradeshtml[$student->id][] = "";
|
||||
$this->gradeshtml[$student->id][$itemgrades->id] = "";
|
||||
}
|
||||
if (!empty($maxgrade)) {
|
||||
$this->totals[$student->id] = (float)($totals[$student->id]) + (float)($currentstudentgrade);
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + (float)($currentstudentgrade);
|
||||
} else {
|
||||
$this->totals[$student->id] = (float)($totals[$student->id]) + 0;
|
||||
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
||||
}
|
||||
|
||||
// load comments here
|
||||
@@ -176,9 +179,9 @@ class grade_export {
|
||||
$comment = $studentgrade->grade_grades_text->feedback;
|
||||
|
||||
if (!empty($comment)) {
|
||||
$this->comments[$student->id][] = $comment;
|
||||
$this->comments[$student->id][$itemgrades->id] = $comment;
|
||||
} else {
|
||||
$this->comments[$student->id][] = '';
|
||||
$this->comments[$student->id][$itemgrades->id] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,19 @@ class grade_export_ods extends grade_export {
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
require_once($CFG->dirroot.'/lib/odslib.class.php');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("$course->shortname $this->strgrades.ods");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.ods");
|
||||
/// Creating a workbook
|
||||
$workbook = new MoodleODSWorkbook("-");
|
||||
/// Sending HTTP headers
|
||||
@@ -67,7 +76,7 @@ class grade_export_ods extends grade_export {
|
||||
if (!empty($this->grades)) {
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
$i++;
|
||||
$student = $students[$studentid];
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
}
|
||||
@@ -95,21 +104,15 @@ class grade_export_ods extends grade_export {
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades_final object and update timestamp if CFG flag is set
|
||||
|
||||
if ($expplugins = explode(",", get_config($CFG->gradeexport))) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$params->idnumber = $this->idnumber;
|
||||
// get the grade item
|
||||
$gradeitem = new grade_item($params);
|
||||
if ($export) {
|
||||
unset($params);
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
unset($params);
|
||||
$params->itemid = $gradeitem->id;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
}
|
||||
$myxls->write_number($i,$j,$this->totals[$student->id]);
|
||||
|
||||
@@ -31,12 +31,20 @@ class grade_export_txt extends grade_export {
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
/// Print header to force download
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// Print header to force download
|
||||
header("Content-Type: application/download\n");
|
||||
$downloadfilename = clean_filename("$this->course->shortname $this->strgrades");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades");
|
||||
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
|
||||
|
||||
/// Print names of all the fields
|
||||
@@ -60,12 +68,14 @@ class grade_export_txt extends grade_export {
|
||||
|
||||
/// 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";
|
||||
foreach ($studentgrades as $grade) {
|
||||
|
||||
foreach ($studentgrades as $gradeitemid => $grade) {
|
||||
$grade = strip_tags($grade);
|
||||
echo "\t$grade";
|
||||
|
||||
@@ -75,22 +85,16 @@ class grade_export_txt extends grade_export {
|
||||
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades_final object and update timestamp if CFG flag is set
|
||||
|
||||
if ($export) {
|
||||
unset($params);
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
if ($expplugins = explode(",", get_config($CFG->gradeexport))) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$params->idnumber = $this->idnumber;
|
||||
// get the grade item
|
||||
$gradeitem = new grade_item($params);
|
||||
|
||||
unset($params);
|
||||
$params->itemid = $gradeitem->id;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
}
|
||||
echo "\t".$this->totals[$student->id];
|
||||
|
||||
@@ -35,10 +35,17 @@ class grade_export_xls extends grade_export {
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
}
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||
|
||||
/// Calculate file name
|
||||
$downloadfilename = clean_filename("$this->course->shortname $this->strgrades.xls");
|
||||
$downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xls");
|
||||
/// Creating a workbook
|
||||
$workbook = new MoodleExcelWorkbook("-");
|
||||
/// Sending HTTP headers
|
||||
@@ -68,7 +75,7 @@ class grade_export_xls extends grade_export {
|
||||
if (!empty($this->grades)) {
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
$i++;
|
||||
$student = $students[$studentid];
|
||||
$student = $this->students[$studentid];
|
||||
if (empty($this->totals[$student->id])) {
|
||||
$this->totals[$student->id] = '';
|
||||
}
|
||||
@@ -96,21 +103,15 @@ class grade_export_xls extends grade_export {
|
||||
/// if export flag needs to be set
|
||||
/// construct the grade_grades_final object and update timestamp if CFG flag is set
|
||||
|
||||
if ($expplugins = explode(",", get_config($CFG->gradeexport))) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$params->idnumber = $this->idnumber;
|
||||
// get the grade item
|
||||
$gradeitem = new grade_item($params);
|
||||
if ($export) {
|
||||
unset($params);
|
||||
$params->itemid = $gradeitemid;
|
||||
$params->userid = $studentid;
|
||||
|
||||
unset($params);
|
||||
$params->itemid = $gradeitem->id;
|
||||
$params->userid = $studentid;
|
||||
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
$grade_grades_final = new grade_grades_final($params);
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
}
|
||||
$myxls->write_number($i,$j,$this->totals[$student->id]);
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
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 = required_param('itemids', PARAM_NOTAGS);
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// print all the exported data here
|
||||
$export = new grade_export_xml($id, $itemids);
|
||||
$export->print_grades($feedback);
|
||||
|
||||
?>
|
||||
@@ -33,19 +33,27 @@ class grade_export_xml extends grade_export {
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
if ($expplugins = explode(",", $CFG->gradeexport)) {
|
||||
if (in_array($this->format, $expplugins)) {
|
||||
$export = true;
|
||||
}
|
||||
}
|
||||
|
||||
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-Disposition: attachment; filename=\"$downloadfilename\"");
|
||||
|
||||
/// time stamp to ensure uniqueness of batch export
|
||||
echo '<results batch="xml_export_'.time().'">';
|
||||
foreach ($this->$columnidnumbers as $index => $idnumber) {
|
||||
|
||||
foreach ($this->columnidnumbers as $index => $idnumber) {
|
||||
|
||||
// studentgrades[] index should match with corresponding $index
|
||||
foreach ($this->grades as $studentid => $studentgrades) {
|
||||
@@ -54,13 +62,13 @@ class grade_export_xml extends grade_export {
|
||||
// state can be new, or regrade
|
||||
// require comparing of timestamps in db
|
||||
|
||||
$params->idnumber = $this->idnumber;
|
||||
$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) {
|
||||
if (!empty($gradeitem->exported)) {
|
||||
|
||||
// get the grade_grades_final for this user
|
||||
unset($params);
|
||||
@@ -91,9 +99,14 @@ class grade_export_xml extends grade_export {
|
||||
echo '<feedback>'.$this->comments[$studentid][$index].'</feedback>';
|
||||
}
|
||||
echo '</result>';
|
||||
|
||||
// if flag is set, timestamp this
|
||||
}
|
||||
|
||||
// timestamp this if needed
|
||||
if ($export) {
|
||||
$grade_grades_final->exported = time();
|
||||
// update the time stamp;
|
||||
$grade_grades_final->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</results>';
|
||||
exit;
|
||||
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?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_xml.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$feedback = optional_param('feedback', '', PARAM_ALPHA);
|
||||
|
||||
// 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.'&itemids='.$itemids);
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
print_header();
|
||||
$export = new grade_export($id, $itemids);
|
||||
$export->display_grades($feedback);
|
||||
print_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
print_gradeitem_selections($id);
|
||||
?>
|
||||
Reference in New Issue
Block a user