ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/Calendar/classes/class.ilDatePresentation.php';
6 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
7 require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
8 require_once 'Services/Rating/classes/class.ilRatingGUI.php';
9 
18 {
22  protected $mapper;
23 
27  protected $is_moderator = false;
28 
32  protected $ref_id = 0;
33 
37  protected $overview_setting = '';
38 
42  protected $topicData = array();
43 
47  protected $ctrl;
48 
52  protected $merge_thread_obj = NULL;
53 
57  public $position = 1;
58 
67  public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
68  {
74  global $ilCtrl, $lng, $tpl;
75 
76  $this->lng = $lng;
77  $this->ctrl = $ilCtrl;
78  $this->parent_cmd = $a_parent_cmd;
81  $this->setRefId($ref_id);
82  $this->setTopicData($topicData);
83 
84  // Call this immediately in constructor
85  $this->setId('frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_'. $this->getRefId());
86 
87  // Let the database do the work
88  $this->setDefaultOrderDirection('DESC');
89  $this->setDefaultOrderField('lp_date');
90  $this->setExternalSorting(true);
91  $this->setExternalSegmentation(true);
92 
93  parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
94 
95  // Add global css for table styles
96  $tpl->addCss('./Modules/Forum/css/forum_table.css');
97  }
98 
99  public function populate()
100  {
101  if($this->parent_cmd == 'mergeThreads')
102  {
103  $this->initMergeThreadsTable();
104  }
105  else
106  {
107  $this->initTopicsOverviewTable();
108  }
109  }
110 
114  public function initTopicsOverviewTable()
115  {
119  global $ilUser;
120 
121  if($this->parent_cmd == "showThreads")
122  {
123  $this->setSelectAllCheckbox('thread_ids');
124  $this->addColumn('', 'check', '1px', true);
125  }
126  else
127  {
128  $this->addColumn('', 'check', '10px', true);
129  }
130 
131  $this->addColumn($this->lng->txt('forums_thread'), '');
132  $this->addColumn($this->lng->txt('forums_created_by'), '');
133  $this->addColumn($this->lng->txt('forums_articles'), '');
134  $this->addColumn($this->lng->txt('visits'), '');
135  $this->addColumn($this->lng->txt('forums_last_post'), 'post_date');
136  if('showThreads' == $this->parent_cmd && $this->parent_obj->objProperties->isIsThreadRatingEnabled())
137  {
138  $this->addColumn($this->lng->txt('frm_rating'), 'rating');
139  }
140 
141  // Default Form Action
142  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
143 
144  // Row template
145  $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
146 
147  if($this->parent_cmd == 'sortThreads')
148  {
149  $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
150  }
151  else
152  {
153  // Multi commands
154  $this->addMultiCommand('', $this->lng->txt('please_choose'));
155  if($this->ilias->getSetting('forum_notification') > 0 && !$ilUser->isAnonymous())
156  {
157  $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
158  $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
159  }
160  if($this->getIsModerator())
161  {
162  $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
163  $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
164  $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
165  $this->addMultiCommand('close', $this->lng->txt('close_topics'));
166  $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
167  $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
168  }
169  $this->addMultiCommand('html', $this->lng->txt('export_html'));
170  if($this->getIsModerator())
171  {
172  $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
173  $this->addMultiCommand('merge', $this->lng->txt('merge_posts_into_thread'));
174  }
175  }
176  $this->setShowRowsSelector(true);
177  $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
178  }
179 
180  public function initMergeThreadsTable()
181  {
182  // Columns
183  $this->addColumn('', 'check', '1px', true);
184  $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
185  $this->addColumn($this->lng->txt('forums_created_by'), 'author');
186  $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
187  $this->addColumn($this->lng->txt('visits'), 'num_visit');
188  $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
189 
190  // Disable sorting
191  $this->disable('sort');
192 
193  // Default Form Action
194  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
195 
196  // Row template
197  $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
198 
199  ilUtil::sendInfo($this->lng->txt('please_choose_target'));
200 
201  $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
202 
203  $this->addCommandButton('confirmMergeThreads',$this->lng->txt('merge'));
204  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
205  $this->setShowRowsSelector(true);
206  $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
207  }
208 
212  public function fillRow(ilForumTopic $thread)
213  {
217  global $ilUser;
218 
219  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
220  if('mergeThreads' == $this->parent_cmd)
221  {
222  $checked = $this->max_count == 1 || (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']));
223  $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton(
224  $checked, 'thread_ids[]', $thread->getId()
225  ));
226  }
227  else if('showThreads' == $this->parent_cmd)
228  {
229  $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
230  (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false), 'thread_ids[]', $thread->getId()
231  ));
232 
233  if($this->parent_obj->objProperties->isIsThreadRatingEnabled())
234  {
235  $rating = new ilRatingGUI();
236  $rating->setObject($this->parent_obj->object->getId(), $this->parent_obj->object->getType(), $thread->getId(), 'thread');
237  $rating->setUserId($ilUser->getId());
238  $this->tpl->setVariable('VAL_RATING', $rating->getHTML());
239  }
240  }
241  else
242  {
243  if($thread->isSticky())
244  {
245  $this->tpl->setVariable('VAL_SORTING_NAME','thread_sorting['.$thread->getId().']' );
246  $this->tpl->setVariable('VAL_SORTING', (int)$this->position * 10 );
247  }
248  else
249  {
250  $this->tpl->setVariable('VAL_CHECK', '');
251  }
252  $this->position++;
253  }
254  $subject = '';
255 
256  if($thread->isSticky())
257  {
258  $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
259  }
260  if($thread->isClosed())
261  {
262  $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
263  }
264 
265  if(!$ilUser->isAnonymous() &&
266  $this->ilias->getSetting('forum_notification') != 0 &&
267  $thread->getUserNotificationEnabled()
268  )
269  {
270  $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
271  }
272 
273  $num_posts = $thread->getNumPosts();
274  $num_unread = $thread->getNumUnreadPosts();
275  $num_new = $thread->getNumNewPosts();
276 
277  if($num_posts > 0)
278  {
279  $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
280  }
281  else
282  {
283  $subject = $thread->getSubject() . $subject;
284  }
285  $this->tpl->setVariable('VAL_SUBJECT', $subject);
286 
287  // Author
288  $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
289  $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
290 
291  $authorinfo = new ilForumAuthorInformation(
292  $thread->getThrAuthorId(),
293  $thread->getDisplayUserId(),
294  $thread->getUserAlias(),
295  $thread->getImportName(),
296  array(
297  'class' => 'il_ItemProperty',
298  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
299  )
300  );
301  $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
302 
303  $topicStats = $num_posts;
304  if(!$ilUser->isAnonymous())
305  {
306  if($num_unread > 0)
307  {
308  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
309  }
310  if($num_new > 0 && $this->getOverviewSetting() == 0)
311  {
312  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
313  }
314  }
315 
316  $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
317  $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
318 
319  // Last posting
320  if($num_posts > 0)
321  {
322  if($this->getIsModerator())
323  {
324  $objLastPost = $thread->getLastPost();
325  }
326  else
327  {
328  $objLastPost = $thread->getLastActivePost();
329  }
330 
331  if(is_object($objLastPost))
332  {
333  $authorinfo = new ilForumAuthorInformation(
334  $objLastPost->getPosAuthorId(),
335  $objLastPost->getDisplayUserId(),
336  $objLastPost->getUserAlias(),
337  $objLastPost->getImportName(),
338  array(
339  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
340  )
341  );
342 
343  $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
344  '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
345  );
346  }
347  }
348 
349  // Row style
350  $css_row = $this->css_row;
351  if($thread->isSticky())
352  {
353  $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
354  }
355  $this->tpl->setVariable('CSS_ROW', $css_row);
356 
357  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
358  $this->ctrl->setParameter($this->getParentObject(), 'user', '');
359  $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
360  }
361 
368  protected function formatCellValue($cell, $value)
369  {
370  return $value;
371  }
372 
378  public function numericOrdering($column)
379  {
380  return false;
381  }
382 
386  public function fetchData()
387  {
388  $this->determineOffsetAndOrder();
389 
390  $excluded_ids = array();
391  if($this->parent_cmd == 'mergeThreads' &&
392  $this->getSelectedThread() instanceof ilForumTopic)
393  {
394  $excluded_ids[] = $this->getSelectedThread()->getId();
395  }
396 
397  $params = array(
398  'is_moderator' => $this->getIsModerator(),
399  'excluded_ids' => $excluded_ids,
400  'order_column' => $this->getOrderField(),
401  'order_direction' => $this->getOrderDirection()
402  );
403 
404  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
405  if(!count($data['items']) && $this->getOffset() > 0)
406  {
407  $this->resetOffset();
408  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
409  }
410 
411  $this->setMaxCount($data['cnt']);
412  $this->setData($data['items']);
413 
414  // Collect user ids for preloading user objects
415  $thread_ids = array();
416  $user_ids = array();
417  foreach($data['items'] as $thread)
418  {
422  $thread_ids[] = (int)$thread->getId();
423  if($thread->getDisplayUserId() > 0)
424  {
425  $user_ids[$thread->getDisplayUserId()] = (int)$thread->getDisplayUserId();
426  }
427  }
428 
429  $user_ids = array_merge(
430  ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids),
431  $user_ids
432  );
433 
434  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
435 
436  return $this;
437  }
438 
443  public function setMapper(ilForum $mapper)
444  {
445  $this->mapper = $mapper;
446  return $this;
447  }
448 
452  public function getMapper()
453  {
454  return $this->mapper;
455  }
456 
461  public function setRefId($ref_id)
462  {
463  $this->ref_id = $ref_id;
464  return $this;
465  }
466 
470  public function getRefId()
471  {
472  return $this->ref_id;
473  }
474 
480  {
481  $this->overview_setting = $overview_setting;
482  return $this;
483  }
484 
488  public function getOverviewSetting()
489  {
491  }
492 
497  public function setIsModerator($is_moderator)
498  {
499  $this->is_moderator = $is_moderator;
500  return $this;
501  }
502 
506  public function getIsModerator()
507  {
508  return $this->is_moderator;
509  }
510 
515  public function setTopicData($topicData)
516  {
517  $this->topicData = $topicData;
518  return $this;
519  }
520 
524  public function getTopicData()
525  {
526  return $this->topicData;
527  }
528 
532  public function setSelectedThread(ilForumTopic $thread_obj)
533  {
534  $this->merge_thread_obj = $thread_obj;
535  }
536 
540  public function getSelectedThread()
541  {
543  }
544 }
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.
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
Constructor.
Class Forum core functions for forum.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
$_POST['username']
Definition: cron.php:12
const IL_CAL_DATETIME
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
setExternalSegmentation($a_val)
Set external segmentation.
resetOffset($a_in_determination=false)
Reset offset.
getOrderDirection()
Get order direction.
getParentObject()
Get parent object.
setId($a_val)
Set id.
setSelectedThread(ilForumTopic $thread_obj)
Class ilForumTopicTableGUI.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
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.
getOffset()
Get offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
static formatDate(ilDateTime $date)
Format a date public.
numericOrdering($column)
Currently not used because of external segmentation and sorting.
Date and time handling
redirection script todo: (a better solution should control the processing via a xml file) ...
setOverviewSetting($overview_setting)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static formRadioButton($checked, $varname, $value, $onclick=null, $disabled=false)
??? public
getLastPost()
Fetches and returns an object of the last post in the current topic.
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
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
fillRow($a_set)
Standard Version of Fill Row.
getLimit()
Get limit.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setMaxCount($a_max_count)
set max.
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.
$params
Definition: example_049.php:96
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public