Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-34164 quiz reports: only try to show graphs if GD is installed.

if (empty($CFG->gdversion)) { seems to be the common idiom for this.
I refactored the graph output into the renderer, to avoid having to
duplicate that test three times.

Conflicts:

	mod/quiz/report/overview/report.php
  • Loading branch information...
commit 03c558af10e25950c9540e27654f9936099b496d 1 parent 9a7c3d5
Tim Hunt authored July 14, 2012
18  mod/quiz/renderer.php
@@ -1108,6 +1108,24 @@ public function quiz_attempt_summary_link_to_reports($quiz, $cm, $context,
1108 1108
                 'id' => $cm->id, 'mode' => quiz_report_default_report($context)));
1109 1109
         return html_writer::link($url, $summary);
1110 1110
     }
  1111
+
  1112
+    /**
  1113
+     * Output a graph, or a message saying that GD is required.
  1114
+     * @param moodle_url $url the URL of the graph.
  1115
+     * @param string $title the title to display above the graph.
  1116
+     * @return string HTML fragment for the graph.
  1117
+     */
  1118
+    public function graph(moodle_url $url, $title) {
  1119
+        global $CFG;
  1120
+
  1121
+        if (empty($CFG->gdversion)) {
  1122
+            $graph = get_string('gdneed');
  1123
+        } else {
  1124
+            $graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title));
  1125
+        }
  1126
+
  1127
+        return $this->heading($title) . html_writer::tag('div', $graph, array('class' => 'graph'));
  1128
+    }
1111 1129
 }
1112 1130
 
1113 1131
 class mod_quiz_links_to_other_attempts implements renderable {
21  mod/quiz/report/overview/report.php
@@ -40,7 +40,7 @@
40 40
 class quiz_overview_report extends quiz_attempt_report {
41 41
 
42 42
     public function display($quiz, $cm, $course) {
43  
-        global $CFG, $COURSE, $DB, $OUTPUT;
  43
+        global $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
44 44
 
45 45
         $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
46 46
 
@@ -330,30 +330,25 @@ public function display($quiz, $cm, $course) {
330 330
         }
331 331
 
332 332
         if (!$table->is_downloading() && $this->should_show_grades($quiz)) {
  333
+            $output = $PAGE->get_renderer('mod_quiz');
333 334
             if ($currentgroup && $groupstudents) {
334 335
                 list($usql, $params) = $DB->get_in_or_equal($groupstudents);
335 336
                 $params[] = $quiz->id;
336 337
                 if ($DB->record_exists_select('quiz_grades', "userid $usql AND quiz = ?",
337 338
                         $params)) {
338  
-                     $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php',
  339
+                    $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php',
339 340
                             array('id' => $quiz->id, 'groupid' => $currentgroup));
340  
-                     $graphname = get_string('overviewreportgraphgroup', 'quiz_overview',
  341
+                    $graphname = get_string('overviewreportgraphgroup', 'quiz_overview',
341 342
                             groups_get_group_name($currentgroup));
342  
-                     echo $OUTPUT->heading($graphname);
343  
-                     echo html_writer::tag('div', html_writer::empty_tag('img',
344  
-                            array('src' => $imageurl, 'alt' => $graphname)),
345  
-                            array('class' => 'graph'));
  343
+                    echo $output->graph($imageurl, $graphname);
346 344
                 }
347 345
             }
348 346
 
349 347
             if ($DB->record_exists('quiz_grades', array('quiz'=> $quiz->id))) {
350  
-                 $graphname = get_string('overviewreportgraph', 'quiz_overview');
351  
-                 $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php',
  348
+                $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php',
352 349
                         array('id' => $quiz->id));
353  
-                 echo $OUTPUT->heading($graphname);
354  
-                 echo html_writer::tag('div', html_writer::empty_tag('img',
355  
-                        array('src' => $imageurl, 'alt' => $graphname)),
356  
-                        array('class' => 'graph'));
  350
+                $graphname = get_string('overviewreportgraph', 'quiz_overview');
  351
+                echo $output->graph($imageurl, $graphname);
357 352
             }
358 353
         }
359 354
         return true;
9  mod/quiz/report/statistics/report.php
@@ -581,18 +581,17 @@ protected function download_quiz_info_table($quizinfo) {
581 581
      * @param int $quizstatsid the id of the statistics to show in the graph.
582 582
      */
583 583
     protected function output_statistics_graph($quizstatsid, $s) {
584  
-        global $OUTPUT;
  584
+        global $PAGE;
585 585
 
586 586
         if ($s == 0) {
587 587
             return;
588 588
         }
589 589
 
  590
+        $output = $PAGE->get_renderer('mod_quiz');
590 591
         $imageurl = new moodle_url('/mod/quiz/report/statistics/statistics_graph.php',
591 592
                 array('id' => $quizstatsid));
592  
-        $OUTPUT->heading(get_string('statisticsreportgraph', 'quiz_statistics'));
593  
-        echo html_writer::tag('div', html_writer::empty_tag('img', array('src' => $imageurl,
594  
-                'alt' => get_string('statisticsreportgraph', 'quiz_statistics'))),
595  
-                array('class' => 'graph'));
  593
+        $graphname = get_string('statisticsreportgraph', 'quiz_statistics');
  594
+        echo $output->graph($imageurl, $graphname);
596 595
     }
597 596
 
598 597
     /**

0 notes on commit 03c558a

Please sign in to comment.
Something went wrong with that request. Please try again.