2007-05-08 08:59:41 +00:00
|
|
|
<?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 //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2007-05-24 02:16:31 +00:00
|
|
|
|
2007-05-11 09:08:30 +00:00
|
|
|
include_once($CFG->dirroot.'/lib/gradelib.php');
|
2007-05-15 08:49:49 +00:00
|
|
|
include_once($CFG->dirroot.'/grade/lib.php');
|
2007-05-11 09:08:30 +00:00
|
|
|
/**
|
|
|
|
* Prints all grade items for selection
|
|
|
|
* @input int id - course id
|
|
|
|
*/
|
2007-05-18 08:49:00 +00:00
|
|
|
function print_gradeitem_selections($id, $params = NULL) {
|
2007-05-24 02:16:31 +00:00
|
|
|
global $CFG;
|
2007-05-11 09:08:30 +00:00
|
|
|
// print all items for selections
|
|
|
|
// make this a standard function in lib maybe
|
2007-05-24 08:57:36 +00:00
|
|
|
include_once('grade_export_form.php');
|
|
|
|
$mform = new grade_export_form(qualified_me(), array('id'=>$id));
|
|
|
|
$mform->display();
|
|
|
|
|
2007-05-11 09:08:30 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Base export class
|
|
|
|
*/
|
2007-05-08 08:59:41 +00:00
|
|
|
class grade_export {
|
|
|
|
|
|
|
|
var $format = ''; // export format
|
|
|
|
var $id; // course id
|
2007-05-09 08:45:25 +00:00
|
|
|
var $itemids; // comma separated grade_item ids;
|
2007-05-08 08:59:41 +00:00
|
|
|
var $grades = array(); // Collect all grades in this array
|
|
|
|
var $gradeshtml= array(); // Collect all grades html formatted in this array
|
2007-05-09 08:45:25 +00:00
|
|
|
var $comments = array(); // Collect all comments for each grade
|
2007-05-08 08:59:41 +00:00
|
|
|
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.
|
2007-05-10 09:29:58 +00:00
|
|
|
var $columnidnumbers = array(); // Collect all gradeitem id numbers
|
2007-05-15 08:49:49 +00:00
|
|
|
var $students = array();
|
2007-05-08 08:59:41 +00:00
|
|
|
var $course; // course
|
|
|
|
|
|
|
|
// common strings
|
|
|
|
var $strgrades;
|
|
|
|
var $strgrade;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor should set up all the private variables ready to be pulled
|
2007-05-09 08:45:25 +00:00
|
|
|
* @input int id - course id
|
|
|
|
* @input string itemids - comma separated value of itemids to process for this export
|
2007-05-08 08:59:41 +00:00
|
|
|
*/
|
2007-05-09 08:45:25 +00:00
|
|
|
function grade_export($id, $itemids = '') {
|
2007-05-08 08:59:41 +00:00
|
|
|
|
|
|
|
$this->strgrades = get_string("grades");
|
|
|
|
$this->strgrade = get_string("grade");
|
2007-05-09 08:45:25 +00:00
|
|
|
$this->itemids = $itemids;
|
2007-05-08 08:59:41 +00:00
|
|
|
|
|
|
|
$strmax = get_string("maximumshort");
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
|
|
error("Course ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id));
|
|
|
|
|
|
|
|
$this->id = $id;
|
|
|
|
$this->course = $course;
|
|
|
|
|
2007-06-18 13:43:40 +00:00
|
|
|
// first make sure we have all final grades
|
|
|
|
// TODO: check that no grade_item has needsupdate set
|
2007-06-21 02:45:04 +00:00
|
|
|
grade_update_final_grades($id);
|
2007-06-18 13:43:40 +00:00
|
|
|
|
2007-05-08 08:59:41 +00:00
|
|
|
/// 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 {
|
|
|
|
$changegroup = -1; /// This means no group change was specified
|
|
|
|
}
|
|
|
|
|
|
|
|
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$currentgroup = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($currentgroup) {
|
2007-05-15 08:49:49 +00:00
|
|
|
$this->students = get_group_students($currentgroup, "u.lastname ASC");
|
2007-05-08 08:59:41 +00:00
|
|
|
} else {
|
2007-05-15 08:49:49 +00:00
|
|
|
$this->students = grade_get_course_students($course->id);
|
2007-05-08 08:59:41 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 08:49:49 +00:00
|
|
|
if (!empty($this->students)) {
|
|
|
|
foreach ($this->students as $student) {
|
2007-05-08 08:59:41 +00:00
|
|
|
$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
|
2007-05-09 08:45:25 +00:00
|
|
|
$this->comments[$student->id] = array(); // Collect all comments in tihs array
|
2007-05-08 08:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-18 08:49:00 +00:00
|
|
|
|
2007-05-09 08:45:25 +00:00
|
|
|
// if grade_item ids are specified
|
2007-05-18 08:49:00 +00:00
|
|
|
if ($itemids) {
|
|
|
|
foreach ($itemids as $iid) {
|
2007-06-12 09:12:07 +00:00
|
|
|
|
|
|
|
if ($iid) {
|
|
|
|
$params->id = $iid;
|
|
|
|
$gradeitems[] = new grade_item($params);
|
|
|
|
}
|
2007-05-09 08:45:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// else we get all items for this course
|
2007-06-24 22:26:33 +00:00
|
|
|
$gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
|
2007-05-18 08:49:00 +00:00
|
|
|
}
|
2007-05-09 08:45:25 +00:00
|
|
|
|
|
|
|
if ($gradeitems) {
|
2007-05-08 08:59:41 +00:00
|
|
|
foreach ($gradeitems as $gradeitem) {
|
2007-05-18 08:49:00 +00:00
|
|
|
|
2007-05-08 08:59:41 +00:00
|
|
|
// load as an array of grade_final objects
|
2007-06-21 02:45:04 +00:00
|
|
|
if ($itemgrades = $gradeitem -> get_final()) {
|
2007-05-16 08:21:46 +00:00
|
|
|
|
2007-05-18 08:49:00 +00:00
|
|
|
$this->columns[$gradeitem->id] = "$gradeitem->itemmodule: ".format_string($gradeitem->itemname,true)." - $gradeitem->grademax";
|
2007-05-08 08:59:41 +00:00
|
|
|
|
2007-05-18 08:49:00 +00:00
|
|
|
$this->columnidnumbers[$gradeitem->id] = $gradeitem->idnumber; // this might be needed for some export plugins
|
2007-05-16 08:21:46 +00:00
|
|
|
|
|
|
|
if (!empty($gradeitem->grademax)) {
|
|
|
|
$maxgrade = "$strmax: $gradeitem->grademax";
|
|
|
|
} else {
|
|
|
|
$maxgrade = "";
|
2007-05-24 02:16:31 +00:00
|
|
|
}
|
2007-05-16 08:21:46 +00:00
|
|
|
|
2007-05-15 08:49:49 +00:00
|
|
|
if (!empty($this->students)) {
|
|
|
|
foreach ($this->students as $student) {
|
2007-05-24 02:16:31 +00:00
|
|
|
unset($studentgrade);
|
2007-05-08 08:59:41 +00:00
|
|
|
// add support for comment here MDL-9634
|
2007-05-24 02:16:31 +00:00
|
|
|
|
|
|
|
if (!empty($itemgrades[$student->id])) {
|
|
|
|
$studentgrade = $itemgrades[$student->id];
|
|
|
|
}
|
2007-05-09 08:45:25 +00:00
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
if (!empty($studentgrade->finalgrade)) {
|
|
|
|
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = $studentgrade->finalgrade;
|
2007-05-08 08:59:41 +00:00
|
|
|
} else {
|
2007-05-18 08:49:00 +00:00
|
|
|
$this->grades[$student->id][$gradeitem->id] = $currentstudentgrade = "";
|
|
|
|
$this->gradeshtml[$student->id][$gradeitem->id] = "";
|
2007-05-08 08:59:41 +00:00
|
|
|
}
|
2007-05-09 08:45:25 +00:00
|
|
|
if (!empty($maxgrade)) {
|
2007-05-15 08:49:49 +00:00
|
|
|
$this->totals[$student->id] = (float)($this->totals[$student->id]) + (float)($currentstudentgrade);
|
2007-05-08 08:59:41 +00:00
|
|
|
} else {
|
2007-05-15 08:49:49 +00:00
|
|
|
$this->totals[$student->id] = (float)($this->totals[$student->id]) + 0;
|
2007-05-09 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2007-05-24 02:16:31 +00:00
|
|
|
if (!empty($comment)) {
|
|
|
|
// load comments here
|
|
|
|
if ($studentgrade) {
|
|
|
|
$studentgrade->load_text();
|
|
|
|
// get the actual comment
|
|
|
|
$comment = $studentgrade->grade_grades_text->feedback;
|
|
|
|
$this->comments[$student->id][$gradeitem->id] = $comment;
|
|
|
|
}
|
2007-05-09 08:45:25 +00:00
|
|
|
} else {
|
2007-05-18 08:49:00 +00:00
|
|
|
$this->comments[$student->id][$gradeitem->id] = '';
|
2007-05-09 08:45:25 +00:00
|
|
|
}
|
2007-05-08 08:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To be implemented by child classes
|
|
|
|
*/
|
|
|
|
function print_grades() { }
|
2007-05-11 09:08:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays all the grades on screen as a feedback mechanism
|
|
|
|
*/
|
2007-05-16 08:21:46 +00:00
|
|
|
function display_grades($feedback=false) {
|
2007-05-22 02:05:00 +00:00
|
|
|
echo '<table>';
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<th>'.get_string("firstname")."</th>".
|
|
|
|
'<th>'.get_string("lastname")."</th>".
|
|
|
|
'<th>'.get_string("idnumber")."</th>".
|
|
|
|
'<th>'.get_string("institution")."</th>".
|
|
|
|
'<th>'.get_string("department")."</th>".
|
|
|
|
'<th>'.get_string("email")."</th>";
|
2007-05-11 09:08:30 +00:00
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
$column = strip_tags($column);
|
2007-05-22 02:05:00 +00:00
|
|
|
echo "<th>$column</th>";
|
2007-05-11 09:08:30 +00:00
|
|
|
|
|
|
|
/// add a column_feedback column
|
|
|
|
if ($feedback) {
|
2007-05-22 02:05:00 +00:00
|
|
|
echo "<th>{$column}_feedback</th>";
|
2007-05-11 09:08:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-22 02:05:00 +00:00
|
|
|
echo '<th>'.get_string("total")."</th>";
|
|
|
|
echo '</tr>';
|
2007-05-11 09:08:30 +00:00
|
|
|
/// Print all the lines of data.
|
2007-05-22 02:05:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->grades as $studentid => $studentgrades) {
|
|
|
|
|
|
|
|
echo '<tr>';
|
2007-05-16 08:21:46 +00:00
|
|
|
$student = $this->students[$studentid];
|
2007-05-11 09:08:30 +00:00
|
|
|
if (empty($this->totals[$student->id])) {
|
|
|
|
$this->totals[$student->id] = '';
|
|
|
|
}
|
2007-05-22 02:05:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
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>";
|
2007-05-11 09:08:30 +00:00
|
|
|
foreach ($studentgrades as $grade) {
|
|
|
|
$grade = strip_tags($grade);
|
2007-05-22 02:05:00 +00:00
|
|
|
echo "<td>$grade</td>";
|
2007-05-11 09:08:30 +00:00
|
|
|
|
|
|
|
if ($feedback) {
|
2007-05-22 02:05:00 +00:00
|
|
|
echo '<td>'.array_shift($this->comments[$student->id]).'</td>';
|
2007-05-11 09:08:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-22 02:05:00 +00:00
|
|
|
echo '<td>'.$this->totals[$student->id].'</td>';
|
|
|
|
echo "</tr>";
|
|
|
|
}
|
|
|
|
echo '</table>';
|
2007-05-11 09:08:30 +00:00
|
|
|
}
|
2007-05-08 08:59:41 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 09:08:30 +00:00
|
|
|
?>
|