Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Post exporter class.
19
 *
20
 * @package    mod_forum
21
 * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_forum\local\exporters;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
use mod_forum\local\entities\post as post_entity;
30
use mod_forum\local\entities\discussion as discussion_entity;
31
use mod_forum\local\exporters\author as author_exporter;
32
use mod_forum\local\factories\exporter as exporter_factory;
33
use core\external\exporter;
34
use core_files\external\stored_file_exporter;
35
use context;
36
use core_tag_tag;
37
use renderer_base;
38
use stdClass;
39
 
40
require_once($CFG->dirroot . '/mod/forum/lib.php');
41
 
42
/**
43
 * Post exporter class.
44
 *
45
 * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
46
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47
 */
48
class post extends exporter {
49
    /** @var post_entity $post The post to export */
50
    private $post;
51
 
52
    /**
53
     * Constructor.
54
     *
55
     * @param post_entity $post The post to export
56
     * @param array $related List of related data
57
     */
58
    public function __construct(post_entity $post, array $related = []) {
59
        $this->post = $post;
60
        return parent::__construct([], $related);
61
    }
62
 
63
    /**
64
     * Return the list of additional properties.
65
     *
66
     * @return array
67
     */
68
    protected static function define_other_properties() {
69
        $attachmentdefinition = stored_file_exporter::read_properties_definition();
70
        $attachmentdefinition['urls'] = [
71
            'type' => [
72
                'export' => [
73
                    'type' => PARAM_URL,
74
                    'description' => 'The URL used to export the attachment',
75
                    'optional' => true,
76
                    'default' => null,
77
                    'null' => NULL_ALLOWED
78
                ]
79
            ]
80
        ];
81
        $attachmentdefinition['html'] = [
82
            'type' => [
83
                'plagiarism' => [
84
                    'type' => PARAM_RAW,
85
                    'description' => 'The HTML source for the Plagiarism Response',
86
                    'optional' => true,
87
                    'default' => null,
88
                    'null' => NULL_ALLOWED
89
                ],
90
            ]
91
        ];
92
 
93
        return [
94
            'id' => ['type' => PARAM_INT],
95
            'subject' => ['type' => PARAM_TEXT],
96
            'replysubject' => ['type' => PARAM_TEXT],
97
            'message' => ['type' => PARAM_RAW],
98
            'messageformat' => ['type' => PARAM_INT],
99
            'author' => ['type' => author_exporter::read_properties_definition()],
100
            'discussionid' => ['type' => PARAM_INT],
101
            'hasparent' => ['type' => PARAM_BOOL],
102
            'parentid' => [
103
                'type' => PARAM_INT,
104
                'optional' => true,
105
                'default' => null,
106
                'null' => NULL_ALLOWED
107
            ],
108
            'timecreated' => [
109
                'type' => PARAM_INT,
110
                'default' => null,
111
                'null' => NULL_ALLOWED
112
            ],
113
            'timemodified' => [
114
                'type' => PARAM_INT,
115
                'default' => null,
116
                'null' => NULL_ALLOWED
117
            ],
118
            'unread' => [
119
                'type' => PARAM_BOOL,
120
                'optional' => true,
121
                'default' => null,
122
                'null' => NULL_ALLOWED
123
            ],
124
            'isdeleted' => ['type' => PARAM_BOOL],
125
            'isprivatereply' => ['type' => PARAM_BOOL],
126
            'haswordcount' => ['type' => PARAM_BOOL],
127
            'wordcount' => [
128
                'type' => PARAM_INT,
129
                'optional' => true,
130
                'default' => null,
131
                'null' => NULL_ALLOWED
132
            ],
133
            'charcount' => [
134
                'type' => PARAM_INT,
135
                'optional' => true,
136
                'default' => null,
137
                'null' => NULL_ALLOWED
138
            ],
139
            'capabilities' => [
140
                'type' => [
141
                    'view' => [
142
                        'type' => PARAM_BOOL,
143
                        'null' => NULL_ALLOWED,
144
                        'description' => 'Whether the user can view the post',
145
                    ],
146
                    'edit' => [
147
                        'type' => PARAM_BOOL,
148
                        'null' => NULL_ALLOWED,
149
                        'description' => 'Whether the user can edit the post',
150
                    ],
151
                    'delete' => [
152
                        'type' => PARAM_BOOL,
153
                        'null' => NULL_ALLOWED,
154
                        'description' => 'Whether the user can delete the post',
155
                    ],
156
                    'split' => [
157
                        'type' => PARAM_BOOL,
158
                        'null' => NULL_ALLOWED,
159
                        'description' => 'Whether the user can split the post',
160
                    ],
161
                    'reply' => [
162
                        'type' => PARAM_BOOL,
163
                        'null' => NULL_ALLOWED,
164
                        'description' => 'Whether the user can reply to the post',
165
                    ],
166
                    'selfenrol' => [
167
                        'type' => PARAM_BOOL,
168
                        'null' => NULL_ALLOWED,
169
                        'description' => 'Whether the user can self enrol into the course',
170
                    ],
171
                    'export' => [
172
                        'type' => PARAM_BOOL,
173
                        'null' => NULL_ALLOWED,
174
                        'description' => 'Whether the user can export the post',
175
                    ],
176
                    'controlreadstatus' => [
177
                        'type' => PARAM_BOOL,
178
                        'null' => NULL_ALLOWED,
179
                        'description' => 'Whether the user can control the read status of the post',
180
                    ],
181
                    'canreplyprivately' => [
182
                        'type' => PARAM_BOOL,
183
                        'null' => NULL_ALLOWED,
184
                        'description' => 'Whether the user can post a private reply',
185
                    ]
186
                ]
187
            ],
188
            'urls' => [
189
                'optional' => true,
190
                'default' => null,
191
                'null' => NULL_ALLOWED,
192
                'type' => [
193
                    'view' => [
194
                        'description' => 'The URL used to view the post',
195
                        'type' => PARAM_URL,
196
                        'optional' => true,
197
                        'default' => null,
198
                        'null' => NULL_ALLOWED
199
                    ],
200
                    'viewisolated' => [
201
                        'description' => 'The URL used to view the post in isolation',
202
                        'type' => PARAM_URL,
203
                        'optional' => true,
204
                        'default' => null,
205
                        'null' => NULL_ALLOWED
206
                    ],
207
                    'viewparent' => [
208
                        'description' => 'The URL used to view the parent of the post',
209
                        'type' => PARAM_URL,
210
                        'optional' => true,
211
                        'default' => null,
212
                        'null' => NULL_ALLOWED
213
                    ],
214
                    'edit' => [
215
                        'description' => 'The URL used to edit the post',
216
                        'type' => PARAM_URL,
217
                        'optional' => true,
218
                        'default' => null,
219
                        'null' => NULL_ALLOWED
220
                    ],
221
                    'delete' => [
222
                        'description' => 'The URL used to delete the post',
223
                        'type' => PARAM_URL,
224
                        'optional' => true,
225
                        'default' => null,
226
                        'null' => NULL_ALLOWED
227
                    ],
228
                    'split' => [
229
                        'description' => 'The URL used to split the discussion ' .
230
                            'with the selected post being the first post in the new discussion',
231
                        'type' => PARAM_URL,
232
                        'optional' => true,
233
                        'default' => null,
234
                        'null' => NULL_ALLOWED
235
                    ],
236
                    'reply' => [
237
                        'description' => 'The URL used to reply to the post',
238
                        'type' => PARAM_URL,
239
                        'optional' => true,
240
                        'default' => null,
241
                        'null' => NULL_ALLOWED
242
                    ],
243
                    'export' => [
244
                        'description' => 'The URL used to export the post',
245
                        'type' => PARAM_URL,
246
                        'optional' => true,
247
                        'default' => null,
248
                        'null' => NULL_ALLOWED
249
                    ],
250
                    'markasread' => [
251
                        'description' => 'The URL used to mark the post as read',
252
                        'type' => PARAM_URL,
253
                        'optional' => true,
254
                        'default' => null,
255
                        'null' => NULL_ALLOWED
256
                    ],
257
                    'markasunread' => [
258
                        'description' => 'The URL used to mark the post as unread',
259
                        'type' => PARAM_URL,
260
                        'optional' => true,
261
                        'default' => null,
262
                        'null' => NULL_ALLOWED
263
                    ],
264
                    'discuss' => [
265
                        'type' => PARAM_URL,
266
                        'optional' => true,
267
                        'default' => null,
268
                        'null' => NULL_ALLOWED
269
                    ]
270
                ]
271
            ],
272
            'attachments' => [
273
                'multiple' => true,
274
                'type' => $attachmentdefinition
275
            ],
276
            'messageinlinefiles' => [
277
                'optional' => true,
278
                'multiple' => true,
279
                'type' => stored_file_exporter::read_properties_definition(),
280
            ],
281
            'tags' => [
282
                'optional' => true,
283
                'default' => null,
284
                'null' => NULL_ALLOWED,
285
                'multiple' => true,
286
                'type' => [
287
                    'id' => [
288
                        'type' => PARAM_INT,
289
                        'description' => 'The ID of the Tag',
290
                        'null' => NULL_NOT_ALLOWED,
291
                    ],
292
                    'tagid' => [
293
                        'type' => PARAM_INT,
294
                        'description' => 'The tagid',
295
                        'null' => NULL_NOT_ALLOWED,
296
                    ],
297
                    'isstandard' => [
298
                        'type' => PARAM_BOOL,
299
                        'description' => 'Whether this is a standard tag',
300
                        'null' => NULL_NOT_ALLOWED,
301
                    ],
302
                    'displayname' => [
303
                        'type' => PARAM_TEXT,
304
                        'description' => 'The display name of the tag',
305
                        'null' => NULL_NOT_ALLOWED,
306
                    ],
307
                    'flag' => [
308
                        'type' => PARAM_BOOL,
309
                        'description' => 'Wehther this tag is flagged',
310
                        'null' => NULL_NOT_ALLOWED,
311
                    ],
312
                    'urls' => [
313
                        'description' => 'URLs associated with the tag',
314
                        'null' => NULL_NOT_ALLOWED,
315
                        'type' => [
316
                            'view' => [
317
                                'type' => PARAM_URL,
318
                                'description' => 'The URL to view the tag',
319
                                'null' => NULL_NOT_ALLOWED,
320
                            ],
321
                        ]
322
                    ]
323
                ]
324
            ],
325
            'html' => [
326
                'optional' => true,
327
                'default' => null,
328
                'null' => NULL_ALLOWED,
329
                'type' => [
330
                    'rating' => [
331
                        'optional' => true,
332
                        'default' => null,
333
                        'null' => NULL_ALLOWED,
334
                        'type' => PARAM_RAW,
335
                        'description' => 'The HTML source to rate the post',
336
                    ],
337
                    'taglist' => [
338
                        'optional' => true,
339
                        'default' => null,
340
                        'null' => NULL_ALLOWED,
341
                        'type' => PARAM_RAW,
342
                        'description' => 'The HTML source to view the list of tags',
343
                    ],
344
                    'authorsubheading' => [
345
                        'optional' => true,
346
                        'default' => null,
347
                        'null' => NULL_ALLOWED,
348
                        'type' => PARAM_RAW,
349
                        'description' => 'The HTML source to view the author details',
350
                    ],
351
                ]
352
            ]
353
        ];
354
    }
355
 
356
    /**
357
     * Get the additional values to inject while exporting.
358
     *
359
     * @param renderer_base $output The renderer.
360
     * @return array Keys are the property names, values are their values.
361
     */
362
    protected function get_other_values(renderer_base $output) {
363
        $post = $this->post;
364
        $authorgroups = $this->related['authorgroups'];
365
        $forum = $this->related['forum'];
366
        $discussion = $this->related['discussion'];
367
        $author = $this->related['author'];
368
        $authorcontextid = $this->related['authorcontextid'];
369
        $user = $this->related['user'];
370
        $readreceiptcollection = $this->related['readreceiptcollection'];
371
        $rating = $this->related['rating'];
372
        $tags = $this->related['tags'];
373
        $attachments = $this->related['attachments'];
374
        $inlineattachments = $this->related['messageinlinefiles'];
375
        $includehtml = $this->related['includehtml'];
376
        $isdeleted = $post->is_deleted();
377
        $isprivatereply = $post->is_private_reply();
378
        $hasrating = $rating != null;
379
        $hastags = !empty($tags);
380
        $discussionid = $post->get_discussion_id();
381
        $parentid = $post->get_parent_id();
382
 
383
        $capabilitymanager = $this->related['capabilitymanager'];
384
        $canview = $capabilitymanager->can_view_post($user, $discussion, $post);
385
        $canedit = $capabilitymanager->can_edit_post($user, $discussion, $post);
386
        $candelete = $capabilitymanager->can_delete_post($user, $discussion, $post);
387
        $cansplit = $capabilitymanager->can_split_post($user, $discussion, $post);
388
        $canreply = $capabilitymanager->can_reply_to_post($user, $discussion, $post);
389
        $canexport = $capabilitymanager->can_export_post($user, $post);
390
        $cancontrolreadstatus = $capabilitymanager->can_manually_control_post_read_status($user);
391
        $canselfenrol = $capabilitymanager->can_self_enrol($user);
392
        $canreplyprivately = $capabilitymanager->can_reply_privately_to_post($user, $post);
393
 
394
        $urlfactory = $this->related['urlfactory'];
395
        $viewurl = $canview ? $urlfactory->get_view_post_url_from_post($post) : null;
396
        $viewisolatedurl = $canview ? $urlfactory->get_view_isolated_post_url_from_post($post) : null;
397
        $viewparenturl = $post->has_parent() ? $urlfactory->get_view_post_url_from_post_id($discussionid, $parentid) : null;
398
        $editurl = $canedit ? $urlfactory->get_edit_post_url_from_post($forum, $post) : null;
399
        $deleteurl = $candelete ? $urlfactory->get_delete_post_url_from_post($post) : null;
400
        $spliturl = $cansplit ? $urlfactory->get_split_discussion_at_post_url_from_post($post) : null;
401
        $replyurl = $canreply || $canselfenrol ? $urlfactory->get_reply_to_post_url_from_post($post) : null;
402
        $exporturl = $canexport ? $urlfactory->get_export_post_url_from_post($post) : null;
403
        $markasreadurl = $cancontrolreadstatus ? $urlfactory->get_mark_post_as_read_url_from_post($post) : null;
404
        $markasunreadurl = $cancontrolreadstatus ? $urlfactory->get_mark_post_as_unread_url_from_post($post) : null;
405
        $discussurl = $canview ? $urlfactory->get_discussion_view_url_from_post($post) : null;
406
 
407
        $authorexporter = new author_exporter(
408
            $author,
409
            $authorcontextid,
410
            $authorgroups,
411
            $canview,
412
            $this->related
413
        );
414
        $exportedauthor = $authorexporter->export($output);
415
        // Only bother loading the content if the user can see it.
416
        $loadcontent = $canview && !$isdeleted;
417
        $exportattachments = $loadcontent && !empty($attachments);
418
        $exportinlineattachments = $loadcontent && !empty($inlineattachments);
419
 
420
        if ($loadcontent) {
421
            $subject = $post->get_subject();
422
            $timecreated = $this->get_start_time($discussion, $post);
423
            $message = $this->get_message($post);
424
        } else {
425
            $subject = $isdeleted ? get_string('forumsubjectdeleted', 'forum') : get_string('forumsubjecthidden', 'forum');
426
            $message = $isdeleted ? get_string('forumbodydeleted', 'forum') : get_string('forumbodyhidden', 'forum');
427
            $timecreated = null;
428
        }
429
 
430
        $showwordcount = $forum->should_display_word_count();
431
        if ($showwordcount) {
432
            $wordcount = $post->get_wordcount() ?? count_words($message);
433
            $charcount = $post->get_charcount() ?? count_letters($message);
434
        } else {
435
            $wordcount = null;
436
            $charcount = null;
437
        }
438
 
439
        return [
440
            'id' => $post->get_id(),
441
            'subject' => $subject,
1441 ariadna 442
            'replysubject' => $subject,
1 efrain 443
            'message' => $message,
444
            'messageformat' => $post->get_message_format(),
445
            'author' => $exportedauthor,
446
            'discussionid' => $post->get_discussion_id(),
447
            'hasparent' => $post->has_parent(),
448
            'parentid' => $post->has_parent() ? $post->get_parent_id() : null,
449
            'timecreated' => $timecreated,
450
            'timemodified' => $post->get_time_modified(),
451
            'unread' => ($loadcontent && $readreceiptcollection) ? !$readreceiptcollection->has_user_read_post($user, $post) : null,
452
            'isdeleted' => $isdeleted,
453
            'isprivatereply' => $isprivatereply,
454
            'haswordcount' => $showwordcount,
455
            'wordcount' => $wordcount,
456
            'charcount' => $charcount,
457
            'capabilities' => [
458
                'view' => $canview,
459
                'edit' => $canedit,
460
                'delete' => $candelete,
461
                'split' => $cansplit,
462
                'reply' => $canreply,
463
                'export' => $canexport,
464
                'controlreadstatus' => $cancontrolreadstatus,
465
                'canreplyprivately' => $canreplyprivately,
466
                'selfenrol' => $canselfenrol
467
            ],
468
            'urls' => [
469
                'view' => $viewurl ? $viewurl->out(false) : null,
470
                'viewisolated' => $viewisolatedurl ? $viewisolatedurl->out(false) : null,
471
                'viewparent' => $viewparenturl ? $viewparenturl->out(false) : null,
472
                'edit' => $editurl ? $editurl->out(false) : null,
473
                'delete' => $deleteurl ? $deleteurl->out(false) : null,
474
                'split' => $spliturl ? $spliturl->out(false) : null,
475
                'reply' => $replyurl ? $replyurl->out(false) : null,
476
                'export' => $exporturl && $exporturl ? $exporturl->out(false) : null,
477
                'markasread' => $markasreadurl ? $markasreadurl->out(false) : null,
478
                'markasunread' => $markasunreadurl ? $markasunreadurl->out(false) : null,
479
                'discuss' => $discussurl ? $discussurl->out(false) : null,
480
            ],
481
            'attachments' => ($exportattachments) ? $this->export_attachments($attachments, $post, $output, $canexport) : [],
482
            'messageinlinefiles' => ($exportinlineattachments) ? $this->export_inline_attachments($inlineattachments,
483
                $post, $output) : [],
484
            'tags' => ($loadcontent && $hastags) ? $this->export_tags($tags) : [],
485
            'html' => $includehtml ? [
486
                'rating' => ($loadcontent && $hasrating) ? $output->render($rating) : null,
487
                'taglist' => ($loadcontent && $hastags) ? $output->tag_list($tags) : null,
488
                'authorsubheading' => ($loadcontent) ? $this->get_author_subheading_html($exportedauthor, $timecreated) : null
489
            ] : null
490
        ];
491
    }
492
 
493
    /**
494
     * Returns a list of objects that are related.
495
     *
496
     * @return array
497
     */
498
    protected static function define_related() {
499
        return [
500
            'capabilitymanager' => 'mod_forum\local\managers\capability',
501
            'readreceiptcollection' => 'mod_forum\local\entities\post_read_receipt_collection?',
502
            'urlfactory' => 'mod_forum\local\factories\url',
503
            'forum' => 'mod_forum\local\entities\forum',
504
            'discussion' => 'mod_forum\local\entities\discussion',
505
            'author' => 'mod_forum\local\entities\author',
506
            'authorcontextid' => 'int?',
507
            'user' => 'stdClass',
508
            'context' => 'context',
509
            'authorgroups' => 'stdClass[]',
510
            'attachments' => '\stored_file[]?',
511
            'messageinlinefiles' => '\stored_file[]?',
512
            'tags' => '\core_tag_tag[]?',
513
            'rating' => 'rating?',
514
            'includehtml' => 'bool'
515
        ];
516
    }
517
 
518
    /**
519
     * This method returns the parameters for the post's message to
520
     * use with the function \core_external\util::format_text().
521
     *
522
     * @return array
523
     */
524
    protected function get_format_parameters_for_message() {
525
        return [
526
            'component' => 'mod_forum',
527
            'filearea' => 'post',
528
            'itemid' => $this->post->get_id(),
529
            'options' => [
530
                'para' => false,
531
                'trusted' => $this->post->is_message_trusted()
532
            ]
533
        ];
534
    }
535
 
536
    /**
537
     * Get the message text from a post.
538
     *
539
     * @param post_entity $post The post
540
     * @return string
541
     */
542
    private function get_message(post_entity $post): string {
543
        global $CFG;
544
 
545
        $message = $post->get_message();
546
 
547
        if (!empty($CFG->enableplagiarism)) {
548
            require_once($CFG->libdir . '/plagiarismlib.php');
549
            $forum = $this->related['forum'];
550
            $message .= plagiarism_get_links([
551
                'userid' => $post->get_author_id(),
552
                'content' => $message,
553
                'cmid' => $forum->get_course_module_record()->id,
554
                'course' => $forum->get_course_id(),
555
                'forum' => $forum->get_id()
556
            ]);
557
        }
558
 
559
        return $message;
560
    }
561
 
562
    /**
563
     * Get the exported attachments for a post.
564
     *
565
     * @param stored_file[] $attachments The list of attachments for the post
566
     * @param post_entity $post The post being exported
567
     * @param renderer_base $output Renderer base
568
     * @param bool $canexport If the user can export the post (relates to portfolios not exporters like this class)
569
     * @return array
570
     */
571
    private function export_attachments(array $attachments, post_entity $post, renderer_base $output, bool $canexport): array {
572
        global $CFG;
573
 
574
        $urlfactory = $this->related['urlfactory'];
575
        $enableplagiarism = $CFG->enableplagiarism;
576
        $forum = $this->related['forum'];
577
        $context = $this->related['context'];
578
 
579
        if ($enableplagiarism) {
580
            require_once($CFG->libdir . '/plagiarismlib.php' );
581
        }
582
 
583
        return array_map(function($attachment) use (
584
            $output,
585
            $enableplagiarism,
586
            $canexport,
587
            $context,
588
            $forum,
589
            $post,
590
            $urlfactory
591
        ) {
592
            $exporter = new stored_file_exporter($attachment, ['context' => $context]);
593
            $exportedattachment = $exporter->export($output);
594
            $exporturl = $canexport ? $urlfactory->get_export_attachment_url_from_post_and_attachment($post, $attachment) : null;
595
 
596
            if ($enableplagiarism) {
597
                $plagiarismhtml = plagiarism_get_links([
598
                    'userid' => $post->get_author_id(),
599
                    'file' => $attachment,
600
                    'cmid' => $forum->get_course_module_record()->id,
601
                    'course' => $forum->get_course_id(),
602
                    'forum' => $forum->get_id()
603
                ]);
604
            } else {
605
                $plagiarismhtml = null;
606
            }
607
 
608
            $exportedattachment->urls = [
609
                'export' => $exporturl ? $exporturl->out(false) : null
610
            ];
611
            $exportedattachment->html = [
612
                'plagiarism' => $plagiarismhtml
613
            ];
614
 
615
            return $exportedattachment;
616
        }, $attachments);
617
    }
618
 
619
    /**
620
     * Get the exported inline attachments for a post.
621
     *
622
     * @param array $inlineattachments The list of inline attachments for the post
623
     * @param post_entity $post The post being exported
624
     * @param renderer_base $output Renderer base
625
     * @return array
626
     */
627
    private function export_inline_attachments(array $inlineattachments, post_entity $post, renderer_base $output): array {
628
 
629
        return array_map(function($attachment) use (
630
            $output,
631
            $post
632
        ) {
633
            $exporter = new stored_file_exporter($attachment, ['context' => $this->related['context']]);
634
            return $exporter->export($output);;
635
        }, $inlineattachments);
636
    }
637
 
638
    /**
639
     * Export the list of tags.
640
     *
641
     * @param core_tag_tag[] $tags List of tags to export
642
     * @return array
643
     */
644
    private function export_tags(array $tags): array {
645
        $user = $this->related['user'];
646
        $context = $this->related['context'];
647
        $capabilitymanager = $this->related['capabilitymanager'];
648
        $canmanagetags = $capabilitymanager->can_manage_tags($user);
649
 
650
        return array_values(array_map(function($tag) use ($context, $canmanagetags) {
651
            $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $context->id);
652
            return [
653
                'id' => $tag->taginstanceid,
654
                'tagid' => $tag->id,
655
                'isstandard' => $tag->isstandard,
656
                'displayname' => $tag->get_display_name(),
657
                'flag' => $canmanagetags && !empty($tag->flag),
658
                'urls' => [
659
                    'view' => $viewurl->out(false)
660
                ]
661
            ];
662
        }, $tags));
663
    }
