Merge branch 'MDL-81397' of https://github.com/paulholden/moodle
[moodle.git] / analytics / classes / action.php
blobb05d513bd38d4fdb0ddd93a0bc8535709b7af3d7
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.
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();
29 /**
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 {
38 /**
39 * @var Action type useful.
41 const TYPE_POSITIVE = 'useful';
43 /**
44 * @var Action type notuseful.
46 const TYPE_NEGATIVE = 'notuseful';
48 /**
49 * @var Action type neutral.
51 const TYPE_NEUTRAL = 'neutral';
53 /**
54 * @var string
56 protected $actionname = null;
58 /**
59 * @var \moodle_url
61 protected $url = null;
63 /**
64 * @var \renderable
66 protected $actionlink = null;
68 /**
69 * @var string
71 protected $text = null;
73 /** @var string Store the action type. */
74 protected string $type = '';
76 /**
77 * Returns the action name.
79 * @return string
81 public function get_action_name() {
82 return $this->actionname;
85 /**
86 * Returns the url to the action.
88 * @return \moodle_url
90 public function get_url() {
91 return $this->url;
94 /**
95 * Returns the link to the action.
97 * @return \renderable
99 public function get_action_link() {
100 return $this->actionlink;
104 * Returns the action text.
105 * @return string
107 public function get_text() {
108 return $this->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) {
118 if (!$type) {
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);
129 $this->type = $type;
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() {
138 return $this->type;