Skip to content

Commit

Permalink
gradebook MDL-21514 Ironed out a bug with hiding course totals
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed Feb 12, 2010
1 parent 623c8fd commit 1762a26
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 85 deletions.
167 changes: 83 additions & 84 deletions grade/report/user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,105 +238,104 @@ private function fill_table_recursive(&$element) {
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
// return false;
} else {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' ['.get_string('excluded', 'grades').']';
$excluded = ' excluded';
}

/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' ['.get_string('excluded', 'grades').']';
$excluded = ' excluded';
}

/// Other class information
$class = "$hidden $excluded";
if ($this->switch) { // alter style based on whether aggregation is first or last
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " ".$alter."d$depth baggt b2b" : " item b1b";
} else {
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " ".$alter."d$depth baggb" : " item b1b";
}
/// Other class information
$class = "$hidden $excluded";
if ($this->switch) { // alter style based on whether aggregation is first or last
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " ".$alter."d$depth baggt b2b" : " item b1b";
} else {
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " ".$alter."d$depth baggb" : " item b1b";
}

/// Name
$data['itemname']['content'] = $fullname;
$data['itemname']['class'] = $class;
$data['itemname']['colspan'] = ($this->maxdepth - $depth);

/// Actual Grade
$gradeval = $grade_grade->finalgrade;
if ($grade_grade->grade_item->needsupdate) {
$data['grade']['class'] = $class.' gradingerror';
$data['grade']['content'] = get_string('error');
} else if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$this->canviewhidden and $grade_grade->is_hidden()
and !$grade_grade->grade_item->is_category_item() and !$grade_grade->grade_item->is_course_item()) {
// the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
$class .= ' datesubmitted';
$data['grade']['class'] = $class;
$data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));

} elseif ($grade_grade->is_hidden()) {
$data['grade']['class'] = $class.' hidden';
$data['grade']['content'] = '-';
} else {
$data['grade']['class'] = $class;
$gradeval = $this->blank_hidden_total($this->courseid, $grade_grade->grade_item, $gradeval);
$data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
}
/// Name
$data['itemname']['content'] = $fullname;
$data['itemname']['class'] = $class;
$data['itemname']['colspan'] = ($this->maxdepth - $depth);

/// Percentage
if ($this->showpercentage) {
/// Actual Grade
$gradeval = $grade_grade->finalgrade;
if ($grade_grade->grade_item->needsupdate) {
$data['percentage']['class'] = $class.' gradingerror';
$data['percentage']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['percentage']['class'] = $class.' hidden';
$data['percentage']['content'] = '-';
$data['grade']['class'] = $class.' gradingerror';
$data['grade']['content'] = get_string('error');
} else if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$this->canviewhidden and $grade_grade->is_hidden()
and !$grade_grade->grade_item->is_category_item() and !$grade_grade->grade_item->is_course_item()) {
// the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
$class .= ' datesubmitted';
$data['grade']['class'] = $class;
$data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));

} elseif ($grade_grade->is_hidden()) {
$data['grade']['class'] = $class.' hidden';
$data['grade']['content'] = '-';
} else {
$data['percentage']['class'] = $class;
$data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
$data['grade']['class'] = $class;
$gradeval = $this->blank_hidden_total($this->courseid, $grade_grade->grade_item, $gradeval);
$data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
}
}

/// Rank
if ($this->showrank) {
// TODO: this is broken if hidden grades present!!
if ($grade_grade->grade_item->needsupdate) {
$data['rank']['class'] = $class.' gradingerror';
$data['rank']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['rank']['class'] = $class.' hidden';
/// Percentage
if ($this->showpercentage) {
if ($grade_grade->grade_item->needsupdate) {
$data['percentage']['class'] = $class.' gradingerror';
$data['percentage']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['percentage']['class'] = $class.' hidden';
$data['percentage']['content'] = '-';
} else {
$data['percentage']['class'] = $class;
$data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
}
}

/// Rank
if ($this->showrank) {
// TODO: this is broken if hidden grades present!!
if ($grade_grade->grade_item->needsupdate) {
$data['rank']['class'] = $class.' gradingerror';
$data['rank']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['rank']['class'] = $class.' hidden';
$data['rank']['content'] = '-';
} else if (is_null($gradeval)) {
// no grade, no rank
$data['rank']['class'] = $class;
$data['rank']['content'] = '-';
} else if (is_null($gradeval)) {
// no grade, no rank
$data['rank']['class'] = $class;
$data['rank']['content'] = '-';

} else {
/// find the number of users with a higher grade
$sql = "SELECT COUNT(DISTINCT(userid))
FROM {grade_grades}
WHERE finalgrade > ?
AND itemid = ?";
$rank = $DB->count_records_sql($sql, array($grade_grade->finalgrade, $grade_grade->grade_item->id)) + 1;

$data['rank']['class'] = $class;
$data['rank']['content'] = "$rank/".$this->get_numusers(false); // total course users
} else {
/// find the number of users with a higher grade
$sql = "SELECT COUNT(DISTINCT(userid))
FROM {grade_grades}
WHERE finalgrade > ?
AND itemid = ?";
$rank = $DB->count_records_sql($sql, array($grade_grade->finalgrade, $grade_grade->grade_item->id)) + 1;

$data['rank']['class'] = $class;
$data['rank']['content'] = "$rank/".$this->get_numusers(false); // total course users
}
}
}

/// Feedback
if (empty($grade_grade->feedback) or (!$this->canviewhidden and $grade_grade->is_hidden())) {
$data['feedback']['class'] = $class.' feedbacktext';
$data['feedback']['content'] = ' ';
/// Feedback
if (empty($grade_grade->feedback) or (!$this->canviewhidden and $grade_grade->is_hidden())) {
$data['feedback']['class'] = $class.' feedbacktext';
$data['feedback']['content'] = ' ';

} else {
$data['feedback']['class'] = $class.' feedbacktext';
$data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
}
} else {
$data['feedback']['class'] = $class.' feedbacktext';
$data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
}

/// Range
if ($this->showrange) {
$data['range']['class'] = $class;
$data['range']['content'] = $grade_grade->grade_item->get_formatted_range();
/// Range
if ($this->showrange) {
$data['range']['class'] = $class;
$data['range']['content'] = $grade_grade->grade_item->get_formatted_range();
}
}
}
}

/// Category
if ($type == 'category') {
Expand Down
2 changes: 1 addition & 1 deletion lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ public function set_locked($lockedstate, $cascade=false, $refresh=true) {
public function set_hidden($hidden, $cascade=false) {
$this->load_grade_item();
//this hides the associated grade item (the course total)
$this->grade_item->set_hidden($hidden);
$this->grade_item->set_hidden($hidden, $cascade);
//this hides the category itself and everything it contains
parent::set_hidden($hidden, $cascade);

Expand Down

0 comments on commit 1762a26

Please sign in to comment.