weekly back-to-dev release 5.0dev
[moodle.git] / report / insights / action.php
blobb2000d2f44ffedf2905231488c467ffc1dc88a4f
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Forwards the user to the action they selected.
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');
27 $predictionid = required_param('predictionid', PARAM_INT);
28 $actionname = required_param('action', PARAM_ALPHANUMEXT);
29 $forwardurl = required_param('forwardurl', PARAM_LOCALURL);
31 if (!\core_analytics\manager::is_analytics_enabled()) {
32 $PAGE->set_context(\context_system::instance());
33 $renderer = $PAGE->get_renderer('report_insights');
34 echo $renderer->render_analytics_disabled();
35 exit(0);
38 list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid, true);
39 if ($context->contextlevel < CONTEXT_COURSE) {
40 // Only for higher levels than course.
41 $PAGE->set_context($context);
44 if (empty($forwardurl)) {
45 $params = array('modelid' => $model->get_id(), 'contextid' => $context->id);
46 $forwardurl = new \moodle_url('/report/insights/insights.php', $params);
49 $params = array('predictionid' => $prediction->get_prediction_data()->id, 'action' => $actionname, 'forwardurl' => $forwardurl);
50 $url = new \moodle_url('/report/insights/action.php', $params);
51 $PAGE->set_url($url);
53 $modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
54 if (!$modelready) {
56 $PAGE->set_pagelayout('report');
58 // We don't want to disclose the name of the model if it has not been enabled.
59 $PAGE->set_title($context->get_context_name());
60 $PAGE->set_heading($context->get_context_name());
61 echo $OUTPUT->header();
62 echo $OUTPUT->notification(get_string('disabledmodel', 'report_insights'), \core\output\notification::NOTIFY_INFO);
63 echo $OUTPUT->footer();
64 exit(0);
67 $prediction->action_executed($actionname, $model->get_target());
69 redirect($forwardurl);