MDL-10224 fixing some more regressions in grade reports; adding proper CSS; more fixes and improvements

This commit is contained in:
skodak
2007-07-01 19:45:13 +00:00
parent 026eada789
commit 739196ba10
11 changed files with 178 additions and 147 deletions
+17 -4
View File
@@ -87,6 +87,14 @@ switch ($action) {
//TODO: implement deleting in grade items and categories
break;
case 'autosort':
//TODO: implement autosorting based on order of mods on course page, categories first, manual items last
break;
case 'synclegacy':
grade_grab_legacy_grades($course->id);
redirect($returnurl);
case 'move':
if ($eid and confirm_sesskey()) {
$moveafter = required_param('moveafter', PARAM_ALPHANUM);
@@ -145,17 +153,22 @@ switch ($action) {
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
echo '<ul class="grade_tree">';
print_box_start('gradetreebox generalbox');
echo '<ul id="grade_tree">';
print_grade_tree($gtree->top_element, $moving);
echo '</ul>';
print_box_end();
echo '<div class="buttons">';
if ($moving) {
print_single_button('category.php', array('id'=>$course->id), get_string('cancel'), 'get');
} else {
print_single_button('edit_category.php', array('courseid'=>$course->id), get_string('addcategory', 'grades'), 'get');
print_single_button('edit_item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get');
print_single_button('edit_item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get'); // TODO: localize
print_single_button('category.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get'); //TODO: localize
print_single_button('category.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get'); //TODO: localize
}
echo '</div>';
print_footer($course);
die;
@@ -230,7 +243,7 @@ function print_grade_tree($element, $moving) {
/// print the list items now
if ($moving == $eid) {
// do not diplay children
echo '<li class="'.$element['type'].'">'.$icon.$name.'('.get_string('move').')</li>';
echo '<li class="'.$element['type'].' moving">'.$icon.$name.'('.get_string('move').')</li>';
} else if ($element['type'] != 'category') {
echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>'.$moveto;
+25 -2
View File
@@ -2,7 +2,7 @@
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
require_once 'edit_category_form.php';
require_once $CFG->libdir.'/formslib.php';
$courseid = required_param('courseid', PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
@@ -61,4 +61,27 @@ print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriese
$mform->display();
print_footer($course);
die;
die;
class edit_category_form extends moodleform {
function definition() {
$mform =& $this->_form;
// visible elements
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
//TODO: add other elements
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', 0);
$mform->setType('courseid', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
}
@@ -1,26 +0,0 @@
<?php //$Id$
require_once $CFG->libdir.'/formslib.php';
class edit_category_form extends moodleform {
function definition() {
$mform =& $this->_form;
// visible elements
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
//TODO: add other elements
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', 0);
$mform->setType('courseid', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
}
?>
+4
View File
@@ -0,0 +1,4 @@
<?php //$id:$
//TODO: implement
?>
+28 -2
View File
@@ -2,7 +2,7 @@
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
require_once 'edit_item_form.php';
require_once $CFG->libdir.'/formslib.php';
$courseid = required_param('courseid', PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
@@ -61,4 +61,30 @@ print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stritemsedit,
$mform->display();
print_footer($course);
die;
die;
class edit_item_form extends moodleform {
function definition() {
$mform =& $this->_form;
// visible elements
$mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
//TODO: add other elements
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', 0);
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'itemtype', 0);
$mform->setType('itemtype', PARAM_ALPHA);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
}
-29
View File
@@ -1,29 +0,0 @@
<?php //$Id$
require_once $CFG->libdir.'/formslib.php';
class edit_item_form extends moodleform {
function definition() {
$mform =& $this->_form;
// visible elements
$mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
//TODO: add other elements
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', 0);
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'itemtype', 0);
$mform->setType('itemtype', PARAM_ALPHA);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
}
?>
+22 -21
View File
@@ -122,33 +122,25 @@ if (!empty($target) && !empty($action) && confirm_sesskey()) {
case 'hide':
// TODO Implement calendar for selection of a date to hide element until
if (!$element['object']->set_hidden(1)) {
debugging("Could not update the element's hidden state!");
} else {
$gtree = new grade_tree($courseid);
}
$element['object']->set_hidden(1);
$gtree = new grade_tree($courseid);
break;
case 'show':
if (!$element['object']->set_hidden(0)) {
debugging("Could not update the element's hidden state!");
} else {
$gtree = new grade_tree($courseid);
}
$element['object']->set_hidden(0);
$gtree = new grade_tree($courseid);
break;
case 'lock':
// TODO Implement calendar for selection of a date to lock element after
if (!$element['object']->set_locked(1)) {
debugging("Could not update the element's locked state!");
} else {
$gtree = new grade_tree($courseid);
}
$gtree = new grade_tree($courseid);
break;
case 'unlock':
if (!$element['object']->set_locked(0)) {
debugging("Could not update the element's locked state!");
} else {
$gtree = new grade_tree($courseid);
}
$gtree = new grade_tree($courseid);
break;
default:
break;
@@ -306,10 +298,10 @@ foreach ($gtree->levels as $key=>$row) {
}
if ($element['type'] == 'filler') {
$headerhtml .= '<td class="filler'.$catlevel.'" '.$colspan.'>&nbsp;</td>';
if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') {
$headerhtml .= '<td class="'.$type.$catlevel.'" '.$colspan.'>&nbsp;</td>';
} else if ($element['type'] == 'category') {
} else if ($type == 'category') {
$headerhtml .= '<td class="category'.$catlevel.'" '.$colspan.'">'.$element['object']->get_name();
// Print icons
@@ -333,7 +325,7 @@ foreach ($gtree->levels as $key=>$row) {
$dimmed = 'class="dimmed_text"';
}
$headerhtml .= '<th '.$dimmed.' class="'.$element['type'].$catlevel.'"><a href="'.$baseurl.'&amp;sortitemid='
$headerhtml .= '<th '.$dimmed.' class="'.$type.$catlevel.'"><a href="'.$baseurl.'&amp;sortitemid='
. $element['object']->id .'">'. $element['object']->get_name()
. '</a>' . $arrow;
@@ -359,11 +351,11 @@ foreach ($users as $userid => $user) {
if (isset($finalgrades[$userid][$item->id])) {
$gradeval = $finalgrades[$userid][$item->id]->finalgrade;
$grade_grades = new grade_grades($finalgrades[$userid][$item->id], false);
$grade_grades->feedback = $finalgrades[$userid][$item->id]->feedback;
$grade = new grade_grades($finalgrades[$userid][$item->id], false);
$grade->feedback = $finalgrades[$userid][$item->id]->feedback;
} else {
$gradeval = '-';
$grade_grades = new grade_grades(array('userid' => $userid, 'itemid' => $item->id), false);
$grade = new grade_grades(array('userid' => $userid, 'itemid' => $item->id), false);
}
// if in editting mode, we need to print either a text box
@@ -408,6 +400,15 @@ foreach ($users as $userid => $user) {
}
}
// Do not show any icons if no grade (no record in DB to match)
if (!empty($grade->id)) {
// emulate grade element
$grade->courseid = $course->id;
$grade->grade_item = $item; // this may speedup is_hidden() and other grade_grades methods
$element = array ('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade');
$studentshtml .= grade_get_icons($element, $gtree);
}
$studentshtml .= '</td>' . "\n";
}
$studentshtml .= '</tr>';
+1
View File
@@ -522,6 +522,7 @@ class grade_item extends grade_object {
/**
* Set the hidden status of grade_item and all grades, 0 mean visible, 1 always hidden, number means date to hide until.
* @param int $hidden new hidden status
* @return void
*/
function set_hidden($hidden) {
$this->hidden = $hidden;
+25 -23
View File
@@ -130,6 +130,8 @@ class grade_tree {
}
$chdepths = array();
$chids = array_keys($element['children']);
$last_child = end($chids);
$first_child = reset($chids);
foreach ($chids as $chid) {
$chdepths[$chid] = grade_tree::inject_fillers($element['children'][$chid], $depth);
@@ -142,8 +144,15 @@ class grade_tree {
continue;
}
for ($i=0; $i < $maxdepth-$chd; $i++) {
if ($chid == $first_child) {
$type = 'fillerfirst';
} else if ($chid == $last_child) {
$type = 'fillerlast';
} else {
$type = 'filler';
}
$oldchild =& $element['children'][$chid];
$element['children'][$chid] = array('object'=>'filler', 'type'=>'filler', 'eid'=>'', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
$element['children'][$chid] = array('object'=>'filler', 'type'=>$type, 'eid'=>'', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
}
}
@@ -172,6 +181,21 @@ class grade_tree {
* @return object element
*/
function locate_element($eid) {
if (strpos($eid, 'g') === 0) {
// it is a grade construct a new object
$id = (int)substr($eid, 1);
if (!$grade = grade_grades::fetch(array('id'=>$id))) {
return null;
}
//extra security check - the grade item must be in this tree
if (!$item_el = $this->locate_element('i'.$grade->itemid)) {
return null;
}
$grade->grade_item =& $item_el['object']; // this may speedup grade_grades methods!
return array('eid'=>'g'.$id,'object'=>$grade, 'type'=>'grade');
}
// it is a category or item
foreach ($this->levels as $row) {
foreach ($row as $element) {
if ($element['type'] == 'filler') {
@@ -186,26 +210,4 @@ class grade_tree {
return null;
}
/**
* Given an element object, returns its type (topcat, subcat or item).
* The $element can be a straight object (fully instantiated), an array of 'object' and 'children'/'final_grades', or a stdClass element
* as produced by grade_tree::locate_element(). This method supports all three types of inputs.
* @param object $element
* @return string Type
*/
function get_element_type($element) {
if ($element['object'] == 'filler') {
return 'filler';
}
if (get_class($element['object']) == 'grade_category') {
if ($element['object']->depth == 2) {
return 'topcat';
} else {
return 'subcat';
}
}
return 'item';
}
}
+16 -3
View File
@@ -391,8 +391,9 @@ function grade_update_final_grades($courseid, $regradeall=false) {
/**
* For backwards compatibility with old third-party modules, this function can
* be used to import all grades from activities with legacy grading.
* @param int $courseid or null if all courses
*/
function grade_grab_legacy_grades() {
function grade_grab_legacy_grades($courseid=null) {
global $CFG;
@@ -400,6 +401,12 @@ function grade_grab_legacy_grades() {
error('No modules installed!');
}
if ($courseid) {
$course_sql = " AND cm.course=$courseid";
} else {
$course_sql = "";
}
foreach ($mods as $mod) {
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
@@ -429,7 +436,7 @@ function grade_grab_legacy_grades() {
// get all instance of the activity
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
FROM {$CFG->prefix}$mod a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='$mod' AND m.id=cm.module AND cm.instance=a.id";
WHERE m.name='$mod' AND m.id=cm.module AND cm.instance=a.id $course_sql";
if ($modinstances = get_records_sql($sql)) {
foreach ($modinstances as $modinstance) {
@@ -724,10 +731,16 @@ function grade_get_icons($element, $tree) {
$html .= '<a href="report/grader/edit_category.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
} else {
} else if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') {
$html .= '<a href="report/grader/edit_item.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
} else if ($type == 'grade') {
$html .= '<a href="report/grader/edit_grade.php?courseid='.$object->courseid.'&amp;id='.$object->id.'">';
$html .= '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'
.$stredit.'" title="'.$stredit.'" /></a>'. "\n";
}
// Prepare Hide/Show icon state
+40 -37
View File
@@ -2047,6 +2047,7 @@ body#grade-index .grades .weighted {
margin:0px 20px 0px 20px;
}
/* new grades CSS */
#grade-report table {
@@ -2086,66 +2087,68 @@ body#grade-index .grades .weighted {
border-style:solid;
}
#grade-report td.fillerfirst {
border-width:0px 0px 0px 1px;
border-style:solid;
}
#grade-report td.fillerlast {
border-width:0px 1px 0px 0px;
border-style:solid;
}
#grade-report th.item {
border-width:1px 1px 1px 1px;
border-style:solid;
}
/* gradebook edit tree */
#grade_edit_tree .movetarget {
#grade-report-grader-category .gradetreebox {
width:70%;
margin-left:auto;
margin-right:auto;
margin-top:10px;
padding-bottom:15px;
}
#grade-report-grader-category .buttons {
margin: 20px;
text-align:center;
}
#grade-report-grader-category .buttons .singlebutton {
display: inline;
padding: 5px;
}
#grade-report-grader-category .movetarget {
position: relative;
width: 80px;
height: 16px;
}
#content ul#grade_edit_tree {
#grade-report-grader-category ul#grade_tree {
width: auto;
}
#grade_edit_tree li {
#grade-report-grader-category ul#grade_tree li {
list-style: none;
margin-top: 8px;
}
#grade_edit_tree li div.moduleicon {
margin-right: 5px;
display: inline;
#grade-report-grader-category ul#grade_tree li.category {
margin-bottom: 6px;
}
#grade_edit_tree li div.select_checkbox {
margin-right: 5px;
display: inline;
}
#grade_edit_tree li.insertion {
cursor: pointer;
}
#grade_edit_tree .moveuparrow {
cursor: pointer;
}
#grade_edit_tree .movedownarrow {
cursor: pointer;
}
#grade_edit_tree form.movearrow div {
display: inline;
}
#grade_edit_tree form.movearrow {
display: inline;
}
#grade_edit_tree .selected_element {
#grade-report-grader-category .moving {
background-color: #E8EEF7;
}
#grade_edit_tree .icons {
position: relative;
display: inline;
margin-left: 10px;
#grade-report-grader-category .iconsmall {
margin-left: 4px;
}
/***
*** Login
***/