From 21d4ae93531496dffcf5ff4a8c4e3e0db818e21a Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 21 Jun 2017 21:17:48 +0200 Subject: [PATCH] MDL-59060 analytics: Allow all predictions to be retrieved Part of MDL-57791 epic. --- analytics/classes/model.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/analytics/classes/model.php b/analytics/classes/model.php index d90413e4873..2999767ca86 100644 --- a/analytics/classes/model.php +++ b/analytics/classes/model.php @@ -1001,11 +1001,11 @@ class model { * Gets the predictions for this context. * * @param \context $context - * @param int $page The page of results to fetch - * @param int $perpage The max number of results to fetch + * @param int $page The page of results to fetch. False for all results. + * @param int $perpage The max number of results to fetch. Ignored if $page is false. * @return array($total, \core_analytics\prediction[]) */ - public function get_predictions(\context $context, $page = 0, $perpage = 100) { + public function get_predictions(\context $context, $page = false, $perpage = 100) { global $DB; \core_analytics\manager::check_can_list_insights($context); @@ -1033,12 +1033,13 @@ class model { list($unused, $samplesdata) = $this->get_analyser()->get_samples($sampleids); - // Add samples data as part of each prediction. - $paginated = []; $current = 0; - $offset = $page * $perpage; - $limit = $offset + $perpage; + + if ($page !== false) { + $offset = $page * $perpage; + $limit = $offset + $perpage; + } foreach ($predictions as $predictionid => $predictiondata) { @@ -1051,7 +1052,7 @@ class model { } // Return paginated dataset - we cannot paginate in the DB because we post filter the list. - if ($current >= $offset && $current < $limit) { + if ($page === false || ($current >= $offset && $current < $limit)) { // Replace \stdClass object by \core_analytics\prediction objects. $prediction = new \core_analytics\prediction($predictiondata, $samplesdata[$sampleid]); $predictions[$predictionid] = $prediction; -- 2.43.0