2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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();
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
{
41 protected $actionname = null;
44 * @var \action_menu_link
46 protected $actionlink = null;
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
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);
73 $this->actionlink
= new \action_menu_link_primary
($url, $icon, $text, $attributes);
78 * Returns the action name.
82 public function get_action_name() {
83 return $this->actionname
;
87 * Returns the link to the action.
89 * @return \action_menu_link
91 public function get_action_link() {
92 return $this->actionlink
;