ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumExplorerGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php';
5 
11 {
15  protected $js_explorer_frm_path = './Modules/Forum/js/ilForumExplorer.js';
16 
20  protected $thread;
21 
25  protected $max_entries = PHP_INT_MAX;
26 
30  protected $tpl;
31 
35  protected $ctrl;
36 
40  protected $preloaded = false;
41 
45  protected $preloaded_children = array();
46 
51 
55  protected $root_node = null;
56 
60  public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd)
61  {
66  global $tpl, $ilCtrl;
67 
68  parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
69 
70  $this->setSkipRootNode(false);
71  $this->setAjax(true);
72 
73  $this->tpl = $tpl;
74  $this->ctrl = $ilCtrl;
75 
76  $frm = new ilForum();
77  $this->max_entries = (int)$frm->getPageHits();
78  }
79 
83  public function getThread()
84  {
85  return $this->thread;
86  }
87 
91  public function setThread($thread)
92  {
93  $this->thread = $thread;
94  $this->root_node = $thread->getFirstPostNode();
95  $this->root_node->setIsRead($this->root_node->isRead($this->root_node->getPosAuthorId()));
96 
97  $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
98  }
99 
103  public function getRootNode()
104  {
105  if(null === $this->root_node)
106  {
107  $this->root_node = $this->thread->getFirstPostNode();
108  }
109 
110  return array(
111  'pos_pk' => $this->root_node->getId(),
112  'pos_subject' => $this->root_node->getSubject(),
113  'pos_author_id' => $this->root_node->getPosAuthorId(),
114  'pos_display_user_id' => $this->root_node->getDisplayUserId(),
115  'pos_usr_alias' => $this->root_node->getUserAlias(),
116  'pos_date' => $this->root_node->getCreateDate(),
117  'import_name' => $this->root_node->getImportName(),
118  'post_read' => $this->root_node->isPostRead()
119  );
120  }
121 
126  protected function getNodeTemplateInstance() {
127  return new ilTemplate('tpl.tree_node_content.html', true, true, 'Modules/Forum');
128  }
129 
133  public function getChildsOfNode($a_parent_node_id)
134  {
135  if($this->preloaded)
136  {
137  if(isset($this->preloaded_children[$a_parent_node_id]))
138  {
139  return $this->preloaded_children[$a_parent_node_id];
140  }
141  }
142 
143  return $this->thread->getNestedSetPostChildren($a_parent_node_id, 1);
144  }
145 
149  public function preloadChildren()
150  {
151  $this->preloaded_children = array();
152  $this->node_id_to_parent_node_id_map = array();
153 
154  $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
155 
156  array_walk($children, function(&$a_node, $key) {
157  $this->node_id_to_parent_node_id_map[(int)$a_node['pos_pk']] = (int)$a_node['parent_pos'];
158  $this->preloaded_children[(int)$a_node['parent_pos']][$a_node['pos_pk']] = $a_node;
159  });
160 
161  $this->preloaded = true;
162  }
163 
167  public function getNodeContent($a_node)
168  {
169  $tpl = $this->getNodeTemplateInstance();
170 
171  $tpl->setCurrentBlock('node-content-block');
172  $tpl->setVariable('TITLE', $a_node['pos_subject']);
173  $tpl->setVariable('TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($a_node)));
174  $tpl->parseCurrentBlock();
175 
176  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
177  $authorinfo = new ilForumAuthorInformation(
178  $a_node['pos_author_id'],
179  $a_node['pos_display_user_id'],
180  $a_node['pos_usr_alias'],
181  $a_node['import_name']
182  );
183 
184  $tpl->setCurrentBlock('unlinked-node-content-block');
185  $tpl->setVariable('UNLINKED_CONTENT_CLASS', $this->getUnlinkedNodeContentClass());
186  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
187  $tpl->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($a_node['pos_date'], IL_CAL_DATETIME)));
188  $tpl->parseCurrentBlock();
189 
190  return $tpl->get();
191  }
192 
197  protected function getNodeTitleClasses(array $node_config)
198  {
199  $node_title_classes = array('ilForumTreeTitle');
200 
201  if(isset($node_config['post_read']) && !$node_config['post_read'])
202  {
203  $node_title_classes[] = 'ilForumTreeTitleUnread';
204  }
205 
206  return $node_title_classes;
207  }
208 
212  protected function getUnlinkedNodeContentClass()
213  {
214  return 'ilForumTreeUnlinkedContent';
215  }
216 
220  public function getNodeHref($a_node)
221  {
222  $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
223  $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $a_node['pos_pk']);
224 
225  if(isset($a_node['counter']))
226  {
227  $this->ctrl->setParameter($this->parent_obj, 'offset', floor($a_node['counter'] / $this->max_entries) * $this->max_entries);
228  }
229 
230  if(isset($a_node['post_read']) && $a_node['post_read'])
231  {
232  return $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, $a_node['pos_pk']);
233  }
234  else
235  {
236  return $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', $a_node['pos_pk']);
237  }
238  }
239 
243  public function getNodeId($a_node)
244  {
245  return $a_node['pos_pk'];
246  }
247 
251  public function getNodeIcon($a_node)
252  {
253  return ilObject::_getIcon(0, 'tiny', 'frm');
254  }
255 
259  public function getHTML()
260  {
261  $this->preloadChildren();
262 
263  if(isset($_GET['post_created_below']) && (int)$_GET['post_created_below'] > 0)
264  {
265  $parent = (int)$_GET['post_created_below'];
266  do
267  {
268  $this->setNodeOpen((int)$parent);
269  }
270  while($parent = $this->node_id_to_parent_node_id_map[$parent]);
271  }
272 
273  $html = parent::getHTML();
274 
275  $this->tpl->addOnLoadCode('il.ForumExplorer.init(' . json_encode(array(
276  'selectors' => array(
277  'container' => '#' . $this->getContainerId(),
278  'unlinked_content' => '.' . $this->getUnlinkedNodeContentClass()
279  )
280  )) . ');');
281 
282  $this->tpl->addJavascript($this->js_explorer_frm_path);
283 
284  return $html;
285  }
286 }
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Class Forum core functions for forum.
const IL_CAL_DATETIME
Class ilForumExplorerGUI.
$_GET["client_id"]
setSkipRootNode($a_val)
Set skip root node.
__construct($a_expl_id, $a_parent_obj, $a_parent_cmd)
Constructor.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour) ...
global $ilCtrl
Definition: ilias.php:18
getChildsOfNode($a_parent_node_id)
{}
Explorer base GUI class.
special template class to simplify handling of ITX/PEAR
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
Create styles array
The data for the language used.
getNodeTemplateInstance()
Factory method for a new instance of a node template.
getNodeTitleClasses(array $node_config)
$html
Definition: example_001.php:87
getContainerId()
Get container id.