Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 402 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   * Testable contenttype plugin class.
  19   *
  20   * @package    core_contentbank
  21   * @category   test
  22   * @copyright  2020 Sara Arjona <sara@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace contenttype_testable;
  27  
  28  /**
  29   * Testable contenttype plugin class.
  30   *
  31   * @package    core_contentbank
  32   * @copyright  2020 Sara Arjona <sara@moodle.com>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class contenttype extends \core_contentbank\contenttype {
  36  
  37      /** Feature for testing */
  38      const CAN_TEST = 'test';
  39  
  40      /** @var array Additional features for testing */
  41      public static $featurestotest;
  42  
  43      /**
  44       * Returns the HTML code to render the icon for content bank contents.
  45       *
  46       * @param  content $content The content to delete.
  47       * @return string               HTML code to render the icon
  48       */
  49      public function get_icon(\core_contentbank\content $content): string {
  50          global $OUTPUT;
  51  
  52          return $OUTPUT->image_url('f/archive-64', 'moodle')->out(false);
  53      }
  54  
  55      /**
  56       * Return an array of implemented features by this plugin.
  57       *
  58       * @return array
  59       */
  60      protected function get_implemented_features(): array {
  61          $features = [self::CAN_TEST];
  62  
  63          if (!empty(self::$featurestotest)) {
  64              $features = array_merge($features, self::$featurestotest);
  65          }
  66  
  67          return $features;
  68      }
  69  
  70      /**
  71       * Return an array of extensions this plugin could manage.
  72       *
  73       * @return array
  74       */
  75      public function get_manageable_extensions(): array {
  76          return  ['.txt', '.png', '.h5p'];
  77      }
  78  
  79      /**
  80       * Returns the list of different types of the given content type.
  81       *
  82       * @return array
  83       */
  84      public function get_contenttype_types(): array {
  85          $type = new \stdClass();
  86          $type->typename = 'testable';
  87  
  88          return [$type];
  89      }
  90  
  91      /**
  92       * Returns true, so the user has permission on the feature.
  93       *
  94       * @return bool     True if content could be edited or created. False otherwise.
  95       */
  96      final public function can_test2(): bool {
  97          if (!$this->is_feature_supported('test2')) {
  98              return false;
  99          }
 100  
 101          return true;
 102      }
 103  
 104      /**
 105       * This implements custom file serving.
 106       *
 107       * @param stdClass $course the course object
 108       * @param stdClass $cm the course module object
 109       * @param \context $context the context
 110       * @param string $filearea the name of the file area
 111       * @param array $args extra arguments (itemid, path)
 112       * @param bool $forcedownload whether or not force download
 113       * @param array $options additional options affecting the file serving
 114       * @return void
 115       */
 116      public static function pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []): void {
 117          return;
 118      }
 119  }