Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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.
   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   * Contains class for displaying a collection.
  19   *
  20   * @package   core_badges
  21   * @copyright 2019 Damyon Wiese
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_badges\external;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use core\external\exporter;
  30  use stdClass;
  31  
  32  /**
  33   * Class for displaying a badge competency.
  34   *
  35   * @package   core_badges
  36   * @copyright 2019 Damyon Wiese
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class collection_exporter extends exporter {
  40  
  41      /**
  42       * Either map version 1 data to version 2 or return it untouched.
  43       *
  44       * @param stdClass $data The remote data.
  45       * @param string $apiversion The backpack version used to communicate remotely.
  46       * @return stdClass
  47       */
  48      public static function map_external_data($data, $apiversion) {
  49          if ($apiversion == OPEN_BADGES_V1) {
  50              $result = new stdClass();
  51              $result->entityType = 'BackpackCollection';
  52              $result->entityId = $data->groupId;
  53              $result->name = $data->name;
  54              $result->description = $data->description;
  55              $result->assertions = [];
  56              return $result;
  57          }
  58          return $data;
  59      }
  60  
  61      /**
  62       * Return the list of properties.
  63       *
  64       * @return array
  65       */
  66      protected static function define_properties() {
  67          return [
  68              'entityType' => [
  69                  'type' => PARAM_ALPHA,
  70                  'description' => 'BackpackCollection',
  71              ],
  72              'entityId' => [
  73                  'type' => PARAM_RAW,
  74                  'description' => 'Unique identifier for this collection',
  75              ],
  76              'name' => [
  77                  'type' => PARAM_TEXT,
  78                  'description' => 'Collection name',
  79              ],
  80              'description' => [
  81                  'type' => PARAM_TEXT,
  82                  'description' => 'Collection description',
  83              ],
  84              'share_url' => [
  85                  'type' => PARAM_URL,
  86                  'description' => 'Url to view this collection',
  87              ],
  88              'published' => [
  89                  'type' => PARAM_BOOL,
  90                  'description' => 'True means this collection is public.',
  91              ],
  92              'assertions' => [
  93                  'type' => PARAM_RAW,
  94                  'description' => 'List of assertion ids in this collection',
  95                  'multiple' => true,
  96              ],
  97          ];
  98      }
  99  
 100      /**
 101       * Returns a list of objects that are related.
 102       *
 103       * @return array
 104       */
 105      protected static function define_related() {
 106          return array(
 107              'context' => 'context',
 108          );
 109      }
 110  }