MDL-59265 report_insights: Fix PHP notice when no predictions
authorDavid Monllao <davidm@moodle.com>
Mon, 14 Aug 2017 13:12:27 +0000 (15:12 +0200)
committerDavid Monllao <davidm@moodle.com>
Fri, 25 Aug 2017 11:16:20 +0000 (13:16 +0200)
report/insights/classes/output/insights_list.php

index 71d7fed..3f67c4a 100644 (file)
@@ -91,12 +91,16 @@ class insights_list implements \renderable, \templatable {
         $total = 0;
 
         if ($this->model->uses_insights()) {
-            list($total, $predictions) = $this->model->get_predictions($this->context, $this->page, $this->perpage);
+            $predictionsdata = $this->model->get_predictions($this->context, $this->page, $this->perpage);
 
             $data->insights = array();
-            foreach ($predictions as $prediction) {
-                $insightrenderable = new \report_insights\output\insight($prediction, $this->model, true);
-                $data->insights[] = $insightrenderable->export_for_template($output);
+            if ($predictionsdata) {
+                list($total, $predictions) = $predictionsdata;
+
+                foreach ($predictions as $prediction) {
+                    $insightrenderable = new \report_insights\output\insight($prediction, $this->model, true);
+                    $data->insights[] = $insightrenderable->export_for_template($output);
+                }
             }
 
             if (empty($data->insights) && $this->page == 0) {