2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Class for exporting record data.
21 * @copyright 2017 Juan Leyva <juan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace mod_data\external
;
25 defined('MOODLE_INTERNAL') ||
die();
27 use core\external\exporter
;
32 * Class for exporting record data.
34 * @copyright 2017 Juan Leyva <juan@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class record_exporter
extends exporter
{
39 protected static function define_properties() {
44 'description' => 'Record id.',
48 'description' => 'The id of the user who created the record.',
53 'description' => 'The group id this record belongs to (0 for no groups).',
58 'description' => 'The database id this record belongs to.',
61 'timecreated' => array(
63 'description' => 'Time the record was created.',
66 'timemodified' => array(
68 'description' => 'Last time the record was modified.',
73 'description' => 'Whether the entry has been approved (if the database is configured in that way).',
79 protected static function define_related() {
81 'database' => 'stdClass',
82 'user' => 'stdClass?',
83 'context' => 'context',
84 'contents' => 'stdClass[]?',
88 protected static function define_other_properties() {
90 'canmanageentry' => array(
92 'description' => 'Whether the current user can manage this entry',
96 'description' => 'The user who created the entry fullname.',
100 'type' => content_exporter
::read_properties_definition(),
101 'description' => 'The record contents.',
108 protected function get_other_values(renderer_base
$output) {
112 'canmanageentry' => data_user_can_manage_entry($this->data
, $this->related
['database'], $this->related
['context']),
115 if (!empty($this->related
['user']) and !empty($this->related
['user']->id
)) {
116 $values['fullname'] = fullname($this->related
['user']);
117 } else if ($this->data
->userid
) {
118 $user = core_user
::get_user($this->data
->userid
);
119 $values['fullname'] = fullname($user);
122 if (!empty($this->related
['contents'])) {
124 foreach ($this->related
['contents'] as $content) {
125 $related = array('context' => $this->related
['context']);
126 $exporter = new content_exporter($content, $related);
127 $contents[] = $exporter->export($PAGE->get_renderer('core'));
129 $values['contents'] = $contents;