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 a cohort summary from an stdClass.
  19   *
  20   * @package    core_cohort
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_cohort\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderer_base;
  28  
  29  /**
  30   * Class for exporting a cohort summary from an stdClass.
  31   *
  32   * @copyright  2015 Damyon Wiese
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class cohort_summary_exporter extends \core\external\exporter {
  36  
  37      protected static function define_related() {
  38          // Cohorts can exist on a category context.
  39          return array('context' => '\\context');
  40      }
  41  
  42      public static function define_properties() {
  43          return array(
  44              'id' => array(
  45                  'type' => PARAM_INT,
  46              ),
  47              'name' => array(
  48                  'type' => PARAM_TEXT,
  49              ),
  50              'idnumber' => array(
  51                  'type' => PARAM_RAW,        // ID numbers are plain text.
  52                  'default' => '',
  53                  'null' => NULL_ALLOWED
  54              ),
  55              'description' => array(
  56                  'type' => PARAM_TEXT,
  57                  'default' => '',
  58                  'null' => NULL_ALLOWED
  59              ),
  60              'descriptionformat' => array(
  61                  'type' => PARAM_INT,
  62                  'default' => FORMAT_HTML,
  63                  'null' => NULL_ALLOWED
  64              ),
  65              'visible' => array(
  66                  'type' => PARAM_BOOL,
  67              ),
  68              'theme' => array(
  69                  'type' => PARAM_THEME,
  70                  'null' => NULL_ALLOWED
  71              )
  72          );
  73      }
  74  
  75      public static function define_other_properties() {
  76          return array(
  77              'contextname' => array(
  78                  // The method context::get_context_name() already formats the string, and may return HTML.
  79                  'type' => PARAM_RAW
  80              ),
  81          );
  82      }
  83  
  84      protected function get_other_values(renderer_base $output) {
  85          return array(
  86              'contextname' => $this->related['context']->get_context_name()
  87          );
  88      }
  89  }