First draft of the grader report

This commit is contained in:
nicolasconnault 2007-06-20 11:56:51 +00:00
parent 412dd995c8
commit 6500f2807f
6 changed files with 299 additions and 10 deletions

View File

@ -0,0 +1 @@
The default gradebook interface that teachers will use.

View File

@ -0,0 +1,29 @@
<?php // $Id$
$gradereport_grader_capabilities = array(
'gradereport/grader:view' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'gradereport/grader:manage' => array(
'riskbitmask' => RISK_PERSONAL | RISK_CONFIG,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
)
);
?>

View File

@ -0,0 +1,182 @@
<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 2001-2007 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 //
// //
///////////////////////////////////////////////////////////////////////////
set_time_limit(0);
require_once $CFG->libdir . '/grade/grade_tree.php';
require_once $CFG->libdir . '/gradelib.php';
$param = new stdClass();
$param->courseid = optional_param('courseid', 0 , PARAM_INT);
$param->moveup = optional_param('moveup', 0, PARAM_INT);
$param->movedown = optional_param('movedown', 0, PARAM_INT);
$param->source = optional_param('source', 0, PARAM_INT);
$param->action = optional_param('action', 0, PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->type = optional_param('type', 0, PARAM_ALPHA);
$param->target = optional_param('target', 0, PARAM_INT);
$param->confirm = optional_param('confirm', 0, PARAM_INT);
$param->items = optional_param('items', 0, PARAM_INT);
$param->categories = optional_param('categories', 0, PARAM_INT);
$param->element_type = optional_param('element_type', 0, PARAM_ALPHA);
$param->category_name = optional_param('category_name', 0, PARAM_ALPHA);
print_object($param);
$tree = new grade_tree($param->courseid);
$select_source = false;
if (!empty($param->action) && !empty($param->source) && confirm_sesskey()) {
$element = $tree->locate_element($param->source);
$element_name = $element->element['object']->get_name();
$strselectdestination = get_string('selectdestination', 'grades', $element_name);
$strmovingelement = get_string('movingelement', 'grades', $element_name);
$strcancel = get_string('cancel');
print_heading($strselectdestination);
echo $strmovingelement . ' (<a href="category.php?cancelmove=true' . $tree->commonvars . '">' . $strcancel . '</a>)' . "\n";
} elseif (!empty($param->source) && confirm_sesskey()) {
if (!empty($param->moveup)) {
$tree->move_element($param->source, $param->moveup);
} elseif(!empty($param->movedown)) {
$tree->move_element($param->source, $param->movedown, 'after');
} elseif(!empty($param->move)) {
$tree->move_element($param->source, $param->move, 'after');
}
$tree->renumber();
$tree->update_db();
} elseif (!empty($param->target) && !empty($param->action) && confirm_sesskey()) {
$element = $tree->locate_element($param->target);
switch ($param->action) {
case 'edit':
break;
case 'delete':
if ($param->confirm == 1) { // Perform the deletion
$tree->remove_element($param->target);
$tree->renumber();
$tree->update_db();
// Print result message
} else { // Print confirmation dialog
$strdeletecheckfull = get_string('deletecheck', '', $element->element['object']->get_name());
$linkyes = "category.php?target=$param->target&amp;action=delete&amp;confirm=1$tree->commonvars";
$linkno = "category.php?$tree->commonvars";
notice_yesno($strdeletecheckfull, $linkyes, $linkno);
}
break;
case 'hide':
// TODO Implement calendar for selection of a date to hide element until
if (!$element->element['object']->set_hidden(1)) {
debugging("Could not update the element's hidden state!");
} else {
$tree = new grade_tree($param->courseid);
}
break;
case 'show':
if (!$element->element['object']->set_hidden(0)) {
debugging("Could not update the element's hidden state!");
} else {
$tree = new grade_tree($param->courseid);
}
break;
case 'lock':
// TODO Implement calendar for selection of a date to lock element after
if (!$element->element['object']->set_locked(1)) {
debugging("Could not update the element's locked state!");
} else {
$tree = new grade_tree($param->courseid);
}
break;
case 'unlock':
if (!$element->element['object']->set_locked(0)) {
debugging("Could not update the element's locked state!");
} else {
$tree = new grade_tree($param->courseid);
}
break;
default:
break;
}
unset($param->target);
} elseif (!empty($param->element_type) && !empty($param->action) && $param->action == 'create' && confirm_sesskey()) {
if (empty($param->category_name)) {
notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('nocategoryname', 'grades'));
} elseif ($param->element_type == 'items') {
if (!empty($param->items)) {
$category = new grade_category();
$category->fullname = $param->category_name;
$category->courseid = $tree->courseid;
$category->insert();
$items = array();
foreach ($param->items as $sortorder => $useless_var) {
$element = $tree->locate_element($sortorder);
$items[$element->element['object']->id] = $element->element['object'];
}
if ($category->set_as_parent($items) && $category->update()) {
$tree = new grade_tree($param->courseid);
} else { // creation of category didn't work, print a message
debugging("Could not create a parent category over the items you selected..");
}
} else { // No items selected. Can't create a category over them...
notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('noselecteditems', 'grades'));
}
} elseif ($param->element_type == 'categories') {
if (!empty($param->categories)) {
$category = new grade_category();
$category->fullname = $param->category_name;
$category->courseid = $tree->courseid;
$category->insert();
$categories = array();
foreach ($param->categories as $sortorder => $useless_var) {
$element = $tree->locate_element($sortorder);
$categories[$element->element['object']->id] = $element->element['object'];
}
if ($category->set_as_parent($categories) && $category->update()) {
$tree = new grade_tree($param->courseid);
} else { // creation of category didn't work, print a message
debugging("Could not create a parent category over the categories you selected..");
}
} else { // No categories selected. Can't create a category over them...
notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('noselectedcategories', 'grades'));
}
} else { // The element_type wasn't set properly, throw up an error
}
}
print_heading(get_string('graderreport', 'grades'));
echo $tree->get_edit_tree(1, null, $param->source, $param->action, $param->type);
?>

