ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4require_once 'Services/Table/classes/class.ilTable2GUI.php';
5require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
6require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
7require_once 'Services/Rating/classes/class.ilRatingGUI.php';
8
17{
21 protected $mapper;
22
26 protected $is_moderator = false;
27
31 protected $ref_id = 0;
32
36 protected $overview_setting = '';
37
41 protected $topicData = array();
42
46 protected $ctrl;
47
51 protected $merge_thread_obj = NULL;
52
56 public $position = 1;
57
61 public $is_post_draft_allowed = FALSE;
62
71 public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
72 {
78 global $ilCtrl, $lng, $tpl;
79
80 $this->lng = $lng;
81 $this->ctrl = $ilCtrl;
82 $this->parent_cmd = $a_parent_cmd;
85 $this->setRefId($ref_id);
87
88 // Call this immediately in constructor
89 $id = 'frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_'. $this->getRefId();
90 $this->setId($id);
91
92 // Let the database do the work
93 $this->setDefaultOrderDirection('DESC');
94 $this->setDefaultOrderField('lp_date');
95 $this->setExternalSorting(true);
96 $this->setExternalSegmentation(true);
97
98 parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
99
100 // Add global css for table styles
101 $tpl->addCss('./Modules/Forum/css/forum_table.css');
102
103 $this->is_post_draft_allowed = ilForumPostDraft::isSavePostDraftAllowed();
104 }
105
106 public function init()
107 {
108 if($this->parent_cmd == 'mergeThreads')
109 {
110 $this->initMergeThreadsTable();
111 }
112 else
113 {
114 $this->initTopicsOverviewTable();
115 }
116 }
117
121 public function initTopicsOverviewTable()
122 {
126 global $ilUser;
127
128 if($this->parent_cmd == "showThreads")
129 {
130 $this->setSelectAllCheckbox('thread_ids');
131 $this->addColumn('', 'check', '1px', true);
132 }
133 else
134 {
135 $this->addColumn('', 'check', '10px', true);
136 }
137
138 $this->addColumn($this->lng->txt('forums_thread'), 'thr_subject');
139 $this->addColumn($this->lng->txt('forums_created_by'), '');
140 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
141 $this->addColumn($this->lng->txt('visits'), 'num_visit');
142
143 if($this->is_post_draft_allowed)
144 {
145 $this->addColumn($this->lng->txt('drafts',''));
146 }
147
148 $this->addColumn($this->lng->txt('forums_last_post'), 'post_date');
149 if('showThreads' == $this->parent_cmd && $this->parent_obj->objProperties->isIsThreadRatingEnabled())
150 {
151 $this->addColumn($this->lng->txt('frm_rating'), 'rating');
152 }
153
154 // Default Form Action
155 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
156
157 // Row template
158 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
159
160 if($this->parent_cmd == 'sortThreads')
161 {
162 $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
163 }
164 else
165 {
166 // Multi commands
167 $this->addMultiCommand('', $this->lng->txt('please_choose'));
168 if($this->ilias->getSetting('forum_notification') > 0 && !$ilUser->isAnonymous())
169 {
170 $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
171 $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
172 }
173 if($this->getIsModerator())
174 {
175 $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
176 $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
177 $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
178 $this->addMultiCommand('close', $this->lng->txt('close_topics'));
179 $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
180 $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
181 }
182 $this->addMultiCommand('html', $this->lng->txt('export_html'));
183 if($this->getIsModerator())
184 {
185 $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
186 $this->addMultiCommand('merge', $this->lng->txt('merge_posts_into_thread'));
187 }
188 }
189 $this->setShowRowsSelector(true);
190 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
191 }
192
193 public function initMergeThreadsTable()
194 {
195 // Columns
196 $this->addColumn('', 'check', '1px', true);
197 $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
198 $this->addColumn($this->lng->txt('forums_created_by'), 'author');
199 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
200 $this->addColumn($this->lng->txt('visits'), 'num_visit');
201 if($this->is_post_draft_allowed)
202 {
203 $this->addColumn($this->lng->txt('drafts',''));
204 }
205 $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
206
207 // Disable sorting
208 $this->disable('sort');
209
210 // Default Form Action
211 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
212
213 // Row template
214 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
215
216 ilUtil::sendInfo($this->lng->txt('please_choose_target'));
217
218 $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
219
220 $this->addCommandButton('confirmMergeThreads',$this->lng->txt('merge'));
221 $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
222 $this->setShowRowsSelector(true);
223 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
224 }
225
229 public function fillRow($thread)
230 {
234 global $ilUser;
235
236 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
237 if('mergeThreads' == $this->parent_cmd)
238 {
239 $checked = $this->max_count == 1 || (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']));
240 $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton(
241 $checked, 'thread_ids[]', $thread->getId()
242 ));
243 }
244 else if('showThreads' == $this->parent_cmd)
245 {
246 $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
247 (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false), 'thread_ids[]', $thread->getId()
248 ));
249
250 if($this->parent_obj->objProperties->isIsThreadRatingEnabled())
251 {
252 $rating = new ilRatingGUI();
253 $rating->setObject($this->parent_obj->object->getId(), $this->parent_obj->object->getType(), $thread->getId(), 'thread');
254 $rating->setUserId($ilUser->getId());
255 $this->tpl->setVariable('VAL_RATING', $rating->getHTML());
256 }
257 }
258 else
259 {
260 if($thread->isSticky())
261 {
262 $this->tpl->setVariable('VAL_SORTING_NAME','thread_sorting['.$thread->getId().']' );
263 $this->tpl->setVariable('VAL_SORTING', (int)$this->position * 10 );
264 }
265 else
266 {
267 $this->tpl->setVariable('VAL_CHECK', '');
268 }
269 $this->position++;
270 }
271 $subject = '';
272
273 if($thread->isSticky())
274 {
275 $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
276 }
277 if($thread->isClosed())
278 {
279 $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
280 }
281
282 if(!$ilUser->isAnonymous() &&
283 $this->ilias->getSetting('forum_notification') != 0 &&
284 $thread->getUserNotificationEnabled()
285 )
286 {
287 $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
288 }
289
290 $num_posts = $thread->getNumPosts();
291 $num_unread = $thread->getNumUnreadPosts();
292 $num_new = $thread->getNumNewPosts();
293
294 if($num_posts > 0)
295 {
296 $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
297 }
298 else
299 {
300 $subject = $thread->getSubject() . $subject;
301 }
302 $this->tpl->setVariable('VAL_SUBJECT', $subject);
303
304 // Author
305 $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
306 $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
307
308 $authorinfo = new ilForumAuthorInformation(
309 $thread->getThrAuthorId(),
310 $thread->getDisplayUserId(),
311 $thread->getUserAlias(),
312 $thread->getImportName(),
313 array(
314 'class' => 'il_ItemProperty',
315 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
316 )
317 );
318 $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
319
320 $topicStats = $num_posts;
321 if(!$ilUser->isAnonymous())
322 {
323 if($num_unread > 0)
324 {
325 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
326 }
327 if($num_new > 0 && $this->getOverviewSetting() == 0)
328 {
329 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
330 }
331 }
332
333 $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
334 $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
335 if($this->is_post_draft_allowed)
336 {
337 $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
338 $this->tpl->setVariable('VAL_DRAFTS', (int)$draft_statistics[$thread->getId()]);
339 }
340 // Last posting
341 if($num_posts > 0)
342 {
343 if($this->getIsModerator())
344 {
345 $objLastPost = $thread->getLastPost();
346 }
347 else
348 {
349 $objLastPost = $thread->getLastActivePost();
350 }
351
352 if(is_object($objLastPost))
353 {
354 $authorinfo = new ilForumAuthorInformation(
355 $objLastPost->getPosAuthorId(),
356 $objLastPost->getDisplayUserId(),
357 $objLastPost->getUserAlias(),
358 $objLastPost->getImportName(),
359 array(
360 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
361 )
362 );
363
364 $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
365 '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
366 );
367 }
368 }
369
370 // Row style
371 $css_row = $this->css_row;
372 if($thread->isSticky())
373 {
374 $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
375 }
376 $this->tpl->setVariable('CSS_ROW', $css_row);
377
378 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
379 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
380 $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
381 }
382
389 protected function formatCellValue($cell, $value)
390 {
391 return $value;
392 }
393
399 public function numericOrdering($column)
400 {
401 return false;
402 }
403
407 public function fetchData()
408 {
410
411 $excluded_ids = array();
412 if($this->parent_cmd == 'mergeThreads' &&
413 $this->getSelectedThread() instanceof ilForumTopic)
414 {
415 $excluded_ids[] = $this->getSelectedThread()->getId();
416 }
417
418 $params = array(
419 'is_moderator' => $this->getIsModerator(),
420 'excluded_ids' => $excluded_ids,
421 'order_column' => $this->getOrderField(),
422 'order_direction' => $this->getOrderDirection()
423 );
424
425 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
426 if(!count($data['items']) && $this->getOffset() > 0)
427 {
428 $this->resetOffset();
429 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
430 }
431
432 $this->setMaxCount($data['cnt']);
433 $this->setData($data['items']);
434
435 // Collect user ids for preloading user objects
436 $thread_ids = array();
437 $user_ids = array();
438 foreach($data['items'] as $thread)
439 {
443 $thread_ids[] = (int)$thread->getId();
444 if($thread->getDisplayUserId() > 0)
445 {
446 $user_ids[$thread->getDisplayUserId()] = (int)$thread->getDisplayUserId();
447 }
448 }
449
450 $user_ids = array_merge(
451 ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids),
452 $user_ids
453 );
454
455 ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
456
457 return $this;
458 }
459
464 public function setMapper(ilForum $mapper)
465 {
466 $this->mapper = $mapper;
467 return $this;
468 }
469
473 public function getMapper()
474 {
475 return $this->mapper;
476 }
477
482 public function setRefId($ref_id)
483 {
484 $this->ref_id = $ref_id;
485 return $this;
486 }
487
491 public function getRefId()
492 {
493 return $this->ref_id;
494 }
495
501 {
502 $this->overview_setting = $overview_setting;
503 return $this;
504 }
505
509 public function getOverviewSetting()
510 {
512 }
513
519 {
520 $this->is_moderator = $is_moderator;
521 return $this;
522 }
523
527 public function getIsModerator()
528 {
529 return $this->is_moderator;
530 }
531
536 public function setTopicData($topicData)
537 {
538 $this->topicData = $topicData;
539 return $this;
540 }
541
545 public function getTopicData()
546 {
547 return $this->topicData;
548 }
549
553 public function setSelectedThread(ilForumTopic $thread_obj)
554 {
555 $this->merge_thread_obj = $thread_obj;
556 }
557
561 public function getSelectedThread()
562 {
564 }
565}
sprintf('%.4f', $callTime)
$column
Definition: 39dropdown.php:62
global $tpl
Definition: ilias.php:8
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static getDraftsStatisticsByRefId($ref_id)
Class ilForumTopicTableGUI.
setSelectedThread(ilForumTopic $thread_obj)
setOverviewSetting($overview_setting)
numericOrdering($column)
Currently not used because of external segmentation and sorting.
Class Forum core functions for forum.
Class ilRatingGUI.
Class ilTable2GUI.
setExternalSorting($a_val)
Set external sorting.
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.
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.
fillRow($a_set)
Standard Version of Fill Row.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setRowSelectorLabel($row_selector_label)
setData($a_data)
set table data @access public
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
Constructor.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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.
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:17
$ilUser
Definition: imgupload.php:18