ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
9 {
13  protected $js_explorer_frm_path = './Modules/Forum/js/ilForumExplorer.js';
14 
18  protected $thread;
19 
23  protected $max_entries = PHP_INT_MAX;
24 
28  protected $tpl;
29 
33  protected $ctrl;
34 
38  protected $preloaded = false;
39 
43  protected $preloaded_children = array();
44 
48  protected $node_id_to_parent_node_id_map = array();
49 
53  protected $root_node = null;
54 
56  protected $authorInformation = [];
57 
61  public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd)
62  {
63  global $DIC;
64 
65  parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
66 
67  $this->setSkipRootNode(false);
68  $this->setAjax(true);
69 
70  $this->tpl = $DIC->ui()->mainTemplate();
71  $this->ctrl = $DIC->ctrl();
72 
73  $frm = new ilForum();
74  $this->max_entries = (int) $frm->getPageHits();
75  }
76 
81  public function setThread(ilForumTopic $thread, ilForumPost $firstNode)
82  {
83  $this->thread = $thread;
84  $this->root_node = $firstNode;
85  $this->root_node->setIsRead($this->root_node->isRead($this->root_node->getPosAuthorId()));
86  $this->setNodeOpen($this->root_node->getId());
87 
88  $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
89  }
90 
94  public function isNodeClickable($a_node)
95  {
96  $result = parent::isNodeClickable($a_node);
97  if (!$result) {
98  return false;
99  }
100 
101  return $this->root_node->getId() != $a_node['pos_pk'];
102  }
103 
104 
108  public function getRootNode()
109  {
110  if (null === $this->root_node) {
111  $this->root_node = $this->thread->getFirstPostNode();
112  }
113 
114  return array(
115  'pos_pk' => $this->root_node->getId(),
116  'pos_subject' => $this->root_node->getSubject(),
117  'pos_author_id' => $this->root_node->getPosAuthorId(),
118  'pos_display_user_id' => $this->root_node->getDisplayUserId(),
119  'pos_usr_alias' => $this->root_node->getUserAlias(),
120  'pos_date' => $this->root_node->getCreateDate(),
121  'import_name' => $this->root_node->getImportName(),
122  'post_read' => $this->root_node->isPostRead()
123  );
124  }
125 
130  protected function getNodeTemplateInstance()
131  {
132  return new ilTemplate('tpl.tree_node_content.html', true, true, 'Modules/Forum');
133  }
134 
138  public function getChildsOfNode($a_parent_node_id)
139  {
140  if ($this->preloaded) {
141  if (isset($this->preloaded_children[$a_parent_node_id])) {
142  return $this->preloaded_children[$a_parent_node_id];
143  }
144 
145  return [];
146  }
147 
148  return $this->thread->getNestedSetPostChildren($a_parent_node_id, 1);
149  }
150 
154  public function preloadChildren()
155  {
156  $this->preloaded_children = array();
157  $this->node_id_to_parent_node_id_map = array();
158 
159  $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
160 
161  array_walk($children, function (&$a_node, $key) {
162  $this->node_id_to_parent_node_id_map[(int) $a_node['pos_pk']] = (int) $a_node['parent_pos'];
163  $this->preloaded_children[(int) $a_node['parent_pos']][$a_node['pos_pk']] = $a_node;
164  });
165 
166  $this->preloaded = true;
167  }
168 
172  public function getNodeContent($a_node)
173  {
174  $tpl = $this->getNodeTemplateInstance();
175 
176  $tpl->setCurrentBlock('node-content-block');
177  $tpl->setVariable('TITLE', $a_node['pos_subject']);
178  $tpl->setVariable('TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($a_node)));
179  $tpl->parseCurrentBlock();
180 
181  if ($this->root_node->getId() == $a_node['pos_pk']) {
182  return $tpl->get();
183  }
184 
185  $authorinfo = $this->getAuthorInformationByNode($a_node);
186 
187  $tpl->setCurrentBlock('unlinked-node-content-block');
188  $tpl->setVariable('UNLINKED_CONTENT_CLASS', $this->getUnlinkedNodeContentClass());
189  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
190  $tpl->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($a_node['pos_date'], IL_CAL_DATETIME)));
191  $tpl->parseCurrentBlock();
192 
193  return $tpl->get();
194  }
195 
200  protected function getNodeTitleClasses(array $node_config)
201  {
202  $node_title_classes = array('ilForumTreeTitle');
203 
204  if ($this->root_node->getId() == $node_config['pos_pk']) {
205  return $node_title_classes;
206  }
207 
208  if (isset($node_config['post_read']) && !$node_config['post_read']) {
209  $node_title_classes[] = 'ilForumTreeTitleUnread';
210  }
211 
212  return $node_title_classes;
213  }
214 
218  protected function getUnlinkedNodeContentClass()
219  {
220  return 'ilForumTreeUnlinkedContent';
221  }
222 
226  public function getNodeHref($a_node)
227  {
228  $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
229  $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $a_node['pos_pk']);
230 
231  if (isset($a_node['counter'])) {
232  $this->ctrl->setParameter($this->parent_obj, 'offset', floor($a_node['counter'] / $this->max_entries) * $this->max_entries);
233  }
234 
235  if (isset($a_node['post_read']) && $a_node['post_read']) {
236  return $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, $a_node['pos_pk']);
237  } else {
238  return $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', $a_node['pos_pk']);
239  }
240  }
241 
246  private function getAuthorInformationByNode(array $node) : \ilForumAuthorInformation
247  {
248  if (isset($this->authorInformation[(int) $node['pos_pk']])) {
249  return $this->authorInformation[(int) $node['pos_pk']];
250  }
251 
252  return $this->authorInformation[(int) $node['pos_pk']] = new ilForumAuthorInformation(
253  $node['pos_author_id'],
254  $node['pos_display_user_id'],
255  $node['pos_usr_alias'],
256  $node['import_name']
257  );
258  }
259 
263  public function getNodeId($a_node)
264  {
265  return $a_node['pos_pk'];
266  }
267 
271  public function getNodeIcon($a_node)
272  {
273  if ($this->root_node->getId() == $a_node['pos_pk']) {
274  return ilObject::_getIcon(0, 'tiny', 'frm');
275  }
276 
277  return $this->getAuthorInformationByNode($a_node)->getProfilePicture();
278  }
279 
283  public function beforeRendering()
284  {
285  if (isset($_GET['post_created_below']) && (int) $_GET['post_created_below'] > 0) {
286  $parent = (int) $_GET['post_created_below'];
287  do {
288  $this->setNodeOpen((int) $parent);
289  } while ($parent = $this->node_id_to_parent_node_id_map[$parent]);
290 
291  $this->store->set("on_" . $this->id, serialize(array_unique(array_merge($this->open_nodes, $this->custom_open_nodes))));
292  }
293  }
294 
298  public function getHTML()
299  {
300  $this->preloadChildren();
301 
302  $html = parent::getHTML();
303 
304  $this->tpl->addOnLoadCode('il.ForumExplorer.init(' . json_encode(array(
305  'selectors' => array(
306  'container' => '#' . $this->getContainerId(),
307  'unlinked_content' => '.' . $this->getUnlinkedNodeContentClass()
308  )
309  )) . ');');
310 
311  $this->tpl->addJavascript($this->js_explorer_frm_path);
312 
313  return $html;
314  }
315 }
Class Forum core functions for forum.
const IL_CAL_DATETIME
$result
Class ilForumExplorerGUI.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
setSkipRootNode($a_val)
Set skip root node.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour) ...
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
getChildsOfNode($a_parent_node_id)
{}
Explorer base GUI class.
special template class to simplify handling of ITX/PEAR
Date and time handling
setThread(ilForumTopic $thread, ilForumPost $firstNode)
getNodeTemplateInstance()
Factory method for a new instance of a node template.
__construct($a_expl_id, $a_parent_obj, $a_parent_cmd)
{}
getNodeTitleClasses(array $node_config)
$key
Definition: croninfo.php:18
$html
Definition: example_001.php:87
getContainerId()
Get container id.
setIsRead($a_is_read)