ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjForumListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private int $child_id;
30
31 public function init(): void
32 {
33 $this->static_link_enabled = true;
34 $this->delete_enabled = true;
35 $this->cut_enabled = true;
36 $this->copy_enabled = true;
37 $this->subscribe_enabled = true;
38 $this->link_enabled = true;
39 $this->info_screen_enabled = true;
40 $this->type = 'frm';
41 $this->gui_class_name = ilObjForumGUI::class;
42
43 $this->commands = ilObjForumAccess::_getCommands();
44 }
45
46 public function setChildId(int $a_child_id): void
47 {
48 $this->child_id = $a_child_id;
49 }
50
51 public function getChildId(): int
52 {
53 return $this->child_id;
54 }
55
56 public function getProperties(): array
57 {
58 $props = [];
59
60 $maySee = $this->rbacsystem->checkAccess('visible', $this->ref_id);
61 $mayRead = $this->rbacsystem->checkAccess('read', $this->ref_id);
62
63 if (!$maySee && !$mayRead) {
64 return $props;
65 }
66
67 $props = parent::getProperties();
68
69 if (!$mayRead || ilObject::lookupOfflineStatus($this->obj_id)) {
70 return $props;
71 }
72
73 $this->lng->loadLanguageModule('forum');
74
75 $properties = ilObjForumAccess::getStatisticsByRefId($this->ref_id);
76 $num_posts_total = $properties['num_posts'];
77 $num_unread_total = $properties['num_unread_posts'];
78
79 $num_drafts_total = 0;
81 $drafts_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->ref_id);
82 $num_drafts_total = $drafts_statistics['total'];
83 }
84 $num_new_total = 0;
85
86 if (!$this->user->isAnonymous()) {
88 $props[] = [
89 'alert' => false,
90 'property' => $this->lng->txt('forums_articles') . ' (' . $this->lng->txt('unread') . ')',
91 'value' => $num_posts_total . ' (' . $num_unread_total . ')'
92 ];
93 }
94
95 if ($num_drafts_total > 0 && ilForumPostDraft::isSavePostDraftAllowed()) {
96 $props[] = [
97 'alert' => false,
98 'property' => $this->lng->txt('drafts'),
99 'value' => $num_drafts_total
100 ];
101 }
102 } else {
103 $props[] = [
104 'alert' => false,
105 'property' => $this->lng->txt('forums_articles'),
106 'value' => $num_posts_total
107 ];
108 }
109
110 if (
112 ilForumProperties::getInstance($this->obj_id)->isAnonymized()
113 ) {
114 $props[] = [
115 'alert' => false,
116 'newline' => false,
117 'property' => $this->lng->txt('forums_anonymized'),
118 'value' => $this->lng->txt('yes')
119 ];
120 }
121
122 $last_post = ilObjForumAccess::getLastPostByRefId($this->ref_id);
123 if (is_array($last_post) && $last_post['pos_pk'] > 0) {
124 $lpCont = "<a class=\"il_ItemProperty\" target=\"" . ilFrameTargetInfo::_getFrame('MainContent') .
125 "\" href=\"ilias.php?baseClass=" . ilRepositoryGUI::class . "&amp;cmd=viewThread&amp;cmdClass=" .
126 ilObjForumGUI::class . "&amp;target=true&amp;pos_pk=" .
127 $last_post['pos_pk'] . "&amp;thr_pk=" . $last_post['pos_thr_fk'] . "&amp;ref_id=" .
128 $this->ref_id . "#" . $last_post["pos_pk"] . "\">" .
129 ilObjForumAccess::prepareMessageForLists($last_post['pos_message']) . "</a> " .
130 strtolower($this->lng->txt('from')) . "&nbsp;";
131
132 $authorinfo = new ilForumAuthorInformation(
133 (int) $last_post['pos_author_id'],
134 (int) $last_post['pos_display_user_id'],
135 (string) $last_post['pos_usr_alias'],
136 (string) $last_post['import_name'],
137 [
138 'class' => 'il_ItemProperty',
139 'href' => 'ilias.php?baseClass=' . ilRepositoryGUI::class . '&amp;cmd=showUser&amp;' .
140 'cmdClass=' . ilObjForumGUI::class . '&amp;ref_id=' . $this->ref_id . '&amp;' .
141 'user=' . $last_post['pos_display_user_id'] . '&amp;offset=0&amp;backurl=' .
142 urlencode('ilias.php?baseClass=' . ilRepositoryGUI::class . '&amp;ref_id=' . $this->ref_id)
143 ]
144 );
145
146 $lpCont .= $authorinfo->getLinkedAuthorName();
147 $lpCont .= ', ' . ilDatePresentation::formatDate(new ilDateTime($last_post['pos_date'], IL_CAL_DATETIME));
148
149 $props[] = [
150 'alert' => false,
151 'newline' => true,
152 'property' => $this->lng->txt('forums_last_post'),
153 'value' => $lpCont
154 ];
155 }
156
157 return $props;
158 }
159
160 public function getCommandLink(string $cmd): string
161 {
162 switch ($cmd) {
163 case 'thread':
164 return (
165 'ilias.php?baseClass=' . ilRepositoryGUI::class . '&amp;cmd=viewThread&amp;cmdClass=' .
166 ilObjForumGUI::class . '&amp;ref_id=' . $this->ref_id . '&amp;thr_pk=' . $this->getChildId()
167 );
168
169 case 'posting':
170 $thread_post = $this->getChildId();
171 // TODO PHP 8 This cannot be correct, an id which is used as an array (don't know what is the correct code here) ...
172 return (
173 'ilias.php?baseClass=' . ilRepositoryGUI::class . '&amp;cmd=viewThread&amp;cmdClass=' .
174 ilObjForumGUI::class . '&amp;target=1&amp;ref_id=' . $this->ref_id . '&amp;thr_pk=' .
175 $thread_post[0] . '&amp;pos_pk=' . $thread_post[1] . '#' . $thread_post[1]
176 );
177
178 default:
179 return parent::getCommandLink($cmd);
180 }
181 }
182}
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static getDraftsStatisticsByRefId(int $ref_id)
static getInstance(int $a_obj_id=0)
static _getFrame(string $a_class)
static getStatisticsByRefId(int $ref_id)
static _getCommands()
get commands
static prepareMessageForLists(string $text)
static getLastPostByRefId(int $ref_id)
Class ilObjForumListGUI.
setChildId(int $a_child_id)
getProperties()
Get item properties.
getCommandLink(string $cmd)
Get command link url.
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.