664
 
665
    /**
666
     * Get the HTML to display as a subheading in a post.
667
     *
668
     * @param stdClass $exportedauthor The exported author object
669
     * @param int $timecreated The post time created timestamp if it's to be displayed
670
     * @return string
671
     */
672
    private function get_author_subheading_html(stdClass $exportedauthor, int $timecreated): string {
673
        $fullname = $exportedauthor->fullname;
674
        $profileurl = $exportedauthor->urls['profile'] ?? null;
675
        $name = $profileurl ? "<a href=\"{$profileurl}\">{$fullname}</a>" : $fullname;
676
        $date = userdate_htmltime($timecreated, get_string('strftimedaydatetime', 'core_langconfig'));
677
        return get_string('bynameondate', 'mod_forum', ['name' => $name, 'date' => $date]);
678
    }
679
 
680
    /**
681
     * Get the start time for a post.
682
     *
683
     * @param discussion_entity $discussion entity
684
     * @param post_entity $post entity
685
     * @return int The start time (timestamp) for a post
686
     */
687
    private function get_start_time(discussion_entity $discussion, post_entity $post) {
688
        global $CFG;
689
 
690
        $posttime = $post->get_time_created();
691
        $discussiontime = $discussion->get_time_start();
692
        if (!empty($CFG->forum_enabletimedposts) && ($discussiontime > $posttime)) {
693
            return $discussiontime;
694
        }
695
        return $posttime;
696
    }
697
}