MDL-10224 some more improvements in grader report related to total course grade and category grade + other bugfixes

This commit is contained in:
skodak 2007-06-28 22:55:46 +00:00
parent a9f16da37d
commit 314c433698
8 changed files with 147 additions and 75 deletions

View File

@ -280,7 +280,7 @@ $navigation = build_navigation($crumbs);
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
$select_source = false;
if (!empty ($param->action) && !empty ($param->source) && confirm_sesskey()) {
@ -330,14 +330,14 @@ elseif (!empty ($param->target) && !empty ($param->action) && confirm_sesskey())
if (!$element['object']->set_hidden(1)) {
debugging("Could not update the element's hidden state!");
} else {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
}
break;
case 'show' :
if (!$element['object']->set_hidden(0)) {
debugging("Could not update the element's hidden state!");
} else {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
}
break;
case 'lock' :
@ -345,14 +345,14 @@ elseif (!empty ($param->target) && !empty ($param->action) && confirm_sesskey())
if (!$element['object']->set_locked(1)) {
debugging("Could not update the element's locked state!");
} else {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
}
break;
case 'unlock' :
if (!$element['object']->set_locked(0)) {
debugging("Could not update the element's locked state!");
} else {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
}
break;
default :
@ -380,7 +380,7 @@ elseif (!empty ($param->element_type) && !empty ($param->action) && $param->acti
}
if ($category->set_as_parent($items) && $category->update()) {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
} else { // creation of category didn't work, print a message
debugging("Could not create a parent category over the items you selected..");
}
@ -403,7 +403,7 @@ elseif (!empty ($param->element_type) && !empty ($param->action) && $param->acti
}
if ($category->set_as_parent($categories) && $category->update()) {
$gtree = new grade_tree($param->courseid, false, false);
$gtree = new grade_tree($param->courseid, false);
} else { // creation of category didn't work, print a message
debugging("Could not create a parent category over the categories you selected..");
}

View File

@ -55,7 +55,7 @@ $type = optional_param('type', 0, PARAM_ALPHA);
$target = optional_param('target', 0, PARAM_ALPHANUM);
// Grab the grade_tree for this course
$gtree = new grade_tree($courseid, false);
$gtree = new grade_tree($courseid);
// setting the sort order, this depends on last state
// all this should be in the new table class that we might need to use
@ -253,9 +253,6 @@ if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
}
//$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
$topcathtml = '<tr><td class="filler">&nbsp;</td>';
$cathtml = '<tr><td class="filler">&nbsp;</td>';
if ($sortitemid === 'lastname') {
if ($sortorder == 'ASC') {
$lastarrow = ' <img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strsortasc.'" /> ';
@ -286,29 +283,36 @@ $numrows = count($gtree->levels);
foreach ($gtree->levels as $key=>$row) {
if ($key ==0) {
// do not diplay course grade category
continue;
// continue;
}
$headerhtml .= '<tr>';
$headerhtml .= '<tr class="heading">';
if ($key == $numrows - 1) {
$headerhtml .= '<th class="filler"><a href="'.$baseurl.'&amp;sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&amp;sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
$headerhtml .= '<th class="user"><a href="'.$baseurl.'&amp;sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&amp;sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
} else {
$headerhtml .= '<td class="filler">&nbsp;</td>';
$headerhtml .= '<td class="topleft">&nbsp;</td>';
}
foreach ($row as $element) {
if (!empty($element['collspan'])) {
$colspan = 'colspan="'.$element['collspan'].'"';
if (!empty($element['colspan'])) {
$colspan = 'colspan="'.$element['colspan'].'"';
} else {
$colspan = '';
}
if ($element['object'] == 'filler') {
$headerhtml .= '<td class="filler" '.$colspan.'>&nbsp;</td>';
if (!empty($element['depth'])) {
$catlevel = ' catlevel'.$element['depth'];
} else {
$catlevel = '';
}
} else if (get_class($element['object']) == 'grade_category') {
$headerhtml .= '<td '.$colspan.'">' . $element['object']->get_name();
if ($element['type'] == 'filler') {
$headerhtml .= '<td class="filler'.$catlevel.'" '.$colspan.'>&nbsp;</td>';
} else if ($element['type'] == 'category') {
$headerhtml .= '<td class="category'.$catlevel.'" '.$colspan.'">'.$element['object']->get_name();
// Print icons
if ($USER->gradeediting) {
@ -331,7 +335,7 @@ foreach ($gtree->levels as $key=>$row) {
$dimmed = 'class="dimmed_text"';
}
$headerhtml .= '<th '.$dimmed.'><a href="'.$baseurl.'&amp;sortitemid='
$headerhtml .= '<th '.$dimmed.' class="'.$element['type'].$catlevel.'"><a href="'.$baseurl.'&amp;sortitemid='
. $element['object']->id .'">'. $element['object']->get_name()
. '</a>' . $arrow;
@ -349,7 +353,7 @@ foreach ($gtree->levels as $key=>$row) {
$studentshtml = '';
foreach ($users as $userid => $user) {
$studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
$studentshtml .= '<tr><th class="user">' . $user->firstname . ' ' . $user->lastname . '</th>';
foreach ($items as $item) {
@ -416,7 +420,7 @@ foreach ($users as $userid => $user) {
$studentshtml .= '</tr>';
}
$reporthtml = "<table style=\"text-align: center\" border=\"1\">$headerhtml";
$reporthtml = "<table style=\"text-align: center\">$headerhtml";
$reporthtml .= $studentshtml;
$reporthtml .= "</table>";

View File

@ -57,7 +57,7 @@ $numusers = count(get_role_users(@implode(',', $CFG->gradebookroles), $context))
$grade_items[$item->sortorder] = $item;
}
unset($all_grade_items);
asort($grade_items);
ksort($grade_items);
$total = $grade_items[1];
unset($grade_items[1]);

View File

@ -560,15 +560,15 @@ class grade_category extends grade_object {
* @return array
*/
function fetch_course_tree($courseid, $include_grades=false, $include_category_items=false) {
$sortorder = 1;
$course_category = grade_category::fetch_course_category($courseid);
$course_category->set_sortorder($sortorder);
$course_category->sortorder = $sortorder;
$category_array = array('object'=>$course_category,
$category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
'children'=>$course_category->get_children($include_grades, $include_category_items));
if ($include_grades) {
$category_array['finalgrades'] = $course_category->get_final();
}
$sortorder = 1;
$course_category->set_sortorder($sortorder);
$course_category->sortorder = $sortorder;
return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
}
@ -578,8 +578,8 @@ class grade_category extends grade_object {
$category_array['object']->set_sortorder($sortorder);
}
// store the grade_item or grade_category instance
$result = array('object'=>$category_array['object']);
// store the grade_item or grade_category instance with extra info
$result = array('object'=>$category_array['object'], 'type'=>$category_array['type'], 'depth'=>$category_array['depth']);
// reuse final grades if there
if (array_key_exists('finalgrades', $category_array)) {
@ -590,7 +590,7 @@ class grade_category extends grade_object {
if (!empty($category_array['children'])) {
$result['children'] = array();
foreach($category_array['children'] as $oldorder=>$child_array) {
if (!empty($childarray['object']->itemtype) and ($childarray['object']->itemtype == 'course' or $childarray['object']->itemtype == 'category')) {
if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') {
$result['children'][$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
} else {
$result['children'][++$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
@ -637,6 +637,7 @@ class grade_category extends grade_object {
// prevent problems with duplicate sortorders in db
$sortorder = $item->sortorder;
while(array_key_exists($sortorder, $cats[$categoryid]->children)) {
echo "$sortorder exists in item loop<br>";
$sortorder++;
}
@ -651,6 +652,7 @@ class grade_category extends grade_object {
// prevent problems with duplicate sortorders in db
$sortorder = $cat->sortorder;
while(array_key_exists($sortorder, $cats[$cat->parent]->children)) {
echo "$sortorder exists in cat loop<br>";
$sortorder++;
}
@ -679,25 +681,26 @@ class grade_category extends grade_object {
foreach($category->children as $sortorder=>$child) {
if (array_key_exists('itemtype', $child)) {
$grade_item = new grade_item($child, false);
$children_array[$sortorder] = array('object'=>$grade_item);
if ($include_grades) {
$children_array[$sortorder]['finalgrades'] = $grade_item->get_final();
if (in_array($grade_item->itemtype, array('course', 'category'))) {
$type = $grade_item->itemtype.'item';
$depth = $category->depth;
} else {
$type = 'item';
$depth = $category->depth; // we use this to set the same colour
}
$children_array[$sortorder] = array('object'=>$grade_item, 'type'=>$type, 'depth'=>$depth);
} else {
$children = grade_category::_get_children_recursion($child, $include_grades);
$grade_category = new grade_category($child, false);
if (empty($children)) {
$children_array[$sortorder] = array('object'=>$grade_category);
if ($include_grades) {
$children_array[$sortorder]['finalgrades'] = $grade_category->get_final();
}
} else {
$children_array[$sortorder] = array('object'=>$grade_category, 'children'=>$children);
if ($include_grades) {
$children_array[$sortorder]['finalgrades'] = $grade_category->get_final();
}
$children = array();
}
$children_array[$sortorder] = array('object'=>$grade_category, 'type'=>'category', 'depth'=>$grade_category->depth, 'children'=>$children);
}
if ($include_grades) {
$children_array[$sortorder]['finalgrades'] = $grade_item->get_final();
}
}
@ -842,7 +845,11 @@ class grade_category extends grade_object {
* @return string name
*/
function get_name() {
return $this->fullname;
if (empty($this->parent)) {
return "Top course category"; //TODO: localize
} else {
return $this->fullname;
}
}
/**

View File

@ -978,8 +978,6 @@ class grade_item extends grade_object {
* @return void
*/
function set_sortorder($sortorder) {
global $CFG;
if ($this->sortorder == $sortorder) {
return;
}
@ -995,11 +993,11 @@ class grade_item extends grade_object {
*/
function get_name() {
if ($this->is_course_item()) {
return ('Total course grade'); // TODO: localize
return get_string('total'); // TODO: localize
} else if ($this->is_course_item()) {
} else if ($this->is_category_item()) {
$category = $this->get_category();
return $category->get_name().'(grade)'; // TODO: localize
return 'Category<br />grade'; // TODO: localize
} else {
return $this->itemname;

View File

@ -61,19 +61,20 @@ class grade_tree {
* objects for the given courseid. Full objects are instantiated.
* and renumbering.
* @param int $courseid
* @param boolean $include_grades
* @param boolean $fillers include fillers and colspans, make the levels var "rectabgular"
* @param boolean $include_grades
* @param boolean $include_cagegory_items inclute the items for categories in the tree
*/
function grade_tree($courseid, $include_grades=false, $fillers=true, $include_cagegory_items=false) {
function grade_tree($courseid, $fillers=true, $include_grades=false) {
global $USER;
$this->courseid = $courseid;
$this->include_grades = $include_grades;
$this->commonvars = "&amp;sesskey=$USER->sesskey&amp;id=$this->courseid";
$this->levels = array();
// get course grade tree
$this->tree_array =& grade_category::fetch_course_tree($courseid, $include_grades, $include_cagegory_items);
$this->tree_array =& grade_category::fetch_course_tree($courseid, $include_grades, true);
if ($fillers) {
// inject fake categories == fillers
@ -82,7 +83,6 @@ class grade_tree {
grade_tree::inject_colspans($this->tree_array);
}
$this->levels = array();
grade_tree::fill_levels($this->levels, $this->tree_array, 0);
}
@ -90,22 +90,30 @@ class grade_tree {
/**
* Static recursive helper - fills the levels array, useful when accessing tree elements of one level
*/
function fill_levels(&$levels, &$tree, $depth) {
function fill_levels(&$levels, &$element, $depth) {
if (!array_key_exists($depth, $levels)) {
$levels[$depth] = array();
}
$levels[$depth][] =& $tree;
// prepare unique identifier
if ($element['type'] == 'category') {
$element['eid'] = 'c'.$element['object']->id;
} else if (in_array($element['type'], array('item', 'courseitem', 'categoryitem'))) {
$element['eid'] = 'i'.$element['object']->id;
}
$levels[$depth][] =& $element;
$depth++;
if (empty($tree['children'])) {
if (empty($element['children'])) {
return;
}
$prev = 0;
foreach ($tree['children'] as $sortorder=>$child) {
grade_tree::fill_levels($levels, $tree['children'][$sortorder], $depth);
$tree['children'][$sortorder]['prev'] = $prev;
$tree['children'][$sortorder]['next'] = 0;
foreach ($element['children'] as $sortorder=>$child) {
grade_tree::fill_levels($levels, $element['children'][$sortorder], $depth);
$element['children'][$sortorder]['prev'] = $prev;
$element['children'][$sortorder]['next'] = 0;
if ($prev) {
$tree['children'][$prev]['next'] = $sortorder;
$element['children'][$prev]['next'] = $sortorder;
}
$prev = $sortorder;
}
@ -114,17 +122,17 @@ class grade_tree {
/**
* Static recursive helper - makes full tree (all leafes are at the same level)
*/
function inject_fillers(&$tree, $depth) {
function inject_fillers(&$element, $depth) {
$depth++;
if (empty($tree['children'])) {
if (empty($element['children'])) {
return $depth;
}
$chdepths = array();
$chids = array_keys($tree['children']);
$chids = array_keys($element['children']);
foreach ($chids as $chid) {
$chdepths[$chid] = grade_tree::inject_fillers($tree['children'][$chid], $depth);
$chdepths[$chid] = grade_tree::inject_fillers($element['children'][$chid], $depth);
}
arsort($chdepths);
@ -134,8 +142,8 @@ class grade_tree {
continue;
}
for ($i=0; $i < $maxdepth-$chd; $i++) {
$oldchild =& $tree['children'][$chid];
$tree['children'][$chid] = array('object'=>'filler', 'children'=>array($oldchild));
$oldchild =& $element['children'][$chid];
$element['children'][$chid] = array('object'=>'filler', 'type'=>'filler', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
}
}
@ -145,17 +153,15 @@ class grade_tree {
/**
* Static recursive helper - add colspan information into categories
*/
function inject_colspans(&$tree) {
if (empty($tree['children'])) {
function inject_colspans(&$element) {
if (empty($element['children'])) {
return 1;
}
$count = 0;
foreach ($tree['children'] as $key=>$child) {
$count += grade_tree::inject_colspans($tree['children'][$key]);
}
if ($count > 1) {
$tree['colspan'] = $count - 1;
foreach ($element['children'] as $key=>$child) {
$count += grade_tree::inject_colspans($element['children'][$key]);
}
$element['colspan'] = $count;
return $count;
}

View File

@ -700,6 +700,17 @@ body#grade-index .grades .r1 {
background-color: #f0f0f0;
}
/* new grades css*/
#grade-report .catlevel1 {
background-color: #ffffff;
}
#grade-report .catlevel2 {
background-color: #eeeeee;
}
#grade-report .catlevel3 {
background-color: #dddddd;
}
/***
*** Login
@ -1076,3 +1087,4 @@ form.mform .fdescription.required {
#help .center {
text-align: center;
}

View File

@ -2047,6 +2047,50 @@ body#grade-index .grades .weighted {
margin:0px 20px 0px 20px;
}
/* new grades CSS */
#grade-report table {
border-width:1px;
border-style:solid;
}
#grade-report table td {
border-width:1px;
border-style:solid;
}
#grade-report tr.heading {
border-width:0px 0px 0px 0px;
border-style:solid;
}
#grade-report .heading td {
border-width:0px 0px 0px 0px;
border-style:solid;
}
#grade-report td.category {
border-width:1px 1px 0px 1px;
border-style:solid;
}
#grade-report th.user {
border-width:0px 0px 1px 0px;
border-style:solid;
}
#grade-report th.categoryitem,
#grade-report th.courseitem,
#grade-report td.topleft {
border-width:0px 1px 0px 1px;
border-style:solid;
}
#grade-report th.item {
border-width:1px 1px 1px 1px;
border-style:solid;
}
/* gradebook edit tree */
#grade_edit_tree .movetarget {
position: relative;
@ -3516,3 +3560,4 @@ wikiadminactions {
.workshopkey {
text-align:center;
}