Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 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   * Class for exporting content associated to a record.
  19   *
  20   * @package    mod_data
  21   * @copyright  2017 Juan Leyva <juan@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace mod_data\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core\external\exporter;
  28  use renderer_base;
  29  use external_files;
  30  use external_util;
  31  
  32  /**
  33   * Class for exporting content associated to a record.
  34   *
  35   * @copyright  2017 Juan Leyva <juan@moodle.com>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class content_exporter extends exporter {
  39  
  40      protected static function define_properties() {
  41  
  42          return array(
  43              'id' => array(
  44                  'type' => PARAM_INT,
  45                  'description' => 'Content id.',
  46              ),
  47              'fieldid' => array(
  48                  'type' => PARAM_INT,
  49                  'description' => 'The field type of the content.',
  50                  'default' => 0,
  51              ),
  52              'recordid' => array(
  53                  'type' => PARAM_INT,
  54                  'description' => 'The record this content belongs to.',
  55                  'default' => 0,
  56              ),
  57              'content' => array(
  58                  'type' => PARAM_RAW,
  59                  'description' => 'Contents.',
  60                  'null' => NULL_ALLOWED,
  61              ),
  62              'content1' => array(
  63                  'type' => PARAM_RAW,
  64                  'description' => 'Contents.',
  65                  'null' => NULL_ALLOWED,
  66              ),
  67              'content2' => array(
  68                  'type' => PARAM_RAW,
  69                  'description' => 'Contents.',
  70                  'null' => NULL_ALLOWED,
  71              ),
  72              'content3' => array(
  73                  'type' => PARAM_RAW,
  74                  'description' => 'Contents.',
  75                  'null' => NULL_ALLOWED,
  76              ),
  77              'content4' => array(
  78                  'type' => PARAM_RAW,
  79                  'description' => 'Contents.',
  80                  'null' => NULL_ALLOWED,
  81              ),
  82          );
  83      }
  84  
  85      protected static function define_related() {
  86          return array(
  87              'context' => 'context',
  88          );
  89      }
  90  
  91      protected static function define_other_properties() {
  92          return array(
  93              'files' => array(
  94                  'type' => external_files::get_properties_for_exporter(),
  95                  'multiple' => true,
  96                  'optional' => true,
  97              ),
  98          );
  99      }
 100  
 101      protected function get_other_values(renderer_base $output) {
 102          $values = ['files' => external_util::get_area_files($this->related['context']->id, 'mod_data', 'content', $this->data->id)];
 103  
 104          return $values;
 105      }
 106  }