ILIAS  release_7 Revision v7.30-3-g800a261c036
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  $this->ctrl->setParameter($this->getParentObject(), 'page', 0);
264  $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
265  $this->ctrl->setParameter($this->getParentObject(), 'page', null);
266  $this->tpl->setVariable('VAL_SUBJECT', $subject);
267 
268  // Author
269  $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
270  $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getDisplayUserId());
271 
272  $authorinfo = new ilForumAuthorInformation(
273  $thread->getThrAuthorId(),
274  $thread->getDisplayUserId(),
275  $thread->getUserAlias(),
276  $thread->getImportName(),
277  array(
278  'class' => 'il_ItemProperty',
279  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
280  )
281  );
282  $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
283 
284  $topicStats = $num_posts;
285  if (!$this->user->isAnonymous()) {
286  if ($num_unread > 0) {
287  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
288  }
289  if ($num_new > 0 && $this->getOverviewSetting() == 0) {
290  $topicStats .= '<br /><span class="ilAlert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
291  }
292  }
293 
294  $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
295  $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
296  if ($this->is_post_draft_allowed) {
297  $draft_statistics = ilForumPostDraft::getDraftsStatisticsByRefId($this->getRefId());
298  $this->tpl->setVariable('VAL_DRAFTS', (int) $draft_statistics[$thread->getId()]);
299  }
300  // Last posting
301  if ($num_posts > 0) {
302  if ($thread->getLastPostForThreadOverview() instanceof ilForumPost) {
303  $objLastPost = $thread->getLastPostForThreadOverview();
304 
305  $this->ctrl->setParameter($this->getParentObject(), 'user', $objLastPost->getDisplayUserId());
306  $authorinfo = new ilForumAuthorInformation(
307  $objLastPost->getPosAuthorId(),
308  $objLastPost->getDisplayUserId(),
309  $objLastPost->getUserAlias(),
310  $objLastPost->getImportName(),
311  array(
312  'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')
313  )
314  );
315 
316  $this->tpl->setVariable(
317  'VAL_LP_DATE',
318  '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' .
319  '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'
320  );
321  }
322  }
323 
324  // Row style
325  $css_row = $this->css_row;
326  if ($thread->isSticky()) {
327  $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
328  }
329  $this->tpl->setVariable('CSS_ROW', $css_row);
330 
331  $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
332  $this->ctrl->setParameter($this->getParentObject(), 'user', '');
333  $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
334  }
335 
342  protected function formatCellValue($cell, $value)
343  {
344  return $value;
345  }
346 
352  public function numericOrdering($column)
353  {
354  return false;
355  }
356 
360  public function fetchData()
361  {
362  $this->determineOffsetAndOrder();
363 
364  $excluded_ids = array();
365  if ($this->parent_cmd == 'mergeThreads' &&
366  $this->getSelectedThread() instanceof ilForumTopic) {
367  $excluded_ids[] = $this->getSelectedThread()->getId();
368  }
369 
370  $params = array(
371  'is_moderator' => $this->getIsModerator(),
372  'excluded_ids' => $excluded_ids,
373  'order_column' => $this->getOrderField(),
374  'order_direction' => $this->getOrderDirection()
375  );
376 
377  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
378  if (!count($data['items']) && $this->getOffset() > 0) {
379  $this->resetOffset();
380  $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
381  }
382 
383  $this->setMaxCount($data['cnt']);
384  $this->setData($data['items']);
385 
386  // Collect user ids for preloading user objects
387  $thread_ids = array();
388  $user_ids = array();
389  foreach ($data['items'] as $thread) {
393  $thread_ids[] = (int) $thread->getId();
394  if ($thread->getDisplayUserId() > 0) {
395  $user_ids[$thread->getDisplayUserId()] = (int) $thread->getDisplayUserId();
396  }
397  }
398 
399  $user_ids = array_merge(
401  $user_ids
402  );
403 
404  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
405 
406  return $this;
407  }
408 
413  public function setMapper(ilForum $mapper)
414  {
415  $this->mapper = $mapper;
416  return $this;
417  }
418 
422  public function getMapper()
423  {
424  return $this->mapper;
425  }
426 
431  public function setRefId($ref_id)
432  {
433  $this->ref_id = $ref_id;
434  return $this;
435  }
436 
440  public function getRefId()
441  {
442  return $this->ref_id;
443  }
444 
450  {
451  $this->overview_setting = $overview_setting;
452  return $this;
453  }
454 
458  public function getOverviewSetting()
459  {
461  }
462 
467  public function setIsModerator($is_moderator)
468  {
469  $this->is_moderator = $is_moderator;
470  return $this;
471  }
472 
476  public function getIsModerator()
477  {
478  return $this->is_moderator;
479  }
480 
485  public function setTopicData($topicData)
486  {
487  $this->topicData = $topicData;
488  return $this;
489  }
490 
494  public function getTopicData()
495  {
496  return $this->topicData;
497  }
498 
502  public function setSelectedThread(ilForumTopic $thread_obj)
503  {
504  $this->merge_thread_obj = $thread_obj;
505  }
506 
510  public function getSelectedThread()
511  {
513  }
514 }
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
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.
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 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.
global $DIC
Definition: goto.php:24
addMultiCommand($a_cmd, $a_text)
Add Command button.
numericOrdering($column)
Currently not used because of external segmentation and sorting.
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
__construct(Container $dic, ilPlugin $plugin)
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)