View File

@ -23,10 +23,8 @@
// // // //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
set_time_limit(0); set_time_limit(0);
require_once '../../../config.php';
require_once $CFG->libdir . '/grade/grade_tree.php'; require_once $CFG->libdir . '/grade/grade_tree.php';
require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->libdir . '/gradelib.php';
print_header('Edit categories');
$param = new stdClass(); $param = new stdClass();
@ -179,8 +177,6 @@ if (!empty($param->action) && !empty($param->source) && confirm_sesskey()) {
} }
} }
print_heading(get_string('graderreport', 'grades'));
echo $tree->get_edit_tree(1, null, $param->source, $param->action, $param->type); echo $tree->get_edit_tree(1, null, $param->source, $param->action, $param->type);
print_footer();
?> ?>

View File

@ -2,8 +2,22 @@
/// This creates and handles the whole grader report interface, sans header and footer /// This creates and handles the whole grader report interface, sans header and footer
require_once($CFG->libdir.'/tablelib.php');
include_once($CFG->libdir.'/gradelib.php');
// get the params
$courseid = required_param('id', PARAM_INT);
if (!$userid = optional_param('user', 0, PARAM_INT)) {
// current user
$userid = $USER->id;
}
$tree = new grade_tree($courseid, true);
echo $tree->display_grades();
print_heading('Grader Report');
print_heading('Grader Report');
?> ?>

View File

@ -84,6 +84,12 @@ class grade_tree {
*/ */
var $include_grades; var $include_grades;
/**
* An flat array of final grades indexed by userid.
* @var array $grades
*/
var $grades = array();
/** /**
* A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class. * A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
* @var string $commonvars * @var string $commonvars
@ -632,6 +638,38 @@ class grade_tree {
return $objects; return $objects;
} }
/**
* Once the tree_array has been built, fills the $grades array by browsing through the tree
* and adding each final grade that is found.
* @return array $grades
*/
function fill_grades($array = null) {
if (empty($array)) {
$array = $this->tree_array;
}
if (empty($array)) {
return null;
} else {
foreach ($array as $level1order => $level1) {
// If $level1 is a category, enter another recursive layer
if ($this->get_element_type($level1) == 'topcat' || $this->get_element_type($level1) == 'subcat') {
$this->fill_grades($level1['children']);
} else {
if (!empty($level1['finalgrades'])) {
foreach ($level1['finalgrades'] as $final_grade) {
$this->grades[$final_grade->userid][$final_grade->itemid] = $final_grade->gradevalue;
}
}
}
}
reset($array);
return true;
}
}
/** /**
* Static method that returns a sorted, nested array of all grade_categories and grade_items for * Static method that returns a sorted, nested array of all grade_categories and grade_items for
* a given course, or for the entire site if no courseid is given. This method is not recursive * a given course, or for the entire site if no courseid is given. This method is not recursive
@ -814,18 +852,29 @@ class grade_tree {
* @return string HTML table * @return string HTML table
*/ */
function display_grades() { function display_grades() {
global $CFG;
// 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder // 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
$tree = $this->tree_filled; $tree = $this->tree_filled;
$this->fill_grades();
if (empty($this->tree_filled)) { if (empty($this->tree_filled)) {
debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly."); debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
return false; return false;
} }
// Fetch array of students enroled in this course
if (!$context = get_context_instance(CONTEXT_COURSE, $this->courseid)) {
return false;
}
$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
$topcathtml = '<tr>'; $topcathtml = '<tr>';
$cathtml = '<tr>'; $cathtml = '<tr>';
$itemhtml = '<tr>'; $itemhtml = '<tr>';
$items = array();
foreach ($tree as $topcat) { foreach ($tree as $topcat) {
$itemcount = 0; $itemcount = 0;
@ -835,7 +884,8 @@ class grade_tree {
foreach ($cat['children'] as $item) { foreach ($cat['children'] as $item) {
$itemcount++; $itemcount++;
$catitemcount++; $catitemcount++;
$itemhtml .= '<td>' . $item['object']->itemname . '</td>'; $itemhtml .= '<td>' . $item['object']->itemname . '</td>';
$items[] = $item;
} }
if ($cat['object'] == 'filler') { if ($cat['object'] == 'filler') {
@ -858,11 +908,28 @@ class grade_tree {
} }
$studentshtml = '';
foreach ($users as $userid => $user) {
$studentshtml .= '<tr>';
foreach ($items as $item) {
if (!empty($this->grades[$userid][$item['object']->id])) {
$studentshtml .= '<td>' . $this->grades[$userid][$item['object']->id] . '</td>' . "\n";
} else {
$studentshtml .= '<td>0</td>' . "\n";
}
}
$studentshtml .= '</tr>';
}
$itemhtml .= '</tr>'; $itemhtml .= '</tr>';
$cathtml .= '</tr>'; $cathtml .= '</tr>';
$topcathtml .= '</tr>'; $topcathtml .= '</tr>';
return "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml</table>"; $reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
$reporthtml .= $studentshtml;
$reporthtml .= "</table>";
return $reporthtml;
} }