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.
20 * @package core_analytics
21 * @copyright 2019 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.
32 * @package core_analytics
33 * @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 abstract class action
{
39 * @var Action type useful.
41 const TYPE_POSITIVE
= 'useful';
44 * @var Action type notuseful.
46 const TYPE_NEGATIVE
= 'notuseful';
49 * @var Action type neutral.
51 const TYPE_NEUTRAL
= 'neutral';
56 protected $actionname = null;
61 protected $url = null;
66 protected $actionlink = null;
71 protected $text = null;
73 /** @var string Store the action type. */
74 protected string $type = '';
77 * Returns the action name.
81 public function get_action_name() {
82 return $this->actionname
;
86 * Returns the url to the action.
90 public function get_url() {
95 * Returns the link to the action.
99 public function get_action_link() {
100 return $this->actionlink
;
104 * Returns the action text.
107 public function get_text() {
112 * Sets the type of the action according to its positiveness.
114 * @throws \coding_exception
115 * @param string|false $type \core_analytics\action::TYPE_POSITIVE, TYPE_NEGATIVE or TYPE_NEUTRAL
117 public function set_type($type = false) {
119 // Any non-standard action specified by a target is considered positive by default because that is what
120 // they are meant to be.
121 $type = self
::TYPE_POSITIVE
;
124 if ($type !== self
::TYPE_POSITIVE
&& $type !== self
::TYPE_NEUTRAL
&&
125 $type !== self
::TYPE_NEGATIVE
) {
126 throw new \
coding_exception('The provided type must be ' . self
::TYPE_POSITIVE
. ', ' . self
::TYPE_NEUTRAL
.
127 ' or ' . self
::TYPE_NEGATIVE
);
133 * Returns the type of action.
135 * @return string The positiveness of the action (self::TYPE_POSITIVE, self::TYPE_NEGATIVE or self::TYPE_NEUTRAL)
137 public function get_type() {