Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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   * Prediction action clicked event.
  19   *
  20   * @property-read array $other {
  21   *      Extra information about event.
  22   *
  23   *      - string actionname: The action name
  24   * }
  25   *
  26   * @package    core_analytics
  27   * @copyright  2017 David Monllao {@link http://www.davidmonllao.com}
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  namespace core\event;
  32  defined('MOODLE_INTERNAL') || die();
  33  
  34  /**
  35   * Event triggered after a user clicked on one of the prediction suggested actions.
  36   *
  37   * @package    core_analytics
  38   * @copyright  2017 David Monllao {@link http://www.davidmonllao.com}
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class prediction_action_started extends \core\event\base {
  42  
  43      /**
  44       * Set basic properties for the event.
  45       */
  46      protected function init() {
  47          $this->data['objecttable'] = 'analytics_predictions';
  48  
  49          // Marked as create because even if the action is something like viewing a course
  50          // they are starting an action from a prediction, which is kind-of creating an outcome.
  51          $this->data['crud'] = 'c';
  52          // It will depend on the action, we have no idea really but we need to chose one and
  53          // the user is learning from the prediction so LEVEL_PARTICIPATING seems more appropriate
  54          // than LEVEL_OTHER.
  55          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  56      }
  57  
  58      /**
  59       * Returns localised general event name.
  60       *
  61       * @return string
  62       */
  63      public static function get_name() {
  64          return get_string('eventpredictionactionstarted', 'analytics');
  65      }
  66  
  67      /**
  68       * Returns non-localised event description with id's for admin use only.
  69       *
  70       * @return string
  71       */
  72      public function get_description() {
  73          return "The user with id '$this->userid' has started '{$this->other['actionname']}' action for the prediction with id '" .
  74              $this->objectid . "'.";
  75      }
  76  
  77      /**
  78       * Returns relevant URL.
  79       * @return \moodle_url
  80       */
  81      public function get_url() {
  82          return new \moodle_url('/report/insights/prediction.php', array('id' => $this->objectid));
  83      }
  84  
  85      /**
  86       * Custom validations.
  87       *
  88       * @throws \coding_exception
  89       * @return void
  90       */
  91      protected function validate_data() {
  92          parent::validate_data();
  93  
  94          if (!isset($this->objectid)) {
  95              throw new \coding_exception('The \'objectid\' must be set.');
  96          }
  97      }
  98  
  99      /**
 100       * get_objectid_mapping
 101       *
 102       * @return array
 103       */
 104      public static function get_objectid_mapping() {
 105          return array('db' => 'analytics_predictions');
 106      }
 107  }