some fixes for grader report

This commit is contained in:
toyomoyo 2007-06-26 07:32:31 +00:00
parent 0e4743c847
commit 7f331f8914
4 changed files with 150 additions and 22 deletions

View File

@ -28,7 +28,7 @@
$courseid = required_param('id'); // course id
$report = optional_param('report', 'user', PARAM_FILE); // course id
$edit = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
/// Make sure they can even access this course
@ -84,11 +84,40 @@
$crumbs[] = array('name' => $strgrades, 'link' => '', 'type' => 'misc');
$crumbs[] = array('name' => $reportnames[$report], 'link' => '', 'type' => 'misc');
$navigation = build_navigation($crumbs);
$navigation = build_navigation($crumbs);
// build buttons here
/// setting up editting mode
if (!isset($USER->gradeediting)) {
$USER->gradeediting = 0;
}
if (($edit == 1) and confirm_sesskey()) {
$USER->gradeediting = 1;
} else if (($edit == 0) and confirm_sesskey()) {
$USER->gradeediting = 0;
}
// params for the turn editting on button
$options['id'] = $courseid;
$options['report'] = $report;
if ($USER->gradeediting) {
$options['edit'] = 0;
$string = get_string('turneditingoff');
} else {
$options['edit'] = 1;
$string = get_string('turneditingon');
}
$options['sesskey'] = sesskey();
$link = 'report.php';
// turn eidtting on and off buttons
$buttons = print_single_button($link, $options, $string, 'get', '_self', true);
print_header_simple($strgrades.':'.$reportnames[$report], ':'.$strgrades, $navigation,
'', '', true, '', navmenu($course));
'', '', true, $buttons, navmenu($course));
/// Print the report selector at the top if there is more than one report

View File

