ILIAS  release_8 Revision v8.24
class.ilForumExplorerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
31 private int $max_entries;
33 private array $preloaded_children = [];
34
36 private array $authorInformation = [];
37
38 public function __construct(
39 string $a_expl_id,
40 object $a_parent_obj,
41 string $a_parent_cmd,
43 ilForumPost $root
44 ) {
45 global $DIC;
46
47 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $DIC->repositoryTree());
48
49 $this->setSkipRootNode(false);
50 $this->setAjax(false);
51 $this->setPreloadChilds(true);
52
53 $this->thread = $thread;
54 $this->root_node = $root;
55
56 $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
57
58 $frm = new ilForum();
59 $this->max_entries = $frm->getPageHits();
60
61 $this->setNodeOpen($this->root_node->getId());
62 }
63
64 private function getRootNodeId(): int
65 {
66 return $this->root_node->getId();
67 }
68
70 {
71 return $this->authorInformation[(int) $node['pos_pk']] ?? ($this->authorInformation[(int) $node['pos_pk']] = new ilForumAuthorInformation(
72 (int) ($node['pos_author_id'] ?? 0),
73 (int) $node['pos_display_user_id'],
74 (string) $node['pos_usr_alias'],
75 (string) $node['import_name']
76 ));
77 }
78
79 public function getChildsOfNode($a_parent_node_id): array
80 {
81 if ($this->preloaded) {
82 return $this->preloaded_children[$a_parent_node_id] ?? [];
83 }
84
85 return $this->thread->getNestedSetPostChildren($a_parent_node_id, 1);
86 }
87
88 protected function preloadChilds(): void
89 {
90 $this->preloaded_children = [];
91
92 $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
93
94 array_walk($children, function ($node, $key): void {
95 if (!array_key_exists((int) $node['pos_pk'], $this->preloaded_children)) {
96 $this->preloaded_children[(int) $node['pos_pk']] = [];
97 }
98
99 $this->preloaded_children[(int) $node['parent_pos']][$node['pos_pk']] = $node;
100 });
101
102 $this->preloaded = true;
103 }
104
105 public function getChildren($record, $environment = null): array
106 {
107 return $this->getChildsOfNode((int) $record['pos_pk']);
108 }
109
110 public function getTreeLabel(): string
111 {
112 return $this->lng->txt("frm_posts");
113 }
114
115 public function getTreeComponent(): Tree
116 {
117 $rootNode = [
118 [
119 'pos_pk' => $this->root_node->getId(),
120 'pos_subject' => $this->root_node->getSubject(),
121 'pos_author_id' => $this->root_node->getPosAuthorId(),
122 'pos_display_user_id' => $this->root_node->getDisplayUserId(),
123 'pos_usr_alias' => $this->root_node->getUserAlias(),
124 'pos_date' => $this->root_node->getCreateDate(),
125 'import_name' => $this->root_node->getImportName(),
126 'post_read' => $this->root_node->isPostRead()
127 ]
128 ];
129
130 return $this->ui->factory()->tree()
131 ->expandable($this->getTreeLabel(), $this)
132 ->withData($rootNode)
133 ->withHighlightOnNodeClick(false);
134 }
135
136 protected function createNode(
137 \ILIAS\UI\Component\Tree\Node\Factory $factory,
138 $record
139 ): \ILIAS\UI\Component\Tree\Node\Node {
140 $nodeIconPath = $this->getNodeIcon($record);
141
142 $icon = null;
143 if ($nodeIconPath !== '') {
144 $icon = $this->ui
145 ->factory()
146 ->symbol()
147 ->icon()
148 ->custom($nodeIconPath, $this->getNodeIconAlt($record));
149 }
150
151 if ((int) $record['pos_pk'] === $this->root_node->getId()) {
152 $node = $factory->simple($this->getNodeContent($record), $icon);
153 } else {
154 $authorInfo = $this->getAuthorInformationByNode($record);
155 $creationDate = ilDatePresentation::formatDate(new ilDateTime($record['pos_date'], IL_CAL_DATETIME));
156 $bylineString = $authorInfo->getAuthorShortName() . ', ' . $creationDate;
157
158 $node = $factory->bylined($this->getNodeContent($record), $bylineString, $icon);
159 }
160
161 return $node;
162 }
163
164 protected function getNodeStateToggleCmdClasses($record): array
165 {
166 return [
167 ilRepositoryGUI::class,
168 ilObjForumGUI::class,
169 ];
170 }
171
172 public function getNodeId($a_node): int
173 {
174 return (isset($a_node['pos_pk']) ? (int) $a_node['pos_pk'] : 0);
175 }
176
177 public function getNodeIcon($a_node): string
178 {
179 if ($this->getRootNodeId() === (int) $a_node['pos_pk']) {
180 return ilObject::_getIcon(0, 'tiny', 'frm');
181 }
182
183 return $this->getAuthorInformationByNode($a_node)->getProfilePicture();
184 }
185
186 public function getNodeHref($a_node): string
187 {
188 if ($this->getRootNodeId() === (int) $a_node['pos_pk']) {
189 return '';
190 }
191
192 $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
193
194 if (isset($a_node['counter']) && $a_node['counter'] > 0) {
195 $page = (int) floor(($a_node['counter'] - 1) / $this->max_entries);
196 $this->ctrl->setParameter($this->parent_obj, 'page', $page);
197 }
198
199 if (isset($a_node['post_read']) && $a_node['post_read']) {
200 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
201 $url = $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, (string) $a_node['pos_pk']);
202 } else {
203 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $a_node['pos_pk']);
204 $url = $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', (string) $a_node['pos_pk']);
205 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
206 }
207
208 $this->ctrl->setParameter($this->parent_obj, 'page', null);
209
210 return $url;
211 }
212
213 public function getNodeContent($a_node): string
214 {
215 return $a_node['pos_subject'];
216 }
217}
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour)
Class ilForumExplorerGUI.
getNodeContent($a_node)
Get content of a node.
getNodeHref($a_node)
Get href for node.
getAuthorInformationByNode(array $node)
getChildsOfNode($a_parent_node_id)
Get childs of node.
getNodeStateToggleCmdClasses($record)
Should return an array of ilCtrl-enabled command classes which should be used to build the URL for th...
__construct(string $a_expl_id, object $a_parent_obj, string $a_parent_cmd, ilForumTopic $thread, ilForumPost $root)
getNodeIcon($a_node)
Get node icon path.
getChildren($record, $environment=null)
Get a list of records (that list can also be empty).
createNode(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record)
Creates at tree node, can be overwritten in derivatives if another node type should be used.
getNodeId($a_node)
Get id for node.
Class Forum core functions for forum.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
Explorer class that works on tree objects (Services/Tree)
getNodeIconAlt($a_node)
Get node icon alt attribute.
global $DIC
Definition: feed.php:28
This describes a Tree Control.
Definition: Tree.php:29
$factory
Definition: metadata.php:75
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$url