MDL-47503 Grades: Display the notice about upgraded grades on all grade report pages.
authorDamyon Wiese <damyon@moodle.com>
Mon, 20 Oct 2014 08:14:07 +0000 (16:14 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 20 Oct 2014 08:15:51 +0000 (16:15 +0800)
Moved this to the print_grade_page_head function and added an access check so it only
displays for teachers.

grade/lib.php
grade/report/grader/index.php

index 6b5a996..1b8c824 100644 (file)
@@ -481,35 +481,55 @@ function hide_aggregatesubcats_upgrade_notice($courseid) {
  *
  * @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;
@@ -875,6 +895,11 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null,
         }
     }
 
+    $returnval .= print_natural_aggregation_upgrade_notice($courseid,
+                                                           context_course::instance($courseid),
+                                                           '/grade/report/' . $active_plugin . '/index.php',
+                                                           $return);
+
     if ($return) {
         return $returnval;
     }
index d0aee19..822a758 100644 (file)
@@ -128,17 +128,6 @@ $reportname = get_string('pluginname', 'gradereport_grader');
 // 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);