ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
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 
66  public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
67  {
73  global $ilCtrl, $lng, $tpl;
74 
75  $this->lng = $lng;
76  $this->ctrl = $ilCtrl;
77  $this->parent_cmd = $a_parent_cmd;
80  $this->setRefId($ref_id);
81  $this->setTopicData($topicData);
82 
83  // Call this immediately in constructor
84  $this->setId('frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_'. $this->getRefId());
85 
86  // Let the database do the work
87  $this->setDefaultOrderDirection('DESC');
88  $this->setDefaultOrderField('is_sticky');
89  $this->setExternalSorting(true);
90  $this->setExternalSegmentation(true);
91 
92  parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
93 
94  // Add global css for table styles
95  $tpl->addCss('./Modules/Forum/css/forum_table.css');
96  }
97 
98  public function populate()
99  {
100  if($this->parent_cmd == 'mergeThreads')
101  {
102  $this->initMergeThreadsTable();
103  }
104  else
105  {
106  $this->initTopicsOverviewTable();
107  }
108  }
109 
113  public function initTopicsOverviewTable()
114  {
118  global $ilUser;
119 
120  if($this->parent_cmd == "showThreads")
121  {
122  $this->setSelectAllCheckbox('thread_ids');
123  $this->addColumn('', 'check', '1px', true);
124  }
125  else
126  {
127  $this->addColumn('', 'check', '10px', true);
128  }
129 
130  $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
131  $this->addColumn($this->lng->txt('forums_created_by'), 'author');
132  $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
133  $this->addColumn($this->lng->txt('visits'), 'num_visit');
134  $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
135 
136  // Disable sorting
137  $this->disable('sort');
138 
139  // Default Form Action
140  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
141 
142  // Row template
143  $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
144 
145  if($this->parent_cmd == 'sortThreads')
146  {
147  $this->addCommandButton('saveThreadSorting', $this->lng->txt('save'));
148  }
149  else
150  {
151  // Multi commands
152  $this->addMultiCommand('', $this->lng->txt('please_choose'));
153  if($this->ilias->getSetting('forum_notification') > 0 && !$ilUser->isAnonymous())
154  {
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  {
160  $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
161  $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
162  $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
163  $this->addMultiCommand('close', $this->lng->txt('close_topics'));
164  $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
165  $this->addMultiCommand('move', $this->lng->txt('move_thread_to_forum'));
166  }
167  $this->addMultiCommand('html', $this->lng->txt('export_html'));
168  if($this->getIsModerator())
169  {
170  $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
171  $this->addMultiCommand('merge', $this->lng->txt('merge_posts_into_thread'));
172  }
173  }
174  $this->setShowRowsSelector(true);
175  $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
176  }
177 
178  public function initMergeThreadsTable()
179  {
180  // Columns
181  $this->addColumn('', 'check', '1px', true);
182  $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
183  $this->addColumn($this->lng->txt('forums_created_by'), 'author');
184  $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
185  $this->addColumn($this->lng->txt('visits'), 'num_visit');
186  $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
187 
188  // Disable sorting
189  $this->disable('sort');
190 
191  // Default Form Action
192  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'confirmMergeThreads'));
193 
194  // Row template
195  $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
196 
197  ilUtil::sendInfo($this->lng->txt('please_choose_target'));
198 
199  $this->setTitle(sprintf($this->lng->txt('frm_selected_merge_src'), $this->getSelectedThread()->getSubject()));
200 
201  $this->addCommandButton('confirmMergeThreads',$this->lng->txt('merge'));
202  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
203  $this->setShowRowsSelector(true);
204  $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
205  }
206 
210  public function fillRow(ilForumTopic $thread)
211  {
215  global $ilUser;
216 
217  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
218  if('mergeThreads' == $this->parent_cmd)
219  {
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, 'thread_ids[]', $thread->getId()
223  ));
224  }
225  else if('showThreads' == $this->parent_cmd)
226  {
227  $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
228  (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false), 'thread_ids[]', $thread->getId()
229  ));
230  }
231  else
232  {
233  if($thread->isSticky())
234  {
235  $this->tpl->setVariable('VAL_SORTING_NAME','thread_sorting['.$thread->getId().']' );
236  $this->tpl->setVariable('VAL_SORTING', (int)$this->position * 10 );
237  }
238  else
239  {
240  $this->tpl->setVariable('VAL_CHECK', '');
241  }
242  $this->position++;
243  }
244  $subject = '';
245 
246  if($thread->isSticky())
247  {
248  $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
249  }
250  if($thread->isClosed())
251  {
252  $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
253  }
254 
255  if(!$ilUser->isAnonymous() &&
256  $this->ilias->getSetting('forum_notification') != 0 &&
257  $thread->getUserNotificationEnabled()
258  )
259  {
260  $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
261  }
262 
263  $num_posts = $thread->getNumPosts();
264  $num_unread = $thread->getNumUnreadPosts();
265  $num_new = $thread->getNumNewPosts();
266 
267  if($num_posts > 0)
268  {
269  $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
270  }
271  else
272  {
273  $subject = $thread->getSubject() . $subject;
274  }
275  $this->tpl->setVariable('VAL_SUBJECT', $subject);
276 
277  // Author
278  $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
279  $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getUserId());
280 
281  $authorinfo = new ilForumAuthorInformation(
282  $thread->getUserId(),
283  $thread->getUserAlias(),
284  $thread->getImportName(),
285  array(
286  'class' => 'il_ItemProperty',
287  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
288  )
289  );
290  $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
291 
292  $topicStats = $num_posts;
293  if(!$ilUser->isAnonymous())
294  {
295  if($num_unread > 0)
296  {
297  $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
298  }
299  if($num_new > 0 && $this->getOverviewSetting() == 0)
300  {
301  $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
302  }
303  }
304 
305  $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
306  $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
307 
308  // Last posting
309  if($num_posts > 0)
310  {
311  if($this->getIsModerator())
312  {
313  $objLastPost = $thread->getLastPost();
314  }
315  else
316  {
317  $objLastPost = $thread->getLastActivePost();
318  }
319 
320  if(is_object($objLastPost))
321  {
322  $authorinfo = new ilForumAuthorInformation(
323  $objLastPost->getUserId(),
324  $objLastPost->getUserAlias(),
325  $objLastPost->getImportName(),
326  array(
327  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
328  )
329  );
330 
331  $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
332  '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
333  );
334  }
335  }
336 
337  // Row style
338  $css_row = $this->css_row;
339  if($thread->isSticky())
340  {
341  $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
342  }
343  $this->tpl->setVariable('CSS_ROW', $css_row);
344 
345  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
346  $this->ctrl->setParameter($this->getParentObject(), 'user', '');
347  $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
348  }
349 
356  protected function formatCellValue($cell, $value)
357  {
358  return $value;
359  }
360 
366  public function numericOrdering($column)
367  {
368  return false;
369  }
370 
374  public function fetchData()
375  {
376  $this->determineOffsetAndOrder();
377 
378  $excluded_ids = array();
379  if($this->parent_cmd == 'mergeThreads' &&
380  $this->getSelectedThread() instanceof ilForumTopic)
381  {
382  $excluded_ids[] = $this->getSelectedThread()->getId();
383  }
384 
385  $params = array(
386  'is_moderator' => $this->getIsModerator(),
387  'excluded_ids' => $excluded_ids
388  );
389 
390  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
391  if(!count($data['items']) && $this->getOffset() > 0)
392  {
393  $this->resetOffset();
394  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int)$this->getLimit(), (int)$this->getOffset());
395  }
396 
397  $this->setMaxCount($data['cnt']);
398  $this->setData($data['items']);
399 
400  // Collect user ids for preloading user objects
401  $thread_ids = array();
402  $user_ids = array();
403  foreach($data['items'] as $thread)
404  {
408  $thread_ids[] = (int)$thread->getId();
409  if($thread->getUserId() > 0)
410  {
411  $user_ids[$thread->getUserId()] = (int)$thread->getUserId();
412  }
413  }
414 
415  $user_ids = array_merge(
416  ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids),
417  $user_ids
418  );
419 
420  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
421 
422  return $this;
423  }
424 
429  public function setMapper(ilForum $mapper)
430  {
431  $this->mapper = $mapper;
432  return $this;
433  }
434 
438  public function getMapper()
439  {
440  return $this->mapper;
441  }
442 
447  public function setRefId($ref_id)
448  {
449  $this->ref_id = $ref_id;
450  return $this;
451  }
452 
456  public function getRefId()
457  {
458  return $this->ref_id;
459  }
460 
466  {
467  $this->overview_setting = $overview_setting;
468  return $this;
469  }
470 
474  public function getOverviewSetting()
475  {
477  }
478 
483  public function setIsModerator($is_moderator)
484  {
485  $this->is_moderator = $is_moderator;
486  return $this;
487  }
488 
492  public function getIsModerator()
493  {
494  return $this->is_moderator;
495  }
496 
501  public function setTopicData($topicData)
502  {
503  $this->topicData = $topicData;
504  return $this;
505  }
506 
510  public function getTopicData()
511  {
512  return $this->topicData;
513  }
514 
518  public function setSelectedThread(ilForumTopic $thread_obj)
519  {
520  $this->merge_thread_obj = $thread_obj;
521  }
522 
526  public function getSelectedThread()
527  {
529  }
530 }
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.
getParentObject()
Get parent object.
setId($a_val)
Set id.
setSelectedThread(ilForumTopic $thread_obj)
Class ilForumTopicTableGUI.
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.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="")
Add a column to the header.
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) ...
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="")
Add Command button.
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.
disable($a_module_name)
diesables particular modules of table
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
setFormAction($a_form_action)
Set Form action parameter.
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.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public