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 a blog post (entry).
21 * @copyright 2018 Juan Leyva <juan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace core_blog\external
;
25 defined('MOODLE_INTERNAL') ||
die();
27 use core\external\exporter
;
32 use core_tag\external\tag_item_exporter
;
35 * Class for exporting a blog post (entry).
37 * @copyright 2018 Juan Leyva <juan@moodle.com>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class post_exporter
extends exporter
{
43 * Return the list of properties.
45 * @return array list of properties
47 protected static function define_properties() {
51 'null' => NULL_ALLOWED
,
52 'description' => 'Post/entry id.',
55 'type' => PARAM_ALPHANUMEXT
,
56 'null' => NULL_NOT_ALLOWED
,
57 'description' => 'Where it was published the post (blog, blog_external...).',
61 'null' => NULL_NOT_ALLOWED
,
63 'description' => 'Post author.',
67 'null' => NULL_NOT_ALLOWED
,
69 'description' => 'Course where the post was created.',
73 'null' => NULL_NOT_ALLOWED
,
75 'description' => 'Group post was created for.',
79 'null' => NULL_NOT_ALLOWED
,
81 'description' => 'Module id where the post was created (not used anymore).',
83 'coursemoduleid' => array(
85 'null' => NULL_NOT_ALLOWED
,
87 'description' => 'Course module id where the post was created.',
91 'null' => NULL_NOT_ALLOWED
,
92 'description' => 'Post subject.',
96 'null' => NULL_ALLOWED
,
97 'description' => 'Post summary.',
101 'null' => NULL_ALLOWED
,
102 'description' => 'Post content.',
104 'uniquehash' => array(
106 'null' => NULL_NOT_ALLOWED
,
107 'description' => 'Post unique hash.',
111 'null' => NULL_NOT_ALLOWED
,
113 'description' => 'Post rating.',
117 'null' => NULL_NOT_ALLOWED
,
119 'description' => 'Post content format.',
121 'summaryformat' => array(
122 'choices' => array(FORMAT_HTML
, FORMAT_MOODLE
, FORMAT_PLAIN
, FORMAT_MARKDOWN
),
124 'default' => FORMAT_MOODLE
,
125 'description' => 'Format for the summary field.',
127 'attachment' => array(
129 'null' => NULL_ALLOWED
,
130 'description' => 'Post atachment.',
132 'publishstate' => array(
133 'type' => PARAM_ALPHA
,
134 'null' => NULL_NOT_ALLOWED
,
135 'default' => 'draft',
136 'description' => 'Post publish state.',
138 'lastmodified' => array(
140 'null' => NULL_NOT_ALLOWED
,
142 'description' => 'When it was last modified.',
146 'null' => NULL_NOT_ALLOWED
,
148 'description' => 'When it was created.',
150 'usermodified' => array(
152 'null' => NULL_ALLOWED
,
153 'description' => 'User that updated the post.',
158 protected static function define_related() {
160 'context' => 'context'
164 protected static function define_other_properties() {
166 'summaryfiles' => array(
167 'type' => external_files
::get_properties_for_exporter(),
170 'attachmentfiles' => array(
171 'type' => external_files
::get_properties_for_exporter(),
176 'type' => tag_item_exporter
::read_properties_definition(),
177 'description' => 'Tags.',
184 protected function get_other_values(renderer_base
$output) {
185 $context = context_system
::instance(); // Files always on site context.
187 $values['summaryfiles'] = external_util
::get_area_files($context->id
, 'blog', 'post', $this->data
->id
);
188 $values['attachmentfiles'] = external_util
::get_area_files($context->id
, 'blog', 'attachment', $this->data
->id
);
189 if ($this->data
->module
== 'blog_external') {
190 // For external blogs, the content field has the external blog id.
191 $values['tags'] = \core_tag\external\util
::get_item_tags('core', 'blog_external', $this->data
->content
);
193 $values['tags'] = \core_tag\external\util
::get_item_tags('core', 'post', $this->data
->id
);