Merge branch 'MDL-62397-master' of git://github.com/andrewnicols/moodle
[moodle.git] / analytics / classes / prediction_action.php
blob2fb4281ba50934411adb22a77effc950668c073a
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 * Representation of a suggested action associated with a prediction.
20 * @package core_analytics
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 namespace core_analytics;
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Representation of a suggested action associated with a prediction.
32 * @package core_analytics
33 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class prediction_action {
38 /**
39 * @var string
41 protected $actionname = null;
43 /**
44 * @var \action_menu_link
46 protected $actionlink = null;
48 /**
49 * Prediction action constructor.
51 * @param string $actionname They should match a-zA-Z_0-9-, as we apply a PARAM_ALPHANUMEXT filter
52 * @param \core_analytics\prediction $prediction
53 * @param \moodle_url $actionurl
54 * @param \pix_icon $icon Link icon
55 * @param string $text Link text
56 * @param bool $primary Primary button or secondary.
57 * @param array $attributes Link attributes
58 * @return void
60 public function __construct($actionname, \core_analytics\prediction $prediction, \moodle_url $actionurl, \pix_icon $icon,
61 $text, $primary = false, $attributes = array()) {
63 $this->actionname = $actionname;
65 // We want to track how effective are our suggested actions, we pass users through a script that will log these actions.
66 $params = array('action' => $this->actionname, 'predictionid' => $prediction->get_prediction_data()->id,
67 'forwardurl' => $actionurl->out(false));
68 $url = new \moodle_url('/report/insights/action.php', $params);
70 if ($primary === false) {
71 $this->actionlink = new \action_menu_link_secondary($url, $icon, $text, $attributes);
72 } else {
73 $this->actionlink = new \action_menu_link_primary($url, $icon, $text, $attributes);
77 /**
78 * Returns the action name.
80 * @return string
82 public function get_action_name() {
83 return $this->actionname;
86 /**
87 * Returns the link to the action.
89 * @return \action_menu_link
91 public function get_action_link() {
92 return $this->actionlink;