ILIAS  release_8 Revision v8.24
class.ilForumTopicTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
31 private bool $is_moderator = false;
32 private int $ref_id = 0;
33 private int $overview_setting = 0;
36 private int $position = 1;
41
42 public function __construct(
43 ilObjForumGUI $a_parent_obj,
44 string $a_parent_cmd,
45 int $ref_id,
47 bool $is_moderator = false,
48 int $overview_setting = 0
49 ) {
50 global $DIC;
51
52 $this->lng = $DIC->language();
53 $this->mainTemplate = $DIC->ui()->mainTemplate();
54 $this->user = $DIC->user();
55 $this->settings = $DIC->settings();
56
57 $this->parent_cmd = $a_parent_cmd;
58 $this->setIsModerator($is_moderator);
59 $this->setOverviewSetting($overview_setting);
60 $this->setRefId($ref_id);
61 $this->setTopicData($topicData);
62
63 $id = 'frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_' . $this->getRefId();
64 $this->setId($id);
65
66 $this->setDefaultOrderDirection('DESC');
67 $this->setDefaultOrderField('lp_date');
68 $this->setExternalSorting(true);
69 $this->setExternalSegmentation(true);
70
71 parent::__construct($a_parent_obj, $a_parent_cmd);
72 $this->mainTemplate->addCss('./Modules/Forum/css/forum_table.css');
73 $this->is_post_draft_allowed = ilForumPostDraft::isSavePostDraftAllowed();
74 }
75
76 public function init(): void
77 {
78 if ($this->parent_cmd === 'mergeThreads') {
79 $this->initMergeThreadsTable();
80 } else {
82 }
83 }
84
85 public function initTopicsOverviewTable(): void
86 {
87 if ($this->parent_cmd === "showThreads") {
88 $this->setSelectAllCheckbox('thread_ids');
89 $this->addColumn('', 'check', '1px', true);
90 } else {
91 $this->addColumn('', 'check', '10px', true);
92 }
93
94 $this->addColumn($this->lng->txt('forums_thread'), 'thr_subject');
95 $this->addColumn($this->lng->txt('forums_created_by'), '');
96 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
97 $this->addColumn($this->lng->txt('visits'), 'num_visit');
98
99 if ($this->is_post_draft_allowed) {
100 $this->addColumn($this->lng->txt('drafts', ''));
101 }
102
103 $this->addColumn($this->lng->txt('forums_last_post'), 'post_date');
104 if ('showThreads' === $this->parent_cmd && $this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
105 $this->addColumn($this->lng->txt('frm_rating'), 'rating');
106 }
107
108 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
109 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
110
111 if ($this->parent_cmd === 'sortThreads') {
112 $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
113 } else {
114 $this->addMultiCommand('', $this->lng->txt('please_choose'));
115 if ($this->settings->get('forum_notification') > 0 && !$this->user->isAnonymous()) {
116 $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
117 $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
118 }
119 if ($this->getIsModerator()) {
120 $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
121 $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
122 $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
123 $this->addMultiCommand('close', $this->lng->txt('close_topics'));
124 $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
125 $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
126 }
127 $this->addMultiCommand('html', $this->lng->txt('export_html'));
128 if ($this->getIsModerator()) {
129 $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
130 $this->addMultiCommand('mergeThreads', $this->lng->txt('merge_posts_into_thread'));
131 }
132 }
133 $this->setShowRowsSelector(true);
134 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
135 }
136
137 public function initMergeThreadsTable(): void
138 {
139 $this->addColumn('', 'check', '1px', true);
140 $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
141 $this->addColumn($this->lng->txt('forums_created_by'), 'author');
142 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
143 $this->addColumn($this->lng->txt('visits'), 'num_visit');
144 if ($this->is_post_draft_allowed) {
145 $this->addColumn($this->lng->txt('drafts', ''));
146 }
147 $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
148
149 $this->disable('sort');
150 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
151 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
152
153 $this->mainTemplate->setOnScreenMessage('info', $this->lng->txt('please_choose_target'));
154
155 $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
156
157 $this->addCommandButton('confirmMergeThreads', $this->lng->txt('merge'));
158 $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
159 $this->setShowRowsSelector(true);
160 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
161 }
162
163 protected function fillRow(array $a_set): void
164 {
166 $thread = $a_set['thread'];
167
168 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
169 global $DIC;
170 $thread_ids = [];
171 if ($DIC->http()->wrapper()->post()->has('thread_ids')) {
172 $thread_ids = $DIC->http()->wrapper()->post()->retrieve(
173 'thread_ids',
174 $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->int())
175 );
176 }
177
178 if ('mergeThreads' === $this->parent_cmd) {
179 $checked = $this->max_count === 1 || (isset($thread_ids) && in_array($thread->getId(), $thread_ids, true));
180 $this->tpl->setVariable(
181 'VAL_CHECK',
183 $checked,
184 'thread_ids[]',
185 (string) $thread->getId()
186 )
187 );
188 } elseif ('showThreads' === $this->parent_cmd) {
189 $this->tpl->setVariable(
190 'VAL_CHECK',
192 (isset($thread_ids) && in_array($thread->getId(), $thread_ids, true)),
193 'thread_ids[]',
194 (string) $thread->getId()
195 )
196 );
197
198 if ($this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
199 $rating = new ilRatingGUI();
200 $rating->setObject(
201 $this->parent_obj->getObject()->getId(),
202 $this->parent_obj->getObject()->getType(),
203 $thread->getId(),
204 'thread'
205 );
206 $rating->setUserId($this->user->getId());
207 $this->tpl->setVariable('VAL_RATING', $rating->getHTML());
208 }
209 } else {
210 if ($thread->isSticky()) {
211 $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']');
212 $this->tpl->setVariable('VAL_SORTING', $this->position * 10);
213 } else {
214 $this->tpl->setVariable('VAL_CHECK', '');
215 }
216 $this->position++;
217 }
218 $subject = '';
219
220 if ($thread->isSticky()) {
221 $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
222 }
223 if ($thread->isClosed()) {
224 $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
225 }
226
227 if (!$this->user->isAnonymous() &&
228 (int) $this->settings->get('forum_notification', '0') !== 0 &&
229 $thread->isUserNotificationEnabled()
230 ) {
231 $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
232 }
233
234 $num_posts = $thread->getNumPosts();
235 $num_unread = $thread->getNumUnreadPosts();
236 $num_new = $thread->getNumNewPosts();
237
238 $this->ctrl->setParameter($this->getParentObject(), 'page', 0);
239 $subject = '<div><a href="' . $this->ctrl->getLinkTarget(
240 $this->getParentObject(),
241 'viewThread'
242 ) . '">' . $thread->getSubject() . '</a></div>' . $subject;
243 $this->ctrl->setParameter($this->getParentObject(), 'page', null);
244 $this->tpl->setVariable('VAL_SUBJECT', $subject);
245
246 $this->ctrl->setParameter(
247 $this->getParentObject(),
248 'backurl',
249 urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", ""))
250 );
251 $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
252
253 $authorinfo = new ilForumAuthorInformation(
254 $thread->getThrAuthorId(),
255 $thread->getDisplayUserId(),
256 (string) $thread->getUserAlias(),
257 (string) $thread->getImportName(),
258 [
259 'class' => 'il_ItemProperty',
260 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
261 ]
262 );
263 $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
264
265 $topicStats = $num_posts;
266 if (!$this->user->isAnonymous()) {
267 if ($num_unread > 0) {
268 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
269 }
271 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
272 }
273 }
274
275 $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
276 $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
277 if ($this->is_post_draft_allowed) {
278 $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
279 $this->tpl->setVariable(
280 'VAL_DRAFTS',
281 (int) isset($draft_statistics[$thread->getId()]) ? $draft_statistics[$thread->getId()] : 0
282 );
283 }
284
285 if ($num_posts > 0 && $thread->getLastPostForThreadOverview() instanceof ilForumPost) {
286 $objLastPost = $thread->getLastPostForThreadOverview();
287
288 $this->ctrl->setParameter($this->getParentObject(), 'user', $objLastPost->getDisplayUserId());
289 $authorinfo = new ilForumAuthorInformation(
290 $objLastPost->getPosAuthorId(),
291 $objLastPost->getDisplayUserId(),
292 (string) $objLastPost->getUserAlias(),
293 (string) $objLastPost->getImportName(),
294 [
295 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
296 ]
297 );
298
299 $this->tpl->setVariable(
300 'VAL_LP_DATE',
301 '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime(
302 $objLastPost->getCreateDate(),
304 )) . '</div>' .
305 '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
306 );
307 }
308
310 if ($thread->isSticky()) {
311 $css_row = $css_row === 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
312 }
313 $this->tpl->setVariable('CSS_ROW', $css_row);
314
315 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
316 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
317 $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
318 }
319
320 public function fetchData(): ilForumTopicTableGUI
321 {
323
324 $excluded_ids = [];
325 if ($this->parent_cmd === 'mergeThreads' &&
326 $this->getSelectedThread() instanceof ilForumTopic) {
327 $excluded_ids[] = $this->getSelectedThread()->getId();
328 }
329
330 $params = [
331 'is_moderator' => $this->getIsModerator(),
332 'excluded_ids' => $excluded_ids,
333 'order_column' => $this->getOrderField(),
334 'order_direction' => $this->getOrderDirection()
335 ];
336
337 $data = $this->getMapper()->getAllThreads(
338 $this->topicData->getTopPk(),
339 $params,
340 $this->getLimit(),
341 $this->getOffset()
342 );
343 if (!count($data['items']) && $this->getOffset() > 0) {
344 $this->resetOffset();
345 $data = $this->getMapper()->getAllThreads(
346 $this->topicData->getTopPk(),
347 $params,
348 $this->getLimit(),
349 $this->getOffset()
350 );
351 }
352
353 $this->setMaxCount($data['cnt']);
354 $this->setData(array_map(static function (ilForumTopic $thread): array {
355 return ['thread' => $thread];
356 }, $data['items']));
357
358 $thread_ids = [];
359 $user_ids = [];
360 foreach ($data['items'] as $thread) {
362 $thread_ids[] = $thread->getId();
363 if ($thread->getDisplayUserId() > 0) {
364 $user_ids[$thread->getDisplayUserId()] = $thread->getDisplayUserId();
365 }
366 }
367
368 $user_ids = array_merge(
370 $user_ids
371 );
372
374
375 return $this;
376 }
377
378 public function setMapper(ilForum $mapper): self
379 {
380 $this->mapper = $mapper;
381 return $this;
382 }
383
384 public function getMapper(): ilForum
385 {
386 return $this->mapper;
387 }
388
389 public function setRefId(int $ref_id): self
390 {
391 $this->ref_id = $ref_id;
392 return $this;
393 }
394
395 public function getRefId(): int
396 {
397 return $this->ref_id;
398 }
399
400 public function setOverviewSetting(int $overview_setting): self
401 {
402 $this->overview_setting = $overview_setting;
403 return $this;
404 }
405
406 public function getOverviewSetting(): int
407 {
409 }
410
411 public function setIsModerator(bool $is_moderator): self
412 {
413 $this->is_moderator = $is_moderator;
414 return $this;
415 }
416
417 public function getIsModerator(): bool
418 {
419 return $this->is_moderator;
420 }
421
422 public function setTopicData(ForumDto $topicData): self
423 {
424 $this->topicData = $topicData;
425 return $this;
426 }
427
428 public function getTopicData(): ForumDto
429 {
430 return $this->topicData;
431 }
432
433 public function setSelectedThread(ilForumTopic $thread_obj): self
434 {
435 $this->merge_thread_obj = $thread_obj;
436 return $this;
437 }
438
439 public function getSelectedThread(): ?ilForumTopic
440 {
442 }
443}
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
static getDraftsStatisticsByRefId(int $ref_id)
Class ilForumTopicTableGUI.
__construct(ilObjForumGUI $a_parent_obj, string $a_parent_cmd, int $ref_id, ForumDto $topicData, bool $is_moderator=false, int $overview_setting=0)
setSelectedThread(ilForumTopic $thread_obj)
ilGlobalTemplateInterface $mainTemplate
setOverviewSetting(int $overview_setting)
setIsModerator(bool $is_moderator)
setTopicData(ForumDto $topicData)
Class Forum core functions for forum.
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
static formRadioButton(bool $checked, string $varname, string $value, string $onclick=null, bool $disabled=false)
Class ilObjForumGUI.
static getUserIdsOfLastPostsByRefIdAndThreadIds(int $ref_id, array $thread_ids)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setRowSelectorLabel(string $row_selector_label)
determineOffsetAndOrder(bool $a_omit_offset=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExternalSegmentation(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
fillRow(array $a_set)
Standard Version of Fill Row.
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
disable(string $a_module_name)
setMaxCount(int $a_max_count)
set max.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc