ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilForumExplorerGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
12{
14 protected $thread;
15
17 protected $root_node;
18
21
23 protected $max_entries = PHP_INT_MAX;
24
26 protected $preloaded_children = [];
27
29 protected $authorInformation = [];
30
32 protected $currentPostingId = 0;
33
35 private $currentPage = 0;
36
45 public function __construct(string $a_expl_id, object $a_parent_obj, string $a_parent_cmd, ilForumTopic $thread, ilForumPost $root)
46 {
47 global $DIC;
48
49 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $DIC->repositoryTree());
50
51 $this->setSkipRootNode(false);
52 $this->setAjax(false);
53 $this->setPreloadChilds(true);
54
55 $this->thread = $thread;
56 $this->root_node = $root;
57
58 $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
59
60 $frm = new ilForum();
61 $this->max_entries = (int) $frm->getPageHits();
62
63 $this->initPosting();
64
65 $this->setNodeOpen($this->root_node->getId());
66 }
67
71 protected function initPosting() : void
72 {
73 $postingId = (int) ($this->httpRequest->getParsedBody()['pos_pk'] ?? 0);
74 if (0 === $postingId) {
75 $postingId = (int) ($this->httpRequest->getQueryParams()['pos_pk'] ?? 0);
76 }
77
78 $this->currentPostingId = (int) $postingId;
79 }
80
84 public function getChildsOfNode($parentNodeId)
85 {
86 if ($this->preloaded) {
87 if (isset($this->preloaded_children[$parentNodeId])) {
88 return $this->preloaded_children[$parentNodeId];
89 }
90
91 return [];
92 }
93
94 return $this->thread->getNestedSetPostChildren($parentNodeId, 1);
95 }
96
100 public function setCurrentPage(int $currentPage) : void
101 {
102 $this->currentPage = $currentPage;
103 }
104
108 protected function preloadChilds()
109 {
110 $this->preloaded_children = [];
111 $this->node_id_to_parent_node_id_map = [];
112
113 $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
114
115 array_walk($children, function (&$node, $key) {
116 $this->node_id_to_parent_node_id_map[(int) $node['pos_pk']] = (int) $node['parent_pos'];
117
118 if (!array_key_exists((int) $node['pos_pk'], $this->preloaded_children)) {
119 $this->preloaded_children[(int) $node['pos_pk']] = [];
120 }
121
122 $this->preloaded_children[(int) $node['parent_pos']][$node['pos_pk']] = $node;
123 });
124
125 $this->preloaded = true;
126 }
127
131 public function getChildren($record, $environment = null) : array
132 {
133 return $this->getChildsOfNode((int) $record['pos_pk']);
134 }
135
139 public function getTreeLabel()
140 {
141 return $this->lng->txt("frm_posts");
142 }
143
147 public function getTreeComponent() : Tree
148 {
149 $rootNode = [
150 [
151 'pos_pk' => $this->root_node->getId(),
152 'pos_subject' => $this->root_node->getSubject(),
153 'pos_author_id' => $this->root_node->getPosAuthorId(),
154 'pos_display_user_id' => $this->root_node->getDisplayUserId(),
155 'pos_usr_alias' => $this->root_node->getUserAlias(),
156 'pos_date' => $this->root_node->getCreateDate(),
157 'import_name' => $this->root_node->getImportName(),
158 'post_read' => $this->root_node->isPostRead()
159 ]
160 ];
161
162 $tree = $this->ui->factory()->tree()
163 ->expandable($this->getTreeLabel(), $this)
164 ->withData($rootNode)
165 ->withHighlightOnNodeClick(false);
166
167 return $tree;
168 }
169
173 protected function createNode(
174 \ILIAS\UI\Component\Tree\Node\Factory $factory,
175 $record
176 ) : \ILIAS\UI\Component\Tree\Node\Node {
177 $nodeIconPath = $this->getNodeIcon($record);
178
179 $icon = null;
180 if (is_string($nodeIconPath) && strlen($nodeIconPath) > 0) {
181 $icon = $this->ui
182 ->factory()
183 ->symbol()
184 ->icon()
185 ->custom($nodeIconPath, $this->getNodeIconAlt($record));
186 }
187
188 if ((int) $record['pos_pk'] === (int) $this->root_node->getId()) {
189 $node = $factory->simple($this->getNodeContent($record), $icon);
190 } else {
191 $authorInfo = $this->getAuthorInformationByNode($record);
192 $creationDate = ilDatePresentation::formatDate(new ilDateTime($record['pos_date'], IL_CAL_DATETIME));
193 $bylineString = $authorInfo->getAuthorShortName() . ', ' . $creationDate;
194
195 $node = $factory->bylined($this->getNodeContent($record), $bylineString, $icon);
196 }
197
198 return $node;
199 }
200
204 protected function getNodeStateToggleCmdClasses($record) : array
205 {
206 return [
207 'ilRepositoryGUI',
208 'ilObjForumGUI',
209 ];
210 }
211
217 {
218 if (isset($this->authorInformation[(int) $node['pos_pk']])) {
219 return $this->authorInformation[(int) $node['pos_pk']];
220 }
221
222 return $this->authorInformation[(int) $node['pos_pk']] = new ilForumAuthorInformation(
223 $node['pos_author_id'],
224 $node['pos_display_user_id'],
225 $node['pos_usr_alias'],
226 $node['import_name']
227 );
228 }
229
233 public function getNodeId($a_node)
234 {
235 return $a_node['pos_pk'];
236 }
237
241 public function getNodeIcon($node)
242 {
243 if ((int) $this->root_node->getId() === (int) $node['pos_pk']) {
244 return ilObject::_getIcon(0, 'tiny', 'frm');
245 }
246
247 return $this->getAuthorInformationByNode($node)->getProfilePicture();
248 }
249
253 public function getNodeHref($node)
254 {
255 if ((int) $this->root_node->getId() === (int) $node['pos_pk']) {
256 return '';
257 }
258
259 $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
260
261 if (isset($node['counter']) && $node['counter'] > 0) {
262 $page = (int) floor(($node['counter'] - 1) / $this->max_entries);
263 $this->ctrl->setParameter($this->parent_obj, 'page', $page);
264 }
265
266 if (isset($node['post_read']) && $node['post_read']) {
267 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
268 $url = $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, $node['pos_pk'], false, false);
269 } else {
270 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $node['pos_pk']);
271 $url = $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', $node['pos_pk'], false, false);
272 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
273 }
274
275 $this->ctrl->setParameter($this->parent_obj, 'page', null);
276
277 return $url;
278 }
279
283 public function getNodeContent($a_node)
284 {
285 return $a_node['pos_subject'];
286 }
287}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
setSkipRootNode($a_val)
Set skip root node.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour)
Class ilForumExplorerGUI.
getNodeContent($a_node)
@inheritDoc
getChildsOfNode($parentNodeId)
@inheritDoc
getNodeStateToggleCmdClasses($record)
@inheritDoc
__construct(string $a_expl_id, object $a_parent_obj, string $a_parent_cmd, ilForumTopic $thread, ilForumPost $root)
ilForumExplorerGUI constructor.
setCurrentPage(int $currentPage)
getChildren($record, $environment=null)
@inheritDoc
createNode(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record)
@inheritDoc
getNodeId($a_node)
@inheritDoc
Class Forum core functions for forum.
Explorer class that works on tree objects (Services/Tree)
setPreloadChilds($a_val)
Set preload childs.
getNodeIconAlt($a_node)
Get node icon alt attribute.
This describes a Tree Node.
Definition: Node.php:16
This describes a Tree Control.
Definition: Tree.php:14
$factory
Definition: metadata.php:58
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$url
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46