*
* @param int $courseid The current course id.
* @param context $context The course context.
+ * @param string $thispage The relative path for the current page. E.g. /grade/report/user/index.php
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
-function print_natural_aggregation_upgrade_notice($courseid, $context, $return=false) {
+function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage, $return=false) {
global $OUTPUT;
$html = '';
- $show = get_config('core', 'show_sumofgrades_upgrade_' . $courseid);
- if ($show) {
+ $hidesubcatswarning = optional_param('seenaggregatesubcatsupgradedgrades', false, PARAM_BOOL) && confirm_sesskey();
+ $showsubcatswarning = get_config('core', 'show_aggregatesubcats_upgrade_' . $courseid);
+ $hidenaturalwarning = optional_param('seensumofgradesupgradedgrades', false, PARAM_BOOL) && confirm_sesskey();
+ $shownaturalwarning = get_config('core', 'show_sumofgrades_upgrade_' . $courseid);
+
+ // Do not do anything if they are not a teacher.
+ if ($hidesubcatswarning || $showsubcatswarning || $hidenaturalwarning || $shownaturalwarning) {
+ if (!has_capability('moodle/grade:manage', $context)) {
+ return '';
+ }
+ }
+
+ // Hide the warning if the user told it to go away.
+ if ($hidenaturalwarning) {
+ hide_natural_aggregation_upgrade_notice($courseid);
+ }
+ // Hide the warning if the user told it to go away.
+ if ($hidesubcatswarning) {
+ hide_aggregatesubcats_upgrade_notice($courseid);
+ }
+
+ if (!$hidenaturalwarning && $shownaturalwarning) {
$message = get_string('sumofgradesupgradedgrades', 'grades');
$hidemessage = get_string('upgradedgradeshidemessage', 'grades');
$urlparams = array( 'id' => $courseid,
'seensumofgradesupgradedgrades' => true,
'sesskey' => sesskey());
- $goawayurl = new moodle_url('/grade/report/grader/index.php', $urlparams);
+ $goawayurl = new moodle_url($thispage, $urlparams);
$goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get');
$html .= $OUTPUT->notification($message, 'notifysuccess');
$html .= $goawaybutton;
}
- $show = get_config('core', 'show_aggregatesubcats_upgrade_' . $courseid);
- if ($show) {
+ if (!$hidesubcatswarning && $showsubcatswarning) {
$message = get_string('aggregatesubcatsupgradedgrades', 'grades');
$hidemessage = get_string('upgradedgradeshidemessage', 'grades');
$urlparams = array( 'id' => $courseid,
'seenaggregatesubcatsupgradedgrades' => true,
'sesskey' => sesskey());
- $goawayurl = new moodle_url('/grade/report/grader/index.php', $urlparams);
+ $goawayurl = new moodle_url($thispage, $urlparams);
$goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get');
$html .= $OUTPUT->notification($message, 'notifysuccess');
$html .= $goawaybutton;
}
}
+ $returnval .= print_natural_aggregation_upgrade_notice($courseid,
+ context_course::instance($courseid),
+ '/grade/report/' . $active_plugin . '/index.php',
+ $return);
+
if ($return) {
return $returnval;
}
// Print header
print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons);
-// Hide the following warning if the user told it to go away.
-if (optional_param('seensumofgradesupgradedgrades', false, PARAM_BOOL) && confirm_sesskey()) {
- hide_natural_aggregation_upgrade_notice($courseid);
-}
-// Hide the following warning if the user told it to go away.
-if (optional_param('seenaggregatesubcatsupgradedgrades', false, PARAM_BOOL) && confirm_sesskey()) {
- hide_aggregatesubcats_upgrade_notice($courseid);
-}
-// This shows a notice about the upgrade to Natural aggregation.
-print_natural_aggregation_upgrade_notice($COURSE->id, $context);
-
//Initialise the grader report object that produces the table
//the class grade_report_grader_ajax was removed as part of MDL-21562
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);