Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Class for exporting summary information for a course category.
  19   *
  20   * @package    core
  21   * @copyright  2017 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderer_base;
  28  use moodle_url;
  29  
  30  /**
  31   * Class for exporting a course summary from an stdClass.
  32   *
  33   * @copyright  2017 Andrew Nicols <andrew@nicols.co.uk>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class coursecat_summary_exporter extends \core\external\exporter {
  37  
  38      /**
  39       * @var \core_course_category $category
  40       */
  41      protected $category;
  42  
  43      public function __construct(\core_course_category $category, $related) {
  44          $this->category = $category;
  45  
  46          $data = [];
  47          // Specify some defaults.
  48          foreach ($category as $key => $value) {
  49              $data[$key] = $value;
  50          }
  51  
  52          return parent::__construct($data, $related);
  53      }
  54  
  55      protected static function define_related() {
  56          return [
  57              'context' => 'context',
  58          ];
  59      }
  60  
  61      public static function define_other_properties() {
  62          return [
  63              'nestedname' => [
  64                  'type' => PARAM_RAW,
  65              ],
  66              'url' => [
  67                  'type' => PARAM_URL,
  68              ],
  69          ];
  70      }
  71  
  72      protected function get_other_values(renderer_base $output) {
  73          $return = [
  74              'nestedname' => $this->category->get_nested_name(),
  75              'url' => (new moodle_url('/course/index.php', [
  76                      'categoryid' => $this->category->id,
  77                  ]))->out(false),
  78          ];
  79  
  80          return $return;
  81      }
  82  
  83      public static function define_properties() {
  84          return [
  85              'id' => [
  86                  'type' => PARAM_INT,
  87              ],
  88              'name' => [
  89                  'type' => PARAM_TEXT,
  90                  'default' => '',
  91              ],
  92              'idnumber' => [
  93                  'type' => PARAM_RAW,
  94                  'null' => NULL_ALLOWED,
  95              ],
  96              'description' => [
  97                  'type' => PARAM_RAW,
  98                  'optional' => true,
  99              ],
 100              'parent' => [
 101                  'type' => PARAM_INT,
 102              ],
 103              'coursecount' => [
 104                  'type' => PARAM_INT,
 105                  'default' => 0,
 106              ],
 107              'visible' => [
 108                  'type' => PARAM_INT,
 109                  'default' => 1,
 110              ],
 111              'timemodified' => [
 112                  'type' => PARAM_INT,
 113                  'default' => 0,
 114              ],
 115              'depth' => [
 116                  'type' => PARAM_INT,
 117                  'default' => 0,
 118              ],
 119          ];
 120      }
 121  
 122      /**
 123       * Get the formatting parameters for the summary.
 124       *
 125       * @return array
 126       */
 127      protected function get_format_parameters_for_description() {
 128          return [
 129              'component' => 'coursecat',
 130              'filearea' => 'description',
 131          ];
 132      }
 133  }