MDL-58835 report_insights: Not useful and ack prediction actions
[moodle.git] / report / insights / action.php
CommitLineData
373b1de1
DM
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.
13//
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/>.
16
17/**
18 * Forwards the user to the action they selected.
19 *
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
23 */
24
6ec2ae0f 25require_once(__DIR__ . '/../../config.php');
373b1de1
DM
26
27$predictionid = required_param('predictionid', PARAM_INT);
28$actionname = required_param('action', PARAM_ALPHANUMEXT);
29$forwardurl = required_param('forwardurl', PARAM_LOCALURL);
30
1611308b
DM
31list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid, true);
32if ($context->contextlevel < CONTEXT_COURSE) {
33 // Only for higher levels than course.
373b1de1
DM
34 $PAGE->set_context($context);
35}
36
0c0a72e7
DM
37if (empty($forwardurl)) {
38 $params = array('modelid' => $model->get_id(), 'contextid' => $context->id);
39 $forwardurl = new \moodle_url('/report/insights/insights.php', $params);
40}
41
1611308b 42$params = array('predictionid' => $prediction->get_prediction_data()->id, 'action' => $actionname, 'forwardurl' => $forwardurl);
373b1de1 43$url = new \moodle_url('/report/insights/action.php', $params);
373b1de1
DM
44$PAGE->set_url($url);
45
6ec2ae0f 46$modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
3e0f33aa 47if (!$modelready) {
373b1de1
DM
48
49 $PAGE->set_pagelayout('report');
50
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();
3e0f33aa 55 echo $OUTPUT->notification(get_string('disabledmodel', 'report_insights'), \core\output\notification::NOTIFY_INFO);
373b1de1
DM
56 echo $OUTPUT->footer();
57 exit(0);
58}
59
0c0a72e7 60$prediction->action_executed($actionname, $model->get_target());
373b1de1
DM
61
62redirect($forwardurl);