ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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);
88  $this->setTopicData($topicData);
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 {
113  $this->initTopicsOverviewTable();
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  $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
264  $this->tpl->setVariable('VAL_SUBJECT', $subject);
265 
266  // Author
267  $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
268  $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
269 
270  $authorinfo = new ilForumAuthorInformation(
271  $thread->getThrAuthorId(),
272  $thread->getDisplayUserId(),
273  $thread->getUserAlias(),
274  $thread->getImportName(),
275  array(
276  'class' => 'il_ItemProperty',
277  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
278  )
279  );
280  $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
281 
282  $topicStats = $num_posts;
283  if (!$this->user->isAnonymous()) {
284  if ($num_unread > 0) {
285  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
286  }
287  if ($num_new > 0 && $this->getOverviewSetting() == 0) {
288  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
289  }
290  }
291 
292  $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
293  $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
294  if ($this->is_post_draft_allowed) {
295  $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
296  $this->tpl->setVariable('VAL_DRAFTS', (int) $draft_statistics[$thread->getId()]);
297  }
298  // Last posting
299  if ($num_posts > 0) {
300  if ($thread->getLastPostForThreadOverview() instanceof ilForumPost) {
301  $objLastPost = $thread->getLastPostForThreadOverview();
302  $authorinfo = new ilForumAuthorInformation(
303  $objLastPost->getPosAuthorId(),
304  $objLastPost->getDisplayUserId(),
305  $objLastPost->getUserAlias(),
306  $objLastPost->getImportName(),
307  array(
308  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
309  )
310  );
311 
312  $this->tpl->setVariable(
313  'VAL_LP_DATE',
314  '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
315  '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
316  );
317  }
318  }
319 
320  // Row style
321  $css_row = $this->css_row;
322  if ($thread->isSticky()) {
323  $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
324  }
325  $this->tpl->setVariable('CSS_ROW', $css_row);
326 
327  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
328  $this->ctrl->setParameter($this->getParentObject(), 'user', '');
329  $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
330  }
331 
338  protected function formatCellValue($cell, $value)
339  {
340  return $value;
341  }
342 
348  public function numericOrdering($column)
349  {
350  return false;
351  }
352 
356  public function fetchData()
357  {
358  $this->determineOffsetAndOrder();
359 
360  $excluded_ids = array();
361  if ($this->parent_cmd == 'mergeThreads' &&
362  $this->getSelectedThread() instanceof ilForumTopic) {
363  $excluded_ids[] = $this->getSelectedThread()->getId();
364  }
365 
366  $params = array(
367  'is_moderator' => $this->getIsModerator(),
368  'excluded_ids' => $excluded_ids,
369  'order_column' => $this->getOrderField(),
370  'order_direction' => $this->getOrderDirection()
371  );
372 
373  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
374  if (!count($data['items']) && $this->getOffset() > 0) {
375  $this->resetOffset();
376  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
377  }
378 
379  $this->setMaxCount($data['cnt']);
380  $this->setData($data['items']);
381 
382  // Collect user ids for preloading user objects
383  $thread_ids = array();
384  $user_ids = array();
385  foreach ($data['items'] as $thread) {
389  $thread_ids[] = (int) $thread->getId();
390  if ($thread->getDisplayUserId() > 0) {
391  $user_ids[$thread->getDisplayUserId()] = (int) $thread->getDisplayUserId();
392  }
393  }
394 
395  $user_ids = array_merge(
397  $user_ids
398  );
399 
400  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
401 
402  return $this;
403  }
404 
409  public function setMapper(ilForum $mapper)
410  {
411  $this->mapper = $mapper;
412  return $this;
413  }
414 
418  public function getMapper()
419  {
420  return $this->mapper;
421  }
422 
427  public function setRefId($ref_id)
428  {
429  $this->ref_id = $ref_id;
430  return $this;
431  }
432 
436  public function getRefId()
437  {
438  return $this->ref_id;
439  }
440 
446  {
447  $this->overview_setting = $overview_setting;
448  return $this;
449  }
450 
454  public function getOverviewSetting()
455  {
457  }
458 
463  public function setIsModerator($is_moderator)
464  {
465  $this->is_moderator = $is_moderator;
466  return $this;
467  }
468 
472  public function getIsModerator()
473  {
474  return $this->is_moderator;
475  }
476 
481  public function setTopicData($topicData)
482  {
483  $this->topicData = $topicData;
484  return $this;
485  }
486 
490  public function getTopicData()
491  {
492  return $this->topicData;
493  }
494 
498  public function setSelectedThread(ilForumTopic $thread_obj)
499  {
500  $this->merge_thread_obj = $thread_obj;
501  }
502 
506  public function getSelectedThread()
507  {
509  }
510 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setRowSelectorLabel($row_selector_label)
setExternalSorting($a_val)
Set external sorting.
Class Forum core functions for forum.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
settings()
Definition: settings.php:2
const IL_CAL_DATETIME
global $DIC
Definition: saml.php:7
setExternalSegmentation($a_val)
Set external segmentation.
__construct($a_parent_obj, $a_parent_cmd='', $template_context='', $ref_id=0, $topicData=array(), $is_moderator=false, $overview_setting='')
resetOffset($a_in_determination=false)
Reset offset.
if(!array_key_exists('StateId', $_REQUEST)) $id
getOrderDirection()
Get order direction.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
getParentObject()
Get parent object.
setId($a_val)
Set id.
user()
Definition: user.php:4
setSelectedThread(ilForumTopic $thread_obj)
Class ilForumTopicTableGUI.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilTable2GUI.
Class ilRatingGUI.
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.
getOffset()
Get offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
numericOrdering($column)
Currently not used because of external segmentation and sorting.
Date and time handling
setOverviewSetting($overview_setting)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static formRadioButton($checked, $varname, $value, $onclick=null, $disabled=false)
??? public
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
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.
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
static getUserIdsOfLastPostsByRefIdAndThreadIds($ref_id, array $thread_ids)
$_POST["username"]
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public
static getDraftsStatisticsByRefId($ref_id)