-
Notifications
You must be signed in to change notification settings - Fork 4
/
locallib.php
702 lines (642 loc) · 28 KB
/
locallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library of functions for reactforum outside of the core api
*/
require_once($CFG->dirroot . '/mod/reactforum/lib.php');
require_once($CFG->libdir . '/portfolio/caller.php');
/**
* @package mod_reactforum
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class reactforum_portfolio_caller extends portfolio_module_caller_base {
protected $postid;
protected $discussionid;
protected $attachment;
private $post;
private $reactforum;
private $discussion;
private $posts;
private $keyedfiles; // just using multifiles isn't enough if we're exporting a full thread
/**
* @return array
*/
public static function expected_callbackargs() {
return array(
'postid' => false,
'discussionid' => false,
'attachment' => false,
);
}
/**
* @param array $callbackargs
*/
function __construct($callbackargs) {
parent::__construct($callbackargs);
if (!$this->postid && !$this->discussionid) {
throw new portfolio_caller_exception('mustprovidediscussionorpost', 'reactforum');
}
}
/**
* @global object
*/
public function load_data() {
global $DB;
if ($this->postid) {
if (!$this->post = $DB->get_record('reactforum_posts', array('id' => $this->postid))) {
throw new portfolio_caller_exception('invalidpostid', 'reactforum');
}
}
$dparams = array();
if ($this->discussionid) {
$dbparams = array('id' => $this->discussionid);
} else if ($this->post) {
$dbparams = array('id' => $this->post->discussion);
} else {
throw new portfolio_caller_exception('mustprovidediscussionorpost', 'reactforum');
}
if (!$this->discussion = $DB->get_record('reactforum_discussions', $dbparams)) {
throw new portfolio_caller_exception('invaliddiscussionid', 'reactforum');
}
if (!$this->reactforum = $DB->get_record('reactforum', array('id' => $this->discussion->reactforum))) {
throw new portfolio_caller_exception('invalidreactforumid', 'reactforum');
}
if (!$this->cm = get_coursemodule_from_instance('reactforum', $this->reactforum->id)) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
$this->modcontext = context_module::instance($this->cm->id);
$fs = get_file_storage();
if ($this->post) {
if ($this->attachment) {
// Make sure the requested file belongs to this post.
$file = $fs->get_file_by_id($this->attachment);
if ($file->get_contextid() != $this->modcontext->id
|| $file->get_itemid() != $this->post->id) {
throw new portfolio_caller_exception('filenotfound');
}
$this->set_file_and_format_data($this->attachment);
} else {
$attach = $fs->get_area_files($this->modcontext->id, 'mod_reactforum', 'attachment', $this->post->id, 'timemodified', false);
$embed = $fs->get_area_files($this->modcontext->id, 'mod_reactforum', 'post', $this->post->id, 'timemodified', false);
$files = array_merge($attach, $embed);
$this->set_file_and_format_data($files);
}
if (!empty($this->multifiles)) {
$this->keyedfiles[$this->post->id] = $this->multifiles;
} else if (!empty($this->singlefile)) {
$this->keyedfiles[$this->post->id] = array($this->singlefile);
}
} else { // whole thread
$fs = get_file_storage();
$this->posts = reactforum_get_all_discussion_posts($this->discussion->id, 'p.created ASC');
$this->multifiles = array();
foreach ($this->posts as $post) {
$attach = $fs->get_area_files($this->modcontext->id, 'mod_reactforum', 'attachment', $post->id, 'timemodified', false);
$embed = $fs->get_area_files($this->modcontext->id, 'mod_reactforum', 'post', $post->id, 'timemodified', false);
$files = array_merge($attach, $embed);
if ($files) {
$this->keyedfiles[$post->id] = $files;
} else {
continue;
}
$this->multifiles = array_merge($this->multifiles, array_values($this->keyedfiles[$post->id]));
}
}
if (empty($this->multifiles) && !empty($this->singlefile)) {
$this->multifiles = array($this->singlefile); // copy_files workaround
}
// depending on whether there are files or not, we might have to change richhtml/plainhtml
if (empty($this->attachment)) {
if (!empty($this->multifiles)) {
$this->add_format(PORTFOLIO_FORMAT_RICHHTML);
} else {
$this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
}
}
}
/**
* @global object
* @return string
*/
function get_return_url() {
global $CFG;
return $CFG->wwwroot . '/mod/reactforum/discuss.php?d=' . $this->discussion->id;
}
/**
* @global object
* @return array
*/
function get_navigation() {
global $CFG;
$navlinks = array();
$navlinks[] = array(
'name' => format_string($this->discussion->name),
'link' => $CFG->wwwroot . '/mod/reactforum/discuss.php?d=' . $this->discussion->id,
'type' => 'title'
);
return array($navlinks, $this->cm);
}
/**
* either a whole discussion
* a single post, with or without attachment
* or just an attachment with no post
*
* @global object
* @global object
* @uses PORTFOLIO_FORMAT_RICH
* @return mixed
*/
function prepare_package() {
global $CFG;
// set up the leap2a writer if we need it
$writingleap = false;
if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
$leapwriter = $this->exporter->get('format')->leap2a_writer();
$writingleap = true;
}
if ($this->attachment) { // simplest case first - single file attachment
$this->copy_files(array($this->singlefile), $this->attachment);
if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
$entry = new portfolio_format_leap2a_file($this->singlefile->get_filename(), $this->singlefile);
$leapwriter->add_entry($entry);
return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
}
} else if (empty($this->post)) { // exporting whole discussion
$content = ''; // if we're just writing HTML, start a string to add each post to
$ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
foreach ($this->posts as $post) {
$posthtml = $this->prepare_post($post);
if ($writingleap) {
$ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
} else {
$content .= $posthtml . '<br /><br />';
}
}
$this->copy_files($this->multifiles);
$name = 'discussion.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
// add on an extra 'selection' entry
$selection = new portfolio_format_leap2a_entry('reactforumdiscussion' . $this->discussionid,
get_string('discussion', 'reactforum') . ': ' . $this->discussion->name, 'selection');
$leapwriter->add_entry($selection);
$leapwriter->make_selection($selection, $ids, 'Grouping');
$content = $leapwriter->to_xml();
$name = $this->get('exporter')->get('format')->manifest_name();
}
$this->get('exporter')->write_new_file($content, $name, $manifest);
} else { // exporting a single post
$posthtml = $this->prepare_post($this->post);
$content = $posthtml;
$name = 'post.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
$this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
$content = $leapwriter->to_xml();
$name = $this->exporter->get('format')->manifest_name();
}
$this->copy_files($this->multifiles);
$this->get('exporter')->write_new_file($content, $name, $manifest);
}
}
/**
* helper function to add a leap2a entry element
* that corresponds to a single reactforum post,
* including any attachments
*
* the entry/ies are added directly to the leapwriter, which is passed by ref
*
* @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to
* @param object $post the stdclass object representing the database record
* @param string $posthtml the content of the post (prepared by {@link prepare_post}
*
* @return int id of new entry
*/
private function prepare_post_leap2a(portfolio_format_leap2a_writer $leapwriter, $post, $posthtml) {
$entry = new portfolio_format_leap2a_entry('reactforumpost' . $post->id, $post->subject, 'resource', $posthtml);
$entry->published = $post->created;
$entry->updated = $post->modified;
$entry->author = $post->author;
if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id])) {
$leapwriter->link_files($entry, $this->keyedfiles[$post->id], 'reactforumpost' . $post->id . 'attachment');
}
$entry->add_category('web', 'resource_type');
$leapwriter->add_entry($entry);
return $entry->id;
}
/**
* @param array $files
* @param mixed $justone false of id of single file to copy
* @return bool|void
*/
private function copy_files($files, $justone=false) {
if (empty($files)) {
return;
}
foreach ($files as $f) {
if ($justone && $f->get_id() != $justone) {
continue;
}
$this->get('exporter')->copy_existing_file($f);
if ($justone && $f->get_id() == $justone) {
return true; // all we need to do
}
}
}
/**
* this is a very cut down version of what is in reactforum_make_mail_post
*
* @global object
* @param int $post
* @return string
*/
private function prepare_post($post, $fileoutputextras=null) {
global $DB;
static $users;
if (empty($users)) {
$users = array($this->user->id => $this->user);
}
if (!array_key_exists($post->userid, $users)) {
$users[$post->userid] = $DB->get_record('user', array('id' => $post->userid));
}
// add the user object on to the post so we can pass it to the leap writer if necessary
$post->author = $users[$post->userid];
$viewfullnames = true;
// format the post body
$options = portfolio_format_text_options();
$format = $this->get('exporter')->get('format');
$formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
$formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $this->modcontext->id, 'mod_reactforum', 'post', $post->id, $format);
$output = '<table border="0" cellpadding="3" cellspacing="0" class="reactforumpost">';
$output .= '<tr class="header"><td>';// can't print picture.
$output .= '</td>';
if ($post->parent) {
$output .= '<td class="topic">';
} else {
$output .= '<td class="topic starter">';
}
$output .= '<div class="subject">'.format_string($post->subject).'</div>';
$fullname = fullname($users[$post->userid], $viewfullnames);
$by = new stdClass();
$by->name = $fullname;
$by->date = userdate($post->modified, '', core_date::get_user_timezone($this->user));
$output .= '<div class="author">'.get_string('bynameondate', 'reactforum', $by).'</div>';
$output .= '</td></tr>';
$output .= '<tr><td class="left side" valign="top">';
$output .= '</td><td class="content">';
$output .= $formattedtext;
if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) {
$output .= '<div class="attachments">';
$output .= '<br /><b>' . get_string('attachments', 'reactforum') . '</b>:<br /><br />';
foreach ($this->keyedfiles[$post->id] as $file) {
$output .= $format->file_output($file) . '<br/ >';
}
$output .= "</div>";
}
$output .= '</td></tr></table>'."\n\n";
return $output;
}
/**
* @return string
*/
function get_sha1() {
$filesha = '';
try {
$filesha = $this->get_sha1_file();
} catch (portfolio_caller_exception $e) { } // no files
if ($this->post) {
return sha1($filesha . ',' . $this->post->subject . ',' . $this->post->message);
} else {
$sha1s = array($filesha);
foreach ($this->posts as $post) {
$sha1s[] = sha1($post->subject . ',' . $post->message);
}
return sha1(implode(',', $sha1s));
}
}
function expected_time() {
$filetime = $this->expected_time_file();
if ($this->posts) {
$posttime = portfolio_expected_time_db(count($this->posts));
if ($filetime < $posttime) {
return $posttime;
}
}
return $filetime;
}
/**
* @uses CONTEXT_MODULE
* @return bool
*/
function check_permissions() {
$context = context_module::instance($this->cm->id);
if ($this->post) {
return (has_capability('mod/reactforum:exportpost', $context)
|| ($this->post->userid == $this->user->id
&& has_capability('mod/reactforum:exportownpost', $context)));
}
return has_capability('mod/reactforum:exportdiscussion', $context);
}
/**
* @return string
*/
public static function display_name() {
return get_string('modulename', 'reactforum');
}
public static function base_supported_formats() {
return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A);
}
}
/**
* Class representing the virtual node with all itemids in the file browser
*
* @category files
* @copyright 2012 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class reactforum_file_info_container extends file_info {
/** @var file_browser */
protected $browser;
/** @var stdClass */
protected $course;
/** @var stdClass */
protected $cm;
/** @var string */
protected $component;
/** @var stdClass */
protected $context;
/** @var array */
protected $areas;
/** @var string */
protected $filearea;
/**
* Constructor (in case you did not realize it ;-)
*
* @param file_browser $browser
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
* @param array $areas
* @param string $filearea
*/
public function __construct($browser, $course, $cm, $context, $areas, $filearea) {
parent::__construct($browser, $context);
$this->browser = $browser;
$this->course = $course;
$this->cm = $cm;
$this->component = 'mod_reactforum';
$this->context = $context;
$this->areas = $areas;
$this->filearea = $filearea;
}
/**
* @return array with keys contextid, filearea, itemid, filepath and filename
*/
public function get_params() {
return array(
'contextid' => $this->context->id,
'component' => $this->component,
'filearea' => $this->filearea,
'itemid' => null,
'filepath' => null,
'filename' => null,
);
}
/**
* Can new files or directories be added via the file browser
*
* @return bool
*/
public function is_writable() {
return false;
}
/**
* Should this node be considered as a folder in the file browser
*
* @return bool
*/
public function is_directory() {
return true;
}
/**
* Returns localised visible name of this node
*
* @return string
*/
public function get_visible_name() {
return $this->areas[$this->filearea];
}
/**
* Returns list of children nodes
*
* @return array of file_info instances
*/
public function get_children() {
return $this->get_filtered_children('*', false, true);
}
/**
* Help function to return files matching extensions or their count
*
* @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
* @param bool|int $countonly if false returns the children, if an int returns just the
* count of children but stops counting when $countonly number of children is reached
* @param bool $returnemptyfolders if true returns items that don't have matching files inside
* @return array|int array of file_info instances or the count
*/
private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) {
global $DB;
$params = array('contextid' => $this->context->id,
'component' => $this->component,
'filearea' => $this->filearea);
$sql = 'SELECT DISTINCT itemid
FROM {files}
WHERE contextid = :contextid
AND component = :component
AND filearea = :filearea';
if (!$returnemptyfolders) {
$sql .= ' AND filename <> :emptyfilename';
$params['emptyfilename'] = '.';
}
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$sql .= ' '.$sql2;
$params = array_merge($params, $params2);
if ($countonly !== false) {
$sql .= ' ORDER BY itemid DESC';
}
$rs = $DB->get_recordset_sql($sql, $params);
$children = array();
foreach ($rs as $record) {
if (($child = $this->browser->get_file_info($this->context, 'mod_reactforum', $this->filearea, $record->itemid))
&& ($returnemptyfolders || $child->count_non_empty_children($extensions))) {
$children[] = $child;
}
if ($countonly !== false && count($children) >= $countonly) {
break;
}
}
$rs->close();
if ($countonly !== false) {
return count($children);
}
return $children;
}
/**
* Returns list of children which are either files matching the specified extensions
* or folders that contain at least one such file.
*
* @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
* @return array of file_info instances
*/
public function get_non_empty_children($extensions = '*') {
return $this->get_filtered_children($extensions, false);
}
/**
* Returns the number of children which are either files matching the specified extensions
* or folders containing at least one such file.
*
* @param string|array $extensions, for example '*' or array('.gif','.jpg')
* @param int $limit stop counting after at least $limit non-empty children are found
* @return int
*/
public function count_non_empty_children($extensions = '*', $limit = 1) {
return $this->get_filtered_children($extensions, $limit);
}
/**
* Returns parent file_info instance
*
* @return file_info or null for root
*/
public function get_parent() {
return $this->browser->get_file_info($this->context);
}
}
/**
* Returns reactforum posts tagged with a specified tag.
*
* This is a callback used by the tag area mod_reactforum/reactforum_posts to search for reactforum posts
* tagged with a specific tag.
*
* @param core_tag_tag $tag
* @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
* are displayed on the page and the per-page limit may be bigger
* @param int $fromctx context id where the link was displayed, may be used by callbacks
* to display items in the same context first
* @param int $ctx context id where to search for records
* @param bool $rec search in subcontexts as well
* @param int $page 0-based number of page being displayed
* @return \core_tag\output\tagindex
*/
function mod_reactforum_get_tagged_posts($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) {
global $OUTPUT;
$perpage = $exclusivemode ? 20 : 5;
// Build the SQL query.
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
$query = "SELECT fp.id, fp.subject, fd.reactforum, fp.discussion, f.type, fd.timestart, fd.timeend, fd.groupid, fd.firstpost,
fp.parent, fp.userid,
cm.id AS cmid, c.id AS courseid, c.shortname, c.fullname, $ctxselect
FROM {reactforum_posts} fp
JOIN {reactforum_discussions} fd ON fp.discussion = fd.id
JOIN {reactforum} f ON f.id = fd.reactforum
JOIN {modules} m ON m.name='reactforum'
JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = f.id
JOIN {tag_instance} tt ON fp.id = tt.itemid
JOIN {course} c ON cm.course = c.id
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :coursemodulecontextlevel
WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid AND tt.component = :component
AND cm.deletioninprogress = 0
AND fp.id %ITEMFILTER% AND c.id %COURSEFILTER%";
$params = array('itemtype' => 'reactforum_posts', 'tagid' => $tag->id, 'component' => 'mod_reactforum',
'coursemodulecontextlevel' => CONTEXT_MODULE);
if ($ctx) {
$context = $ctx ? context::instance_by_id($ctx) : context_system::instance();
$query .= $rec ? ' AND (ctx.id = :contextid OR ctx.path LIKE :path)' : ' AND ctx.id = :contextid';
$params['contextid'] = $context->id;
$params['path'] = $context->path.'/%';
}
$query .= " ORDER BY ";
if ($fromctx) {
// In order-clause specify that modules from inside "fromctx" context should be returned first.
$fromcontext = context::instance_by_id($fromctx);
$query .= ' (CASE WHEN ctx.id = :fromcontextid OR ctx.path LIKE :frompath THEN 0 ELSE 1 END),';
$params['fromcontextid'] = $fromcontext->id;
$params['frompath'] = $fromcontext->path.'/%';
}
$query .= ' c.sortorder, cm.id, fp.id';
$totalpages = $page + 1;
// Use core_tag_index_builder to build and filter the list of items.
$builder = new core_tag_index_builder('mod_reactforum', 'reactforum_posts', $query, $params, $page * $perpage, $perpage + 1);
while ($item = $builder->has_item_that_needs_access_check()) {
context_helper::preload_from_record($item);
$courseid = $item->courseid;
if (!$builder->can_access_course($courseid)) {
$builder->set_accessible($item, false);
continue;
}
$modinfo = get_fast_modinfo($builder->get_course($courseid));
// Set accessibility of this item and all other items in the same course.
$builder->walk(function ($taggeditem) use ($courseid, $modinfo, $builder, $item) {
// Checking permission for Q&A reactforums performs additional DB queries, do not do them in bulk.
if ($taggeditem->courseid == $courseid && ($taggeditem->type != 'qanda' || $taggeditem->id == $item->id)) {
$cm = $modinfo->get_cm($taggeditem->cmid);
$reactforum = (object)['id' => $taggeditem->reactforum,
'course' => $taggeditem->courseid,
'type' => $taggeditem->type
];
$discussion = (object)['id' => $taggeditem->discussion,
'timestart' => $taggeditem->timestart,
'timeend' => $taggeditem->timeend,
'groupid' => $taggeditem->groupid,
'firstpost' => $taggeditem->firstpost
];
$post = (object)['id' => $taggeditem->id,
'parent' => $taggeditem->parent,
'userid' => $taggeditem->userid,
'groupid' => $taggeditem->groupid
];
$accessible = reactforum_user_can_see_post($reactforum, $discussion, $post, null, $cm);
$builder->set_accessible($taggeditem, $accessible);
}
});
}
$items = $builder->get_items();
if (count($items) > $perpage) {
$totalpages = $page + 2; // We don't need exact page count, just indicate that the next page exists.
array_pop($items);
}
// Build the display contents.
if ($items) {
$tagfeed = new core_tag\output\tagfeed();
foreach ($items as $item) {
context_helper::preload_from_record($item);
$modinfo = get_fast_modinfo($item->courseid);
$cm = $modinfo->get_cm($item->cmid);
$pageurl = new moodle_url('/mod/reactforum/discuss.php', array('d' => $item->discussion), 'p' . $item->id);
$pagename = format_string($item->subject, true, array('context' => context_module::instance($item->cmid)));
$pagename = html_writer::link($pageurl, $pagename);
$courseurl = course_get_url($item->courseid, $cm->sectionnum);
$cmname = html_writer::link($cm->url, $cm->get_formatted_name());
$coursename = format_string($item->fullname, true, array('context' => context_course::instance($item->courseid)));
$coursename = html_writer::link($courseurl, $coursename);
$icon = html_writer::link($pageurl, html_writer::empty_tag('img', array('src' => $cm->get_icon_url())));
$tagfeed->add($icon, $pagename, $cmname.'<br>'.$coursename);
}
$content = $OUTPUT->render_from_template('core_tag/tagfeed',
$tagfeed->export_for_template($OUTPUT));
return new core_tag\output\tagindex($tag, 'mod_reactforum', 'reactforum_posts', $content,
$exclusivemode, $fromctx, $ctx, $rec, $page, $totalpages);
}
}