2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package report_insights
21 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. '/../../config.php');
26 require_once($CFG->libdir
. '/adminlib.php');
28 $predictionid = required_param('id', PARAM_INT
);
30 list($model, $prediction, $context) = \core_analytics\manager
::get_prediction($predictionid, true);
31 if ($context->contextlevel
< CONTEXT_COURSE
) {
32 // Only for higher levels than course.
33 $PAGE->set_context($context);
36 $params = array('id' => $prediction->get_prediction_data()->id
);
37 $url = new \
moodle_url('/report/insights/prediction.php', $params);
39 $PAGE->set_pagelayout('report');
41 $navurl = new \
moodle_url('/report/insights/insights.php', array('contextid' => $context->id
));
42 if ($context->contextlevel
=== CONTEXT_SYSTEM
) {
43 admin_externalpage_setup('reportinsights', '', null, '', array('pagelayout' => 'report'));
44 } else if ($context->contextlevel
=== CONTEXT_USER
) {
45 $user = \core_user
::get_user($context->instanceid
, '*', MUST_EXIST
);
46 $PAGE->navigation
->extend_for_user($user);
48 $modelinsightsurl = clone $navurl;
49 $modelinsightsurl->param('modelid', $model->get_id());
50 $PAGE->add_report_nodes($user->id
, array(
51 'name' => get_string('insights', 'report_insights'),
55 $PAGE->navigation
->override_active_url($navurl);
57 $renderer = $PAGE->get_renderer('report_insights');
59 $insightinfo = new stdClass();
60 $insightinfo->contextname
= $context->get_context_name();
61 $insightinfo->insightname
= $model->get_target()->get_name();
63 $modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
65 echo $renderer->render_model_disabled($insightinfo);
69 if (!$model->uses_insights()) {
70 echo $renderer->render_no_insights_model($context);
74 $PAGE->set_title($insightinfo->insightname
);
75 $PAGE->set_heading($insightinfo->contextname
);
77 echo $OUTPUT->header();
79 $renderable = new \report_insights\output\
insight($prediction, $model, false);
80 echo $renderer->render($renderable);
82 echo $OUTPUT->footer();