*/
var $rowcount = 0;
+ /**
+ * Capability check caching
+ * */
+ var $canviewhidden;
+
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $courseid
global $CFG;
parent::grade_report($courseid, $gpr, $context, $page);
+ $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
+
// load collapsed settings for this report
if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) {
$this->collapsed = unserialize($collapsed);
}
}
- $html .= $this->print_toggle('averages', true);
+ if ($this->canviewhidden) {
+ $html .= $this->print_toggle('averages', true);
+ }
if (has_capability('moodle/grade:viewall', $this->context)
and has_capability('moodle/site:accessallgroups', $this->context)
$scales_array = get_records_list('scale', 'id', $scales_list);
}
- $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
-
foreach ($this->users as $userid => $user) {
- if ($canviewhidden) {
+ if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
// MDL-11274
// Hide grades in the grader report if the current grader doesn't have 'moodle/grade:viewhidden'
- if (!$canviewhidden and $grade->is_hidden()) {
+ if (!$this->canviewhidden and $grade->is_hidden()) {
if (!empty($CFG->grade_hiddenasdate) and !is_null($grade->finalgrade) and !$item->is_category_item() and !$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
$studentshtml .= '<td class="cell c'.$columncount++.'">'.userdate($grade->timecreated,get_string('strftimedatetimeshort')).'</td>';
function get_avghtml($grouponly=false) {
global $CFG, $USER;
+ if (!$this->canviewhidden) {
+ // totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered
+ // better not show them at all if user can not see all hideen grades
+ return;
+ }
+
$averagesdisplaytype = $this->get_pref('averagesdisplaytype');
$averagesdecimalpoints = $this->get_pref('averagesdecimalpoints');
$meanselection = $this->get_pref('meanselection');
$shownumberofgrades = $this->get_pref('shownumberofgrades');
- $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
-
- if ($canviewhidden) {
- $hidingsql1 = "";
- $hidingsql2 = "";
-
- } else {
- $now = round(time(), -2); //100 sec gradularity, we need some db caching speedup here
- $hidingsql1 = "AND g.hidden!=1 AND (g.hidden=0 OR g.hidden<$now)";
- //$hidingsql2 = "OR (g.hidden!=1 AND (g.hidden=0 OR g.hidden<$now))";
- }
-
$avghtml = '';
$avgcssclass = 'avg';
{$CFG->prefix}user u ON g.userid = u.id
$groupsql
WHERE gi.courseid = $this->courseid
- $hidingsql1
$groupwheresql
AND g.userid IN (
SELECT DISTINCT(u.id)
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
- // If the user shouldn't see this grade_item, hide the average as well
- // MDL-11576 If any of the grades are hidden and the user doesn't have permission to view them, hide average as well
- if (!$canviewhidden and $item->is_hidden()) {
- $avghtml .= '<td class="cell c' . $columncount++.'"> - </td>';
- continue;
- }
-
if (empty($sum_array[$item->id])) {
$sum_array[$item->id] = 0;
}
// MDL-10875 Empty grades must be evaluated as grademin, NOT always 0
// This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
- // optionally plus number of hidden grades
$SQL = "SELECT COUNT(*) AS count FROM {$CFG->prefix}user u
WHERE u.id NOT IN
(SELECT userid FROM {$CFG->prefix}grade_grades g
- WHERE g.itemid = $item->id AND
- (g.finalgrade IS NOT NULL $hidingsql1)
+ WHERE g.itemid = $item->id AND g.finalgrade IS NOT NULL
)
AND u.id IN (
SELECT DISTINCT(u.id)
$stryes = get_string('yes');
$strno = get_string('no');
+ $canviewhidden = has_capability('moodle/grade:viewhidden', $context);
+
$checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', 0 => $strno, 1 => $stryes);
GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY => get_string('gradesonly', 'grades')));
- $preferences['prefshow'] = array('showcalculations' => $checkbox_default,
- 'showeyecons' => $checkbox_default,
- 'showaverages' => $checkbox_default,
- 'showgroups' => $checkbox_default,
- 'showlocks' => $checkbox_default);
+ $preferences['prefshow'] = array();
+ $preferences['prefshow']['showcalculations'] = $checkbox_default;
+ $preferences['prefshow']['showeyecons'] = $checkbox_default;
+ if ($canviewhidden) {
+ $preferences['prefshow']['showaverages'] = $checkbox_default;
+ }
+ $preferences['prefshow']['showgroups'] = $checkbox_default;
+ $preferences['prefshow']['showlocks'] = $checkbox_default;
$preferences['prefrows'] = array(
'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
- 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
- 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
- GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
- GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
- GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
- GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
- 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
- GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
- 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
- 'meanselection' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
- GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'),
- GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades')));
- $advanced = array_merge($advanced, array('rangesdisplaytype', 'rangesdecimalpoints', 'averagesdisplaytype', 'averagesdecimalpoints'));
+ 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5));
+ $advanced = array_merge($advanced, array('rangesdisplaytype', 'rangesdecimalpoints'));
+
+ if ($canviewhidden) {
+ $preferences['prefrows']['averagesdisplaytype'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
+ GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
+ GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
+ GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
+ $preferences['prefrows']['averagesdecimalpoints'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
+ 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
+ $preferences['prefrows']['meanselection'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'),
+ GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades'));
+
+ $advanced = array_merge($advanced, array('averagesdisplaytype', 'averagesdecimalpoints'));
+ }
}
// quickgrading and quickfeedback are conditional on grade:edit capability
$preferences['prefshow']['showactivityicons'] = $checkbox_default;
$preferences['prefshow']['showranges'] = $checkbox_default;
- $preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
+ if ($canviewhidden) {
+ $preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
+ }
$advanced = array_merge($advanced, array('aggregationposition'));
}