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 competency_framework data.
  19   *
  20   * @package    core_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_competency\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core_competency\api;
  28  use renderer_base;
  29  
  30  /**
  31   * Class for exporting competency_framework data.
  32   *
  33   * @copyright  2015 Damyon Wiese
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class competency_framework_exporter extends \core\external\persistent_exporter {
  37  
  38      /**
  39       * Define the name of persistent class.
  40       *
  41       * @return string
  42       */
  43      protected static function define_class() {
  44          return \core_competency\competency_framework::class;
  45      }
  46  
  47      /**
  48       * Get other values that do not belong to the basic persisent.
  49       *
  50       * @param renderer_base $output
  51       * @return Array
  52       */
  53      protected function get_other_values(renderer_base $output) {
  54          $filters = array('competencyframeworkid' => $this->persistent->get('id'));
  55          $context = $this->persistent->get_context();
  56          $competenciescount = 0;
  57          try {
  58              $competenciescount = api::count_competencies($filters);
  59          } catch (\required_capability_exception $re) {
  60              $competenciescount = 0;
  61          }
  62          return array(
  63              'canmanage' => has_capability('moodle/competency:competencymanage', $context),
  64              'competenciescount' => $competenciescount,
  65              'contextname' => $context->get_context_name(),
  66              'contextnamenoprefix' => $context->get_context_name(false)
  67          );
  68      }
  69  
  70      /**
  71       * Define other properties that do not belong to the basic persisent.
  72       *
  73       * @return Array
  74       */
  75      protected static function define_other_properties() {
  76          return array(
  77              'canmanage' => array(
  78                  'type' => PARAM_BOOL
  79              ),
  80              'competenciescount' => array(
  81                  'type' => PARAM_INT
  82              ),
  83  
  84              // Both contexts need to be PARAM_RAW because the method context::get_context_name()
  85              // already applies the formatting and thus could return HTML content.
  86              'contextname' => array(
  87                  'type' => PARAM_RAW
  88              ),
  89              'contextnamenoprefix' => array(
  90                  'type' => PARAM_RAW
  91              )
  92          );
  93      }
  94  
  95  }