Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 402] [Versions 310 and 403]

   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   * Representation of a suggested action.
  19   *
  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
  23   */
  24  
  25  namespace core_analytics;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Representation of a suggested action.
  31   *
  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
  35   */
  36  abstract class action {
  37  
  38      /**
  39       * @var  Action type useful.
  40       */
  41      const TYPE_POSITIVE = 'useful';
  42  
  43      /**
  44       * @var  Action type notuseful.
  45       */
  46      const TYPE_NEGATIVE = 'notuseful';
  47  
  48      /**
  49       * @var  Action type neutral.
  50       */
  51      const TYPE_NEUTRAL = 'neutral';
  52  
  53      /**
  54       * @var string
  55       */
  56      protected $actionname = null;
  57  
  58      /**
  59       * @var \moodle_url
  60       */
  61      protected $url = null;
  62  
  63      /**
  64       * @var \renderable
  65       */
  66      protected $actionlink = null;
  67  
  68      /**
  69       * @var string
  70       */
  71      protected $text = null;
  72  
  73      /**
  74       * Returns the action name.
  75       *
  76       * @return string
  77       */
  78      public function get_action_name() {
  79          return $this->actionname;
  80      }
  81  
  82      /**
  83       * Returns the url to the action.
  84       *
  85       * @return \moodle_url
  86       */
  87      public function get_url() {
  88          return $this->url;
  89      }
  90  
  91      /**
  92       * Returns the link to the action.
  93       *
  94       * @return \renderable
  95       */
  96      public function get_action_link() {
  97          return $this->actionlink;
  98      }
  99  
 100      /**
 101       * Returns the action text.
 102       * @return string
 103       */
 104      public function get_text() {
 105          return $this->text;
 106      }
 107  
 108      /**
 109       * Sets the type of the action according to its positiveness.
 110       *
 111       * @throws \coding_exception
 112       * @param string|false $type \core_analytics\action::TYPE_POSITIVE, TYPE_NEGATIVE or TYPE_NEUTRAL
 113       */
 114      public function set_type($type = false) {
 115          if (!$type) {
 116              // Any non-standard action specified by a target is considered positive by default because that is what
 117              // they are meant to be.
 118              $type = self::TYPE_POSITIVE;
 119          }
 120  
 121          if ($type !== self::TYPE_POSITIVE && $type !== self::TYPE_NEUTRAL &&
 122                  $type !== self::TYPE_NEGATIVE) {
 123              throw new \coding_exception('The provided type must be ' . self::TYPE_POSITIVE . ', ' . self::TYPE_NEUTRAL .
 124                  ' or ' . self::TYPE_NEGATIVE);
 125          }
 126          $this->type = $type;
 127      }
 128  
 129      /**
 130       * Returns the type of action.
 131       *
 132       * @return string The positiveness of the action (self::TYPE_POSITIVE, self::TYPE_NEGATIVE or self::TYPE_NEUTRAL)
 133       */
 134      public function get_type() {
 135          return $this->type;
 136      }
 137  }