ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
66 protected $mainTemplate;
67
68 private $user;
69 private $settings;
70
79 public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
80 {
81 global $DIC;
82
83 $this->lng = $DIC->language();
84 $this->ctrl = $DIC->ctrl();
85 $this->mainTemplate = $DIC->ui()->mainTemplate();
86 $this->user = $DIC->user();
87 $this->settings = $DIC->settings();
88
89 $this->parent_cmd = $a_parent_cmd;
92 $this->setRefId($ref_id);
94
95 // Call this immediately in constructor
96 $id = 'frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_' . $this->getRefId();
97 $this->setId($id);
98
99 // Let the database do the work
100 $this->setDefaultOrderDirection('DESC');
101 $this->setDefaultOrderField('lp_date');
102 $this->setExternalSorting(true);
103 $this->setExternalSegmentation(true);
104
105 parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
106
107 // Add global css for table styles
108 $this->mainTemplate->addCss('./Modules/Forum/css/forum_table.css');
109
110 $this->is_post_draft_allowed = ilForumPostDraft::isSavePostDraftAllowed();
111 }
112
113 public function init()
114 {
115 if ($this->parent_cmd == 'mergeThreads') {
116 $this->initMergeThreadsTable();
117 } else {
119 }
120 }
121
125 public function initTopicsOverviewTable()
126 {
127 if ($this->parent_cmd == "showThreads") {
128 $this->setSelectAllCheckbox('thread_ids');
129 $this->addColumn('', 'check', '1px', true);
130 } else {
131 $this->addColumn('', 'check', '10px', true);
132 }
133
134 $this->addColumn($this->lng->txt('forums_thread'), 'thr_subject');
135 $this->addColumn($this->lng->txt('forums_created_by'), '');
136 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
137 $this->addColumn($this->lng->txt('visits'), 'num_visit');
138
139 if ($this->is_post_draft_allowed) {
140 $this->addColumn($this->lng->txt('drafts', ''));
141 }
142
143 $this->addColumn($this->lng->txt('forums_last_post'), 'post_date');
144 if ('showThreads' == $this->parent_cmd && $this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
145 $this->addColumn($this->lng->txt('frm_rating'), 'rating');
146 }
147
148 // Default Form Action
149 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
150
151 // Row template
152 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
153
154 if ($this->parent_cmd == 'sortThreads') {
155 $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
156 } else {
157 // Multi commands
158 $this->addMultiCommand('', $this->lng->txt('please_choose'));
159 if ($this->settings->get('forum_notification') > 0 && !$this->user->isAnonymous()) {
160 $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
161 $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
162 }
163 if ($this->getIsModerator()) {
164 $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
165 $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
166 $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
167 $this->addMultiCommand('close', $this->lng->txt('close_topics'));
168 $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
169 $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
170 }
171 $this->addMultiCommand('html', $this->lng->txt('export_html'));
172 if ($this->getIsModerator()) {
173 $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
174 $this->addMultiCommand('merge', $this->lng->txt('merge_posts_into_thread'));
175 }
176 }
177 $this->setShowRowsSelector(true);
178 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
179 }
180
181 public function initMergeThreadsTable()
182 {
183 // Columns
184 $this->addColumn('', 'check', '1px', true);
185 $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
186 $this->addColumn($this->lng->txt('forums_created_by'), 'author');
187 $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
188 $this->addColumn($this->lng->txt('visits'), 'num_visit');
189 if ($this->is_post_draft_allowed) {
190 $this->addColumn($this->lng->txt('drafts', ''));
191 }
192 $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
193
194 // Disable sorting
195 $this->disable('sort');
196
197 // Default Form Action
198 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
199
200 // Row template
201 $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
202
203 ilUtil::sendInfo($this->lng->txt('please_choose_target'));
204
205 $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
206
207 $this->addCommandButton('confirmMergeThreads', $this->lng->txt('merge'));
208 $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
209 $this->setShowRowsSelector(true);
210 $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
211 }
212
216 public function fillRow($thread)
217 {
218 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
219 if ('mergeThreads' == $this->parent_cmd) {
220 $checked = $this->max_count == 1 || (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']));
221 $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton(
222 $checked,
223 'thread_ids[]',
224 $thread->getId()
225 ));
226 } elseif ('showThreads' == $this->parent_cmd) {
227 $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
228 (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false),
229 'thread_ids[]',
230 $thread->getId()
231 ));
232
233 if ($this->parent_obj->objProperties->isIsThreadRatingEnabled()) {
234 $rating = new ilRatingGUI();
235 $rating->setObject($this->parent_obj->object->getId(), $this->parent_obj->object->getType(), $thread->getId(), 'thread');
236 $rating->setUserId($this->user->getId());
237 $this->tpl->setVariable('VAL_RATING', $rating->getHTML());
238 }
239 } else {
240 if ($thread->isSticky()) {
241 $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']');
242 $this->tpl->setVariable('VAL_SORTING', (int) $this->position * 10);
243 } else {
244 $this->tpl->setVariable('VAL_CHECK', '');
245 }
246 $this->position++;
247 }
248 $subject = '';
249
250 if ($thread->isSticky()) {
251 $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
252 }
253 if ($thread->isClosed()) {
254 $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
255 }
256
257 if (!$this->user->isAnonymous() &&
258 $this->settings->get('forum_notification') != 0 &&
259 $thread->getUserNotificationEnabled()
260 ) {
261 $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
262 }
263
264 $num_posts = $thread->getNumPosts();
265 $num_unread = $thread->getNumUnreadPosts();
266 $num_new = $thread->getNumNewPosts();
267
268 if ($num_posts > 0) {
269 $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
270 } else {
271 $subject = $thread->getSubject() . $subject;
272 }
273 $this->tpl->setVariable('VAL_SUBJECT', $subject);
274
275 // Author
276 $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
277 $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
278
279 $authorinfo = new ilForumAuthorInformation(
280 $thread->getThrAuthorId(),
281 $thread->getDisplayUserId(),
282 $thread->getUserAlias(),
283 $thread->getImportName(),
284 array(
285 'class' => 'il_ItemProperty',
286 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
287 )
288 );
289 $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
290
291 $topicStats = $num_posts;
292 if (!$this->user->isAnonymous()) {
293 if ($num_unread > 0) {
294 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
295 }
296 if ($num_new > 0 && $this->getOverviewSetting() == 0) {
297 $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
298 }
299 }
300
301 $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
302 $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
303 if ($this->is_post_draft_allowed) {
304 $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
305 $this->tpl->setVariable('VAL_DRAFTS', (int) $draft_statistics[$thread->getId()]);
306 }
307 // Last posting
308 if ($num_posts > 0) {
309 if ($thread->getLastPostForThreadOverview() instanceof ilForumPost) {
310 $objLastPost = $thread->getLastPostForThreadOverview();
311
312 $authorinfo = new ilForumAuthorInformation(
313 $objLastPost->getPosAuthorId(),
314 $objLastPost->getDisplayUserId(),
315 $objLastPost->getUserAlias(),
316 $objLastPost->getImportName(),
317 array(
318 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
319 )
320 );
321
322 $this->tpl->setVariable(
323 'VAL_LP_DATE',
324 '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
325 '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
326 );
327 }
328 }
329
330 // Row style
331 $css_row = $this->css_row;
332 if ($thread->isSticky()) {
333 $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
334 }
335 $this->tpl->setVariable('CSS_ROW', $css_row);
336
337 $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
338 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
339 $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
340 }
341
348 protected function formatCellValue($cell, $value)
349 {
350 return $value;
351 }
352
358 public function numericOrdering($column)
359 {
360 return false;
361 }
362
366 public function fetchData()
367 {
369
370 $excluded_ids = array();
371 if ($this->parent_cmd == 'mergeThreads' &&
372 $this->getSelectedThread() instanceof ilForumTopic) {
373 $excluded_ids[] = $this->getSelectedThread()->getId();
374 }
375
376 $params = array(
377 'is_moderator' => $this->getIsModerator(),
378 'excluded_ids' => $excluded_ids,
379 'order_column' => $this->getOrderField(),
380 'order_direction' => $this->getOrderDirection()
381 );
382
383 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
384 if (!count($data['items']) && $this->getOffset() > 0) {
385 $this->resetOffset();
386 $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
387 }
388
389 $this->setMaxCount($data['cnt']);
390 $this->setData($data['items']);
391
392 // Collect user ids for preloading user objects
393 $thread_ids = array();
394 $user_ids = array();
395 foreach ($data['items'] as $thread) {
399 $thread_ids[] = (int) $thread->getId();
400 if ($thread->getDisplayUserId() > 0) {
401 $user_ids[$thread->getDisplayUserId()] = (int) $thread->getDisplayUserId();
402 }
403 }
404
405 $user_ids = array_merge(
407 $user_ids
408 );
409
411
412 return $this;
413 }
414
419 public function setMapper(ilForum $mapper)
420 {
421 $this->mapper = $mapper;
422 return $this;
423 }
424
428 public function getMapper()
429 {
430 return $this->mapper;
431 }
432
437 public function setRefId($ref_id)
438 {
439 $this->ref_id = $ref_id;
440 return $this;
441 }
442
446 public function getRefId()
447 {
448 return $this->ref_id;
449 }
450
456 {
457 $this->overview_setting = $overview_setting;
458 return $this;
459 }
460
464 public function getOverviewSetting()
465 {
467 }
468
474 {
475 $this->is_moderator = $is_moderator;
476 return $this;
477 }
478
482 public function getIsModerator()
483 {
484 return $this->is_moderator;
485 }
486
491 public function setTopicData($topicData)
492 {
493 $this->topicData = $topicData;
494 return $this;
495 }
496
500 public function getTopicData()
501 {
502 return $this->topicData;
503 }
504
508 public function setSelectedThread(ilForumTopic $thread_obj)
509 {
510 $this->merge_thread_obj = $thread_obj;
511 }
512
516 public function getSelectedThread()
517 {
519 }
520}
sprintf('%.4f', $callTime)
$column
Definition: 39dropdown.php:62
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)
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.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$params
Definition: disable.php:11