ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilForumTopicTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $mapper;
17
21 protected $is_moderator = false;
22
26 protected $ref_id = 0;
27
31 protected $overview_setting = '';
32
36 protected $topicData = array();
37
41 protected $ctrl;
42
46 protected $merge_thread_obj = null;
47
51 public $position = 1;
52
56 public $is_post_draft_allowed = false;
57
61 protected $mainTemplate;
62
63 private $user;
64 private $settings;
65
74 public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
75 {
76 global $DIC;
77
78 $this->lng = $DIC->language();
79 $this->ctrl = $DIC->ctrl();
80 $this->mainTemplate = $DIC->ui()->mainTemplate();
81 $this->user = $DIC->user();
82 $this->settings = $DIC->settings();
83
84 $this->parent_cmd = $a_parent_cmd;
87 $this->setRefId($ref_id);
89
90 // Call this immediately in constructor
91 $id = 'frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_' . $this->getRefId();
92 $this->setId($id);
93
94 // Let the database do the work
95 $this->setDefaultOrderDirection('DESC');
96 $this->setDefaultOrderField('lp_date');
97 $this->setExternalSorting(true);
98 $this->setExternalSegmentation(true);
99
100 parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
101
102 // Add global css for table styles
103 $this->mainTemplate->addCss('./Modules/Forum/css/forum_table.css');
104
105 $this->is_post_draft_allowed = ilForumPostDraft::isSavePostDraftAllowed();
106 }
107
108 public function init()
109 {
110 if ($this->parent_cmd == 'mergeThreads') {
111 $this->initMergeThreadsTable();
112 } else {
114 }
115 }
116
120 public function initTopicsOverviewTable()
121 {
122 if ($this->parent_cmd == "showThreads") {
123 $this->setSelectAllCheckbox('thread_ids');
124 $this->addColumn('', 'check', '1px', true);
125 } else {
126 $this->addColumn('', 'check', '10px', true);
127 }
128
129 $this->addColumn($this->lng->txt('forums_thread'), 'thr_subject');
130 $this->addColumn($this->lng->txt('forums_created_by'), '');
131 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
132 $this->addColumn($this->lng->txt('visits'), 'num_visit');
133
134 if ($this->is_post_draft_allowed) {
135 $this->addColumn($this->lng->txt('drafts', ''));
136 }
137
138 $this->addColumn($this->lng->txt('forums_last_post'), 'post_date');
139 if ('showThreads' == $this->parent_cmd && $this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
140 $this->addColumn($this->lng->txt('frm_rating'), 'rating');
141 }
142
143 // Default Form Action
144 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
145
146 // Row template
147 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
148
149 if ($this->parent_cmd == 'sortThreads') {
150 $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
151 } else {
152 // Multi commands
153 $this->addMultiCommand('', $this->lng->txt('please_choose'));
154 if ($this->settings->get('forum_notification') > 0 && !$this->user->isAnonymous()) {
155 $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
156 $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
157 }
158 if ($this->getIsModerator()) {
159 $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
160 $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
161 $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
162 $this->addMultiCommand('close', $this->lng->txt('close_topics'));
163 $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
164 $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
165 }
166 $this->addMultiCommand('html', $this->lng->txt('export_html'));
167 if ($this->getIsModerator()) {
168 $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
169 $this->addMultiCommand('merge', $this->lng->txt('merge_posts_into_thread'));
170 }
171 }
172 $this->setShowRowsSelector(true);
173 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
174 }
175
176 public function initMergeThreadsTable()
177 {
178 // Columns
179 $this->addColumn('', 'check', '1px', true);
180 $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
181 $this->addColumn($this->lng->txt('forums_created_by'), 'author');
182 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
183 $this->addColumn($this->lng->txt('visits'), 'num_visit');
184 if ($this->is_post_draft_allowed) {
185 $this->addColumn($this->lng->txt('drafts', ''));
186 }
187 $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
188
189 // Disable sorting
190 $this->disable('sort');
191
192 // Default Form Action
193 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
194
195 // Row template
196 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
197
198 ilUtil::sendInfo($this->lng->txt('please_choose_target'));
199
200 $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
201
202 $this->addCommandButton('confirmMergeThreads', $this->lng->txt('merge'));
203 $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
204 $this->setShowRowsSelector(true);
205 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
206 }
207
211 public function fillRow($thread)
212 {
213 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
214 if ('mergeThreads' == $this->parent_cmd) {
215 $checked = $this->max_count == 1 || (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']));
216 $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton(
217 $checked,
218 'thread_ids[]',
219 $thread->getId()
220 ));
221 } elseif ('showThreads' == $this->parent_cmd) {
222 $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
223 (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false),
224 'thread_ids[]',
225 $thread->getId()
226 ));
227
228 if ($this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
229 $rating = new ilRatingGUI();
230 $rating->setObject($this->parent_obj->object->getId(), $this->parent_obj->object->getType(), $thread->getId(), 'thread');
231 $rating->setUserId($this->user->getId());
232 $this->tpl->setVariable('VAL_RATING', $rating->getHTML());
233 }
234 } else {
235 if ($thread->isSticky()) {
236 $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']');
237 $this->tpl->setVariable('VAL_SORTING', (int) $this->position * 10);
238 } else {
239 $this->tpl->setVariable('VAL_CHECK', '');
240 }
241 $this->position++;
242 }
243 $subject = '';
244
245 if ($thread->isSticky()) {
246 $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
247 }
248 if ($thread->isClosed()) {
249 $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
250 }
251
252 if (!$this->user->isAnonymous() &&
253 $this->settings->get('forum_notification') != 0 &&
254 $thread->getUserNotificationEnabled()
255 ) {
256 $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
257 }
258
259 $num_posts = $thread->getNumPosts();
260 $num_unread = $thread->getNumUnreadPosts();
261 $num_new = $thread->getNumNewPosts();
262
263 $this->ctrl->setParameter($this->getParentObject(), 'page', 0);
264 $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
265 $this->ctrl->setParameter($this->getParentObject(), 'page', null);
266 $this->tpl->setVariable('VAL_SUBJECT', $subject);
267
268 // Author
269 $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
270 $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
271
272 $authorinfo = new ilForumAuthorInformation(
273 $thread->getThrAuthorId(),
274 $thread->getDisplayUserId(),
275 $thread->getUserAlias(),
276 $thread->getImportName(),
277 array(
278 'class' => 'il_ItemProperty',
279 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
280 )
281 );
282 $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
283
284 $topicStats = $num_posts;
285 if (!$this->user->isAnonymous()) {
286 if ($num_unread > 0) {
287 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
288 }
289 if ($num_new > 0 && $this->getOverviewSetting() == 0) {
290 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
291 }
292 }
293
294 $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
295 $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
296 if ($this->is_post_draft_allowed) {
297 $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
298 $this->tpl->setVariable('VAL_DRAFTS', (int) $draft_statistics[$thread->getId()]);
299 }
300 // Last posting
301 if ($num_posts > 0) {
302 if ($thread->getLastPostForThreadOverview() instanceof ilForumPost) {
303 $objLastPost = $thread->getLastPostForThreadOverview();
304 $authorinfo = new ilForumAuthorInformation(
305 $objLastPost->getPosAuthorId(),
306 $objLastPost->getDisplayUserId(),
307 $objLastPost->getUserAlias(),
308 $objLastPost->getImportName(),
309 array(
310 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
311 )
312 );
313
314 $this->tpl->setVariable(
315 'VAL_LP_DATE',
316 '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
317 '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
318 );
319 }
320 }
321
322 // Row style
323 $css_row = $this->css_row;
324 if ($thread->isSticky()) {
325 $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
326 }
327 $this->tpl->setVariable('CSS_ROW', $css_row);
328
329 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
330 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
331 $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
332 }
333
340 protected function formatCellValue($cell, $value)
341 {
342 return $value;
343 }
344
350 public function numericOrdering($column)
351 {
352 return false;
353 }
354
358 public function fetchData()
359 {
361
362 $excluded_ids = array();
363 if ($this->parent_cmd == 'mergeThreads' &&
364 $this->getSelectedThread() instanceof ilForumTopic) {
365 $excluded_ids[] = $this->getSelectedThread()->getId();
366 }
367
368 $params = array(
369 'is_moderator' => $this->getIsModerator(),
370 'excluded_ids' => $excluded_ids,
371 'order_column' => $this->getOrderField(),
372 'order_direction' => $this->getOrderDirection()
373 );
374
375 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
376 if (!count($data['items']) && $this->getOffset() > 0) {
377 $this->resetOffset();
378 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
379 }
380
381 $this->setMaxCount($data['cnt']);
382 $this->setData($data['items']);
383
384 // Collect user ids for preloading user objects
385 $thread_ids = array();
386 $user_ids = array();
387 foreach ($data['items'] as $thread) {
391 $thread_ids[] = (int) $thread->getId();
392 if ($thread->getDisplayUserId() > 0) {
393 $user_ids[$thread->getDisplayUserId()] = (int) $thread->getDisplayUserId();
394 }
395 }
396
397 $user_ids = array_merge(
399 $user_ids
400 );
401
403
404 return $this;
405 }
406
411 public function setMapper(ilForum $mapper)
412 {
413 $this->mapper = $mapper;
414 return $this;
415 }
416
420 public function getMapper()
421 {
422 return $this->mapper;
423 }
424
429 public function setRefId($ref_id)
430 {
431 $this->ref_id = $ref_id;
432 return $this;
433 }
434
438 public function getRefId()
439 {
440 return $this->ref_id;
441 }
442
448 {
449 $this->overview_setting = $overview_setting;
450 return $this;
451 }
452
456 public function getOverviewSetting()
457 {
459 }
460
466 {
467 $this->is_moderator = $is_moderator;
468 return $this;
469 }
470
474 public function getIsModerator()
475 {
476 return $this->is_moderator;
477 }
478
483 public function setTopicData($topicData)
484 {
485 $this->topicData = $topicData;
486 return $this;
487 }
488
492 public function getTopicData()
493 {
494 return $this->topicData;
495 }
496
500 public function setSelectedThread(ilForumTopic $thread_obj)
501 {
502 $this->merge_thread_obj = $thread_obj;
503 }
504
508 public function getSelectedThread()
509 {
511 }
512}
user()
Definition: user.php:4
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static getDraftsStatisticsByRefId($ref_id)
Class ilForumTopicTableGUI.
setSelectedThread(ilForumTopic $thread_obj)
setOverviewSetting($overview_setting)
__construct($a_parent_obj, $a_parent_cmd='', $template_context='', $ref_id=0, $topicData=array(), $is_moderator=false, $overview_setting='')
numericOrdering($column)
Currently not used because of external segmentation and sorting.
Class Forum core functions for forum.
static getUserIdsOfLastPostsByRefIdAndThreadIds($ref_id, array $thread_ids)
Class ilRatingGUI.
Class ilTable2GUI.
setExternalSorting($a_val)
Set external sorting.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setRowSelectorLabel($row_selector_label)
setData($a_data)
set table data @access public
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
resetOffset($a_in_determination=false)
Reset offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
disable($a_module_name)
diesables particular modules of table
static formRadioButton($checked, $varname, $value, $onclick=null, $disabled=false)
??? @access public
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46