Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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  
  25  require_once(__DIR__ . '/../../config.php');
  26  
  27  $predictionid = required_param('predictionid', PARAM_INT);
  28  $actionname = required_param('action', PARAM_ALPHANUMEXT);
  29  $forwardurl = required_param('forwardurl', PARAM_LOCALURL);
  30  
  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);
  36  }
  37  
  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);
  42  }
  43  
  44  if (empty($forwardurl)) {
  45      $params = array('modelid' => $model->get_id(), 'contextid' => $context->id);
  46      $forwardurl = new \moodle_url('/report/insights/insights.php', $params);
  47  }
  48  
  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);
  52  
  53  $modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
  54  if (!$modelready) {
  55  
  56      $PAGE->set_pagelayout('report');
  57  
  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);
  65  }
  66  
  67  $prediction->action_executed($actionname, $model->get_target());
  68  
  69  redirect($forwardurl);