Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 402] [Versions 39 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   * Base class for checks
  19   *
  20   * @package    core
  21   * @category   check
  22   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  namespace core\check;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Base class for checks
  31   *
  32   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  abstract class check {
  36  
  37      /**
  38       * @var $string $component - The component / plugin this task belongs to.
  39       *
  40       * This is autopopulated by the check manager.
  41       */
  42      protected $component = 'core';
  43  
  44      /**
  45       * Get the frankenstyle component name
  46       *
  47       * @return string
  48       */
  49      public function get_component(): string {
  50          return $this->component;
  51      }
  52  
  53      /**
  54       * Get the frankenstyle component name
  55       *
  56       * @param string $component name
  57       */
  58      public function set_component(string $component) {
  59          $this->component = $component;
  60      }
  61  
  62      /**
  63       * Get the check's id
  64       *
  65       * This defaults to the base name of the class which is ok in the most
  66       * cases but if you have a check which can have multiple instances then
  67       * you should override this to be unique.
  68       *
  69       * @return string must be unique within a component
  70       */
  71      public function get_id(): string {
  72          $class = get_class($this);
  73          $id = explode("\\", $class);
  74          return end($id);
  75      }
  76  
  77      /**
  78       * Get the check reference
  79       *
  80       * @return string must be globally unique
  81       */
  82      public function get_ref(): string {
  83          $ref = $this->get_component();
  84          if (!empty($ref)) {
  85              $ref .= '_';
  86          }
  87          $ref .= $this->get_id();
  88          return $ref;
  89      }
  90  
  91      /**
  92       * Get the short check name
  93       *
  94       * @return string
  95       */
  96      public function get_name(): string {
  97          $id = $this->get_id();
  98          return get_string("check{$id}", $this->get_component());
  99      }
 100  
 101      /**
 102       * A link to a place to action this
 103       *
 104       * @return action_link|null
 105       */
 106      public function get_action_link(): ?\action_link {
 107          return null;
 108      }
 109  
 110      /**
 111       * Return the result
 112       *
 113       * @return result object
 114       */
 115      abstract public function get_result(): result;
 116  
 117  }
 118