Merge branch 'MDL-62397-master' of git://github.com/andrewnicols/moodle
[moodle.git] / report / insights / action.php
blob6f2d333e0a841607ef0386a3b453156aec124e33
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 list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid, true);
32 if ($context->contextlevel < CONTEXT_COURSE) {
33 // Only for higher levels than course.
34 $PAGE->set_context($context);
37 if (empty($forwardurl)) {
38 $params = array('modelid' => $model->get_id(), 'contextid' => $context->id);
39 $forwardurl = new \moodle_url('/report/insights/insights.php', $params);
42 $params = array('predictionid' => $prediction->get_prediction_data()->id, 'action' => $actionname, 'forwardurl' => $forwardurl);
43 $url = new \moodle_url('/report/insights/action.php', $params);
44 $PAGE->set_url($url);
46 $modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
47 if (!$modelready) {
49 $PAGE->set_pagelayout('report');
51 // We don't want to disclose the name of the model if it has not been enabled.
52 $PAGE->set_title($context->get_context_name());
53 $PAGE->set_heading($context->get_context_name());
54 echo $OUTPUT->header();
55 echo $OUTPUT->notification(get_string('disabledmodel', 'report_insights'), \core\output\notification::NOTIFY_INFO);
56 echo $OUTPUT->footer();
57 exit(0);
60 $prediction->action_executed($actionname, $model->get_target());
62 redirect($forwardurl);