ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
62  global $DIC;
63 
64  parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
65 
66  $this->setSkipRootNode(false);
67  $this->setAjax(true);
68 
69  $this->tpl = $DIC->ui()->mainTemplate();
70  $this->ctrl = $DIC->ctrl();
71 
72  $frm = new ilForum();
73  $this->max_entries = (int) $frm->getPageHits();
74  }
75 
79  public function getThread()
80  {
81  return $this->thread;
82  }
83 
87  public function setThread($thread)
88  {
89  $this->thread = $thread;
90  $this->root_node = $thread->getFirstPostNode();
91  $this->root_node->setIsRead($this->root_node->isRead($this->root_node->getPosAuthorId()));
92 
93  $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
94  }
95 
99  public function getRootNode()
100  {
101  if (null === $this->root_node) {
102  $this->root_node = $this->thread->getFirstPostNode();
103  }
104 
105  return array(
106  'pos_pk' => $this->root_node->getId(),
107  'pos_subject' => $this->root_node->getSubject(),
108  'pos_author_id' => $this->root_node->getPosAuthorId(),
109  'pos_display_user_id' => $this->root_node->getDisplayUserId(),
110  'pos_usr_alias' => $this->root_node->getUserAlias(),
111  'pos_date' => $this->root_node->getCreateDate(),
112  'import_name' => $this->root_node->getImportName(),
113  'post_read' => $this->root_node->isPostRead()
114  );
115  }
116 
121  protected function getNodeTemplateInstance()
122  {
123  return new ilTemplate('tpl.tree_node_content.html', true, true, 'Modules/Forum');
124  }
125 
129  public function getChildsOfNode($a_parent_node_id)
130  {
131  if ($this->preloaded) {
132  if (isset($this->preloaded_children[$a_parent_node_id])) {
133  return $this->preloaded_children[$a_parent_node_id];
134  }
135  }
136 
137  return $this->thread->getNestedSetPostChildren($a_parent_node_id, 1);
138  }
139 
143  public function preloadChildren()
144  {
145  $this->preloaded_children = array();
146  $this->node_id_to_parent_node_id_map = array();
147 
148  $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
149 
150  array_walk($children, function (&$a_node, $key) {
151  $this->node_id_to_parent_node_id_map[(int) $a_node['pos_pk']] = (int) $a_node['parent_pos'];
152  $this->preloaded_children[(int) $a_node['parent_pos']][$a_node['pos_pk']] = $a_node;
153  });
154 
155  $this->preloaded = true;
156  }
157 
161  public function getNodeContent($a_node)
162  {
163  $tpl = $this->getNodeTemplateInstance();
164 
165  $tpl->setCurrentBlock('node-content-block');
166  $tpl->setVariable('TITLE', $a_node['pos_subject']);
167  $tpl->setVariable('TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($a_node)));
168  $tpl->parseCurrentBlock();
169 
170  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
171  $authorinfo = new ilForumAuthorInformation(
172  $a_node['pos_author_id'],
173  $a_node['pos_display_user_id'],
174  $a_node['pos_usr_alias'],
175  $a_node['import_name']
176  );
177 
178  $tpl->setCurrentBlock('unlinked-node-content-block');
179  $tpl->setVariable('UNLINKED_CONTENT_CLASS', $this->getUnlinkedNodeContentClass());
180  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
181  $tpl->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($a_node['pos_date'], IL_CAL_DATETIME)));
182  $tpl->parseCurrentBlock();
183 
184  return $tpl->get();
185  }
186 
191  protected function getNodeTitleClasses(array $node_config)
192  {
193  $node_title_classes = array('ilForumTreeTitle');
194 
195  if (isset($node_config['post_read']) && !$node_config['post_read']) {
196  $node_title_classes[] = 'ilForumTreeTitleUnread';
197  }
198 
199  return $node_title_classes;
200  }
201 
205  protected function getUnlinkedNodeContentClass()
206  {
207  return 'ilForumTreeUnlinkedContent';
208  }
209 
213  public function getNodeHref($a_node)
214  {
215  $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
216  $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $a_node['pos_pk']);
217 
218  if (isset($a_node['counter'])) {
219  $this->ctrl->setParameter($this->parent_obj, 'offset', floor($a_node['counter'] / $this->max_entries) * $this->max_entries);
220  }
221 
222  if (isset($a_node['post_read']) && $a_node['post_read']) {
223  return $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, $a_node['pos_pk']);
224  } else {
225  return $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', $a_node['pos_pk']);
226  }
227  }
228 
232  public function getNodeId($a_node)
233  {
234  return $a_node['pos_pk'];
235  }
236 
240  public function getNodeIcon($a_node)
241  {
242  return ilObject::_getIcon(0, 'tiny', 'frm');
243  }
244 
248  public function getHTML()
249  {
250  $this->preloadChildren();
251 
252  if (isset($_GET['post_created_below']) && (int) $_GET['post_created_below'] > 0) {
253  $parent = (int) $_GET['post_created_below'];
254  do {
255  $this->setNodeOpen((int) $parent);
256  } while ($parent = $this->node_id_to_parent_node_id_map[$parent]);
257  }
258 
259  $html = parent::getHTML();
260 
261  $this->tpl->addOnLoadCode('il.ForumExplorer.init(' . json_encode(array(
262  'selectors' => array(
263  'container' => '#' . $this->getContainerId(),
264  'unlinked_content' => '.' . $this->getUnlinkedNodeContentClass()
265  )
266  )) . ');');
267 
268  $this->tpl->addJavascript($this->js_explorer_frm_path);
269 
270  return $html;
271  }
272 }
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.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
setSkipRootNode($a_val)
Set skip root node.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour) ...
getChildsOfNode($a_parent_node_id)
{}
Explorer base GUI class.
special template class to simplify handling of ITX/PEAR
Date and time handling
Create styles array
The data for the language used.
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.