ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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 
56  public function __construct($a_parent_obj, $a_parent_cmd = '', $template_context = '', $ref_id = 0, $topicData = array(), $is_moderator = false, $overview_setting = '')
57  {
64  global $ilCtrl, $lng, $tpl, $ilUser;
65 
66  $this->lng = $lng;
67  $this->ctrl = $ilCtrl;
68 
71  $this->setRefId($ref_id);
72  $this->setTopicData($topicData);
73 
74  // Call this immediately in constructor
75  $this->setId('il_frm_thread_table_' . $this->getRefId());
76  $this->setPrefix('frm_threads');
77 
78  // Let the database do the work
79  $this->setDefaultOrderDirection('DESC');
80  $this->setDefaultOrderField('is_sticky');
81  $this->setExternalSorting(true);
82  $this->setExternalSegmentation(true);
83 
84  parent::__construct($a_parent_obj, $a_parent_cmd, $template_context);
85 
86  // Add global css for table styles
87  $tpl->addCss('./Modules/Forum/css/forum_table.css');
88 
89  // Columns
90  $this->addColumn('', 'check', '1px', true);
91  $this->addColumn($this->lng->txt('forums_thread'), 'th_title');
92  $this->addColumn($this->lng->txt('forums_created_by'), 'author');
93  $this->addColumn($this->lng->txt('forums_articles'), 'num_posts');
94  $this->addColumn($this->lng->txt('visits'), 'num_visit');
95  $this->addColumn($this->lng->txt('forums_last_post'), 'lp_date');
96 
97  // Disable sorting
98  $this->disable('sort');
99  $this->setSelectAllCheckbox('thread_ids');
100 
101  // Default Form Action
102  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), 'showThreads'));
103 
104  // Row template
105  $this->setRowTemplate('tpl.forums_threads_table.html', 'Modules/Forum');
106 
107  // Multi commands
108  $this->addMultiCommand('', $this->lng->txt('please_choose'));
109  if($this->ilias->getSetting('forum_notification') == 1 && !$ilUser->isAnonymous())
110  {
111  $this->addMultiCommand('enable_notifications', $this->lng->txt('forums_enable_notification'));
112  $this->addMultiCommand('disable_notifications', $this->lng->txt('forums_disable_notification'));
113  }
114  if($this->getIsModerator())
115  {
116  $this->addMultiCommand('makesticky', $this->lng->txt('make_topics_sticky'));
117  $this->addMultiCommand('unmakesticky', $this->lng->txt('make_topics_non_sticky'));
118  $this->addMultiCommand('editThread', $this->lng->txt('frm_edit_title'));
119  $this->addMultiCommand('close', $this->lng->txt('close_topics'));
120  $this->addMultiCommand('reopen', $this->lng->txt('reopen_topics'));
121  $this->addMultiCommand('move', $this->lng->txt('move'));
122  }
123  $this->addMultiCommand('html', $this->lng->txt('export_html'));
124  if($this->getIsModerator())
125  {
126  $this->addMultiCommand('confirmDeleteThreads', $this->lng->txt('delete'));
127  }
128 
129  $this->setShowRowsSelector(true);
130  $this->setRowSelectorLabel($this->lng->txt('number_of_threads'));
131  }
132 
136  public function fillRow(ilForumTopic $thread)
137  {
141  global $ilUser;
142 
143  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
144 
145  $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(
146  (isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false), 'thread_ids[]', $thread->getId()
147  ));
148 
149  $subject = '';
150 
151  if($thread->isSticky())
152  {
153  $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
154  }
155  if($thread->isClosed())
156  {
157  $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
158  }
159 
160  if($ilUser->getId() != ANONYMOUS_USER_ID &&
161  $this->ilias->getSetting('forum_notification') != 0 &&
162  $thread->getUserNotificationEnabled()
163  )
164  {
165  $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
166  }
167 
168  $num_posts = $thread->getNumPosts();
169  $num_unread = $thread->getNumUnreadPosts();
170  $num_new = $thread->getNumNewPosts();
171 
172  if($num_posts > 0)
173  {
174  $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
175  }
176  else
177  {
178  $subject = $thread->getSubject() . $subject;
179  }
180  $this->tpl->setVariable('VAL_SUBJECT', $subject);
181 
182  // Author
183  $this->ctrl->setParameter($this->getParentObject(), 'backurl',
184  urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
185  $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getUserId());
186 
187  $authorinfo = new ilForumAuthorInformation(
188  $thread->getUserId(),
189  $thread->getUserAlias(),
190  $thread->getImportName(),
191  array(
192  'class' => 'il_ItemProperty',
193  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
194  )
195  );
196  $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
197 
198  $topicStats = $num_posts;
199  if($ilUser->getId() != ANONYMOUS_USER_ID)
200  {
201  if($num_unread > 0)
202  {
203  $topicStats .= '<br /><span class="alert" style="white-space:nowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
204  }
205  if($num_new > 0 && $this->getOverviewSetting() == 0)
206  {
207  $topicStats .= '<br /><span class="alert" style="white-space:nowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
208  }
209  }
210 
211  $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
212  $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
213 
214  $this->ctrl->clearParameters($this->getParentObject());
215 
216  // Last posting
217  if($num_posts > 0)
218  {
219  if($this->getIsModerator())
220  {
221  $objLastPost = $thread->getLastPost();
222  }
223  else
224  {
225  $objLastPost = $thread->getLastActivePost();
226  }
227 
228  if(is_object($objLastPost))
229  {
230  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
231  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $objLastPost->getThreadId());
232 
233  $authorinfo = new ilForumAuthorInformation(
234  $objLastPost->getUserId(),
235  $objLastPost->getUserAlias(),
236  $objLastPost->getImportName(),
237  array(
238  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()
239  )
240  );
241 
242  $this->tpl->setVariable('VAL_LP_DATE', '<div style="white-space:nowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
243  '<div style="white-space:nowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
244  );
245 
246  $this->ctrl->clearParameters($this->getParentObject());
247  }
248  }
249 
250  // Row style
251  $css_row = $this->css_row;
252  if($thread->isSticky())
253  {
254  $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
255  }
256  $this->tpl->setVariable('CSS_ROW', $css_row);
257  }
258 
265  protected function formatCellValue($cell, $value)
266  {
267  return $value;
268  }
269 
275  public function numericOrdering($column)
276  {
277  return false;
278  }
279 
283  public function fetchData()
284  {
285  global $ilAccess;
286 
287  $this->determineOffsetAndOrder();
288 
289  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $this->getIsModerator(), (int)$this->getLimit(), (int)$this->getOffset());
290  if(!count($data['items']) && $this->getOffset() > 0)
291  {
292  $this->resetOffset();
293  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $this->getIsModerator(), (int)$this->getLimit(), (int)$this->getOffset());
294  }
295 
296  $this->setMaxCount($data['cnt']);
297  $this->setData($data['items']);
298 
299  // Collect user ids for preloading user objects
300  $thread_ids = array();
301  $user_ids = array();
302  foreach($data['items'] as $thread)
303  {
307  $thread_ids[] = (int)$thread->getId();
308  if($thread->getUserId() > 0)
309  {
310  $user_ids[$thread->getUserId()] = (int)$thread->getUserId();
311  }
312  }
313 
314  $user_ids = array_merge(
315  ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids),
316  $user_ids
317  );
318 
319  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
320 
321  return $this;
322  }
323 
328  public function setMapper(ilForum $mapper)
329  {
330  $this->mapper = $mapper;
331  return $this;
332  }
333 
337  public function getMapper()
338  {
339  return $this->mapper;
340  }
341 
346  public function setRefId($ref_id)
347  {
348  $this->ref_id = $ref_id;
349  return $this;
350  }
351 
355  public function getRefId()
356  {
357  return $this->ref_id;
358  }
359 
365  {
366  $this->overview_setting = $overview_setting;
367  return $this;
368  }
369 
373  public function getOverviewSetting()
374  {
376  }
377 
382  public function setIsModerator($is_moderator)
383  {
384  $this->is_moderator = $is_moderator;
385  return $this;
386  }
387 
391  public function getIsModerator()
392  {
393  return $this->is_moderator;
394  }
395 
400  public function setTopicData($topicData)
401  {
402  $this->topicData = $topicData;
403  return $this;
404  }
405 
409  public function getTopicData()
410  {
411  return $this->topicData;
412  }
413 }