ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilForumExplorer.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once 'Services/YUI/classes/class.ilYuiUtil.php';
5include_once 'Services/JSON/classes/class.ilJsonUtil.php';
6
7
18{
25 protected $tpl;
26
33 protected $gui;
34
41 protected $topic;
42
49 protected $properties;
50
57 protected $root_id;
58
65 {
66 global $tpl, $ilCtrl;
67
68 $this->gui = $gui;
69 $this->topic = $topic;
70 $this->properties = $properties;
71
72 $this->tpl = new ilTemplate('tpl.frm_tree.html', true, true, 'Modules/Forum');
73
75 $tpl->addJavaScript(ilYuiUtil::getLocalPath() . '/yahoo/yahoo-min.js');
76 $tpl->addJavaScript(ilYuiUtil::getLocalPath() . '/event/event-min.js');
77 $tpl->addJavaScript('./Modules/Forum/js/treeview.js');
78 $tpl->addJavaScript('./Modules/Forum/js/treeview_extensions.js');
79 $tpl->addCss('./Modules/Forum/css/forum_tree.css');
80
81 // Set ref_id for urls
82 $ilCtrl->setParameter($this->gui, 'thr_pk', $this->topic->getId());
83 $ilCtrl->setParameter($this->gui, 'backurl', null);
84
85 // Set urls for async commands
86 $this->tpl->setVariable('THR_TREE_STATE_URL', $ilCtrl->getLinkTarget($this->gui, 'setTreeStateAsynch', '', true, false));
87 $this->tpl->setVariable('THR_TREE_FETCH_CHILDREN_URL', $ilCtrl->getLinkTarget($this->gui, 'fetchTreeChildrenAsync', '', true, false));
88
89 // Fetch root id of the thread node
90 $this->root_id = $this->topic->getFirstPostNode()->getId();
91
92 if(!is_array($_SESSION['frm'][$this->topic->getId()]['openTreeNodes']))
93 {
94 $_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes'] = array(0);
95 }
96
97 // Prevent key gaps
98 shuffle($_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes']);
99 }
100
101 public function render()
102 {
103 $this->fillTreeTemplate();
104
105 return $this;
106 }
107
108 public function fillTreeTemplate()
109 {
110 $emptyOnLoad = false;
111
112 $nodes_to_request = $_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes'];
113 if(!$_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes'] ||
114 (count($_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes']) == 1 && $_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes'][0] == 0))
115 {
116 $emptyOnLoad = true;
117 $nodes_to_request = array();
118 }
119
120 $objects = $this->topic->getNestedSetPostChildren(null, $nodes_to_request);
121
122 $counter = 0;
123
124 $onloadNodes = array();
125 $nodesFetchedWithChildren = array();
126
127 $frm = new ilForum();
128 $pageHits = $frm->getPageHits();
129
130 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
131
132 foreach($objects as $object)
133 {
134 if($object['pos_pk'] != $this->root_id &&
135 !in_array($object['parent_pos'], $onloadNodes)
136 )
137 {
138 continue;
139 }
140
141 if(in_array((int)$object['parent_pos'], $onloadNodes) &&
142 !in_array((int)$object['parent_pos'], $nodesFetchedWithChildren)
143 )
144 {
145 $nodesFetchedWithChildren[] = (int)$object['parent_pos'];
146 }
147
149 $object, $this->gui, $pageHits
150 );
151
152 $hasChildren = ($object['children'] >= 1);
153
154 $node = new stdClass();
155 $node->html = $html;
156
157 if($object['pos_pk'] == $this->root_id)
158 {
159 $this->tpl->setVariable('FRM_TREE_ROOT_NODE_VARIABLE', 'frmNode' . $object['pos_pk']);
160 $this->tpl->setVariable('FRM_TREE_ROOT_NODE_LINK', ilJsonUtil::encode($node));
161 $this->tpl->setVariable('FRM_TREE_ROOT_NODE_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
162 }
163 else
164 {
165 $this->tpl->setCurrentBlock('frm_nodes');
166 $this->tpl->setVariable('FRM_NODES_VARNAME', 'frmNode' . $object['pos_pk']);
167 $this->tpl->setVariable('FRM_NODES_PARENT_VARNAME', 'frmNode' . $object['parent_pos']);
168 $this->tpl->setVariable('FRM_NODES_LINK', ilJsonUtil::encode($node));
169 $this->tpl->setVariable('FRM_NODES_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
170 $this->tpl->parseCurrentBlock();
171 }
172
173 $onloadNodes[] = (int)$object['pos_pk'];
174
175 ++$counter;
176 }
177 $this->tpl->setVariable('THR_ONLOAD_NODES', ilJsonUtil::encode($onloadNodes));
178 $this->tpl->setVariable('THR_ONLOAD_NODES_FETCHED_WITH_CHILDREN', ilJsonUtil::encode($nodesFetchedWithChildren));
179
180 if($emptyOnLoad)
181 {
182 $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($onloadNodes));
183 $_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes'] = array_unique(array_merge(array(0), $onloadNodes));
184 }
185 else
186 {
187 $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($_SESSION['frm'][(int)$this->topic->getId()]['openTreeNodes']));
188 }
189 }
190
197 public static function getTreeNodeHtml($object, ilObjForumGUI $gui, $pageHits)
198 {
199 global $ilCtrl;
200
201 $html = '';
202
203 // Set pos_pk for urls
204 $ilCtrl->setParameter($gui, 'pos_pk', $object['pos_pk']);
205
206 // Set offset
207 $ilCtrl->setParameter($gui, 'offset', floor($object['counter'] / $pageHits) * $pageHits);
208
209 // @todo: HTML in PHP used because of performance issues of ilTemplate an big forum trees
210 if($object['post_read'])
211 {
212 $url = $ilCtrl->getLinkTarget($gui, 'viewThread', $object['pos_pk']);
213 $link = "<a class='small' href='" . $url . "'>" . stripslashes($object['pos_subject']) . "</a>";
214
215 $html .= "<div class='frmTreeInfo'><span class='frmTitle' id='frm_node_" . $object['pos_pk'] . "'>" . $link . "</span><br />" .
216 "<span id='frm_node_desc_" . $object['pos_pk'] . "' class='small'>";
217 }
218 else
219 {
220 $url = $ilCtrl->getLinkTarget($gui, 'markPostRead', $object['pos_pk']);
221 $link = "<a class='small' href='" . $url . "'>" . stripslashes($object['pos_subject']) . "</a>";
222
223 $html .= "<div class='frmTreeInfo'><span class='frmTitleBold' id='frm_node_" . $object['pos_pk'] . "'>" . $link . "</span><br />" .
224 "<span id='frm_node_desc_" . $object['pos_pk'] . "' class='small'>";
225 }
226
227 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
228 $authorinfo = new ilForumAuthorInformation(
229 $object['pos_author_id'],
230 $object['pos_display_user_id'],
231 $object['pos_usr_alias'],
232 $object['import_name']
233 );
234 $html .= $authorinfo->getAuthorShortName();
235 $html .= ", " . ilDatePresentation::formatDate(new ilDateTime($object['pos_date'], IL_CAL_DATETIME)) . "</span></div>";
236
237 return $html;
238 }
239
246 public function getHtml()
247 {
248 return $this->tpl->get();
249 }
250}
$_SESSION["AccountId"]
const IL_CAL_DATETIME
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Class ilForumExplorer class for explorer view of forum posts.
getHtml()
This method returns the tree html for the forum template @access public.
__construct(ilObjForumGUI $gui, ilForumTopic $topic, ilForumProperties $properties)
Constructor @access public.
static getTreeNodeHtml($object, ilObjForumGUI $gui, $pageHits)
Returns the html used for a single forum tree node @access public.
Class Forum core functions for forum.
static encode($mixed, $suppress_native=false)
Class ilObjForumGUI.
special template class to simplify handling of ITX/PEAR
static initConnection()
Init YUI Connection module.
static getLocalPath($a_name="")
Get local path of a YUI js file.
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
$url
Definition: shib_logout.php:72