@ -64,7 +64,7 @@ $crumbs[] = array('name' => $strcategoriesedit, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($crumbs);
print_header_simple($strgrades.': '.$strgraderreport.': '.$strcategoriesedit, $navigation,
zprint_header_simple($strgrades.': '.$strgraderreport.': '.$strcategoriesedit, $navigation,
'', '', true, '', navmenu($course));
$tree = new grade_tree($param->courseid);

View File

@ -5,12 +5,47 @@
require_once($CFG->libdir.'/tablelib.php');
include_once($CFG->libdir.'/gradelib.php');
/// processing posted grades here
if ($data = data_submitted()) {
foreach ($data as $varname => $postedgrade) {
// skip, not a grade
if (!strstr($varname, 'grade')) {
continue;
}
// clean
$postedgrade = clean_param($postedgrade, PARAM_NUMBER);
$gradeinfo = explode("_", $varname);
$grade = new object();
$grade->userid = $gradeinfo[1];
$gradeitemid = $gradeinfo[2];
$grade->rawgrade = $postedgrade;
// put into grades array
$grades[$gradeitemid][] = $grade;
}
}
// now we update the raw grade for each posted grades
if (!empty($grades)) {
foreach ($grades as $gradeitemid => $itemgrades) {
foreach ($itemgrades as $gradedata) {
echo "gradeitemid is $gradeitemid";
$gradeitem = new grade_item(array('id'=>$gradeitemid), true);
$gradeitem->update_raw_grade($gradedata->userid, $gradedata->rawgrade);
}
}
}
// get the params
$courseid = required_param('id', PARAM_INT);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$page = optional_param('page', 0, PARAM_INT);
$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
$report = optional_param('report', 0, PARAM_ALPHANUM);
$perpage = optional_param('perpage', 3, PARAM_INT); // number of users on a page
// setting the sort order, this depends on last state
// all this should be in the new table class that we might need to use
@ -39,18 +74,24 @@ if ($sortitemid) {
$SESSION->gradeuserreport->sortitemid = $sortitemid;
} else {
// not requesting sort, use last setting (for paging)
$sortitemid = $SESSION->gradeuserreport->sortitemid;
$sortorder = $SESSION->gradeuserreport->sort;
if (isset($SESSION->gradeuserreport->sortitemid)) {
$sortitemid = $SESSION->gradeuserreport->sortitemid;
}
if (isset($SESSION->gradeuserreport->sort)) {
$sortorder = $SESSION->gradeuserreport->sort;
} else {
$sortorder = 'ASC';
}
}
/// end of setting sort order code
// first make sure we have all final grades
// TODO: check that no grade_item has needsupdate set
grade_update_final_grades($courseid);
$perpage = 3;
// roles to be displaye in the gradebook
$gradebookroles = $CFG->gradebookroles;
@ -124,23 +165,22 @@ print_paging_bar($numusers, $page, $perpage, $pbarurl);
if ($gtree = new grade_tree($courseid, false)) {
// 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
$tree = $gtree->tree_filled;
$tree = $gtree->tree_filled;
if (empty($gtree->tree_filled)) {
debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
return false;
}
// Fetch array of students enroled in this course
if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
return false;
return false;
}
//$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 ($sortitemid === 'lastname') {
if ($sortorder == 'ASC') {
$lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
} else {
@ -150,7 +190,7 @@ if ($gtree = new grade_tree($courseid, false)) {
$lastarrow = '';
}
if ($sortitemid == 'firstname') {
if ($sortitemid === 'firstname') {
if ($sortorder == 'ASC') {
$firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
} else {
@ -212,14 +252,56 @@ if ($gtree = new grade_tree($courseid, false)) {
foreach ($users as $userid => $user) {
$studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
foreach ($items as $item) {
// finalgrades[$userid][$itemid] could be null because of the outer join
// in this case it's different than a 0
$studentshtml .= '<td>';
if (isset($finalgrades[$userid][$item['object']->id])) {
$studentshtml .= '<td>' . $finalgrades[$userid][$item['object']->id] . '</td>' . "\n";
$gradeval = $finalgrades[$userid][$item['object']->id];
} else {
$studentshtml .= '<td>-</td>' . "\n";
$gradeval = '-';
}
}
// if in editting mode, we need to print either a text box
// or a drop down (for scales)
if ($USER->gradeediting) {
if ($item['object']->scaleid) {
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
$scales = explode(",", $scale->scale);
// reindex because scale is off 1
$i = 0;
foreach ($scales as $scaleoption) {
$i++;
$scaleopt[$i] = $scaleoption;
}
$studentshtml .= choose_from_menu ($scaleopt, 'grade_'.$userid.'_'.$item['object']->id, $gradeval, get_string('nograde'), '', -1, true);
}
} else {
$studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
}
} else {
// finalgrades[$userid][$itemid] could be null because of the outer join
// in this case it's different than a 0
if ($item['object']->scaleid) {
if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
$scales = explode(",", $scale->scale);
// invalid grade if gradeval < 1
if ((int) $gradeval < 1) {
$studentshtml .= '-';
} else {
$studentshtml .= $scales[$gradeval-1];
}
} else {
// no such scale, throw error?
}
} else {
$studentshtml .= $gradeval;
}
}
$studentshtml .= '</td>' . "\n";
}
$studentshtml .= '</tr>';
}
@ -230,8 +312,24 @@ if ($gtree = new grade_tree($courseid, false)) {
$reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
$reporthtml .= $studentshtml;
$reporthtml .= "</table>";
// print submit button
if ($USER->gradeediting) {
echo '<form action="report.php" method="POST">';
echo '<div>';
echo '<input type="hidden" value="'.$courseid.'" name="id" />';
echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
echo '<input type="hidden" value="grader" name="report"/>';
}
echo $reporthtml;
// print submit button
if ($USER->gradeediting) {
echo '<input type="submit" value="'.get_string('update').'" />';
echo '</div></form>';
}
}
?>

View File

@ -9,7 +9,7 @@ include_once($CFG->libdir.'/gradelib.php');
$courseid = required_param('id', PARAM_INT);
if (!$userid = optional_param('user', 0, PARAM_INT)) {
// current user
$userid = $USER->id;
$userid = $USER->id;
}
@ -22,7 +22,7 @@ if ($gradetree = new grade_tree($courseid)) {
* Table has 6 columns
*| pic | itemname/description | grade (grade_final) | percentage | rank | feedback |
*/
$baseurl = $CFG->wwwroot.'/grade/report?id='.$id.'&amp;userid='.$userid;
$baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&amp;userid='.$userid;
// setting up table headers
$tablecolumns = array('itempic', 'itemname', 'grade', 'percentage', 'rank', 'feedback');
@ -88,6 +88,7 @@ if ($gradetree = new grade_tree($courseid)) {
if ($gradeitem->gradetype == 1) {
// processing numeric grade
if ($grade_grades->finalgrade) {
$percentage = (($grade_grades->finalgrade / $gradeitem->grademax) * 100).'%';
} else {
$percentage = '-';
}