ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumExplorerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
29 private readonly int $max_entries;
31 private array $preloaded_children = [];
32
34 private array $authorInformation = [];
35
36 public function __construct(
37 string $a_expl_id,
38 object $a_parent_obj,
39 string $a_parent_cmd,
40 private readonly ilForumTopic $thread,
41 private readonly ilForumPost $root_node
42 ) {
43 global $DIC;
44
45 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $DIC->repositoryTree());
46
47 $this->setSkipRootNode(false);
48 $this->setAjax(false);
49 $this->setPreloadChilds(true);
50
51 $this->ctrl->setParameter($this->parent_obj, 'thr_pk', $this->thread->getId());
52
53 $frm = new ilForum();
54 $this->max_entries = $frm->getPageHits();
55
56 $this->setNodeOpen($this->root_node->getId());
57 }
58
59 private function getRootNodeId(): int
60 {
61 return $this->root_node->getId();
62 }
63
65 {
66 return $this->authorInformation[(int) $node['pos_pk']] ?? ($this->authorInformation[(int) $node['pos_pk']] = new ilForumAuthorInformation(
67 (int) ($node['pos_author_id'] ?? 0),
68 (int) $node['pos_display_user_id'],
69 (string) $node['pos_usr_alias'],
70 (string) $node['import_name']
71 ));
72 }
73
74 public function getChildsOfNode($a_parent_node_id): array
75 {
76 if ($this->preloaded) {
77 return $this->preloaded_children[$a_parent_node_id] ?? [];
78 }
79
80 return $this->thread->getNestedSetPostChildren($a_parent_node_id, 1);
81 }
82
83 protected function preloadChilds(): void
84 {
85 $this->preloaded_children = [];
86
87 $children = $this->thread->getNestedSetPostChildren($this->root_node->getId());
88
89 array_walk($children, function ($node, $key): void {
90 if (!array_key_exists((int) $node['pos_pk'], $this->preloaded_children)) {
91 $this->preloaded_children[(int) $node['pos_pk']] = [];
92 }
93
94 $this->preloaded_children[(int) $node['parent_pos']][$node['pos_pk']] = $node;
95 });
96
97 $this->preloaded = true;
98 }
99
100 public function getChildren($record, $environment = null): array
101 {
102 return $this->getChildsOfNode((int) $record['pos_pk']);
103 }
104
105 public function getTreeLabel(): string
106 {
107 return $this->lng->txt("frm_posts");
108 }
109
110 public function getTreeComponent(): Tree
111 {
112 $rootNode = [
113 [
114 'pos_pk' => $this->root_node->getId(),
115 'pos_subject' => $this->root_node->getSubject(),
116 'pos_author_id' => $this->root_node->getPosAuthorId(),
117 'pos_display_user_id' => $this->root_node->getDisplayUserId(),
118 'pos_usr_alias' => $this->root_node->getUserAlias(),
119 'pos_date' => $this->root_node->getCreateDate(),
120 'import_name' => $this->root_node->getImportName(),
121 'post_read' => $this->root_node->isPostRead()
122 ]
123 ];
124
125 return $this->ui->factory()->tree()
126 ->expandable($this->getTreeLabel(), $this)
127 ->withData($rootNode)
128 ->withHighlightOnNodeClick(false);
129 }
130
131 protected function createNode(
132 \ILIAS\UI\Component\Tree\Node\Factory $factory,
133 $record
134 ): \ILIAS\UI\Component\Tree\Node\Node {
135 $nodeIconPath = $this->getNodeIcon($record);
136
137 $icon = null;
138 if ($nodeIconPath !== '') {
139 $icon = $this->ui
140 ->factory()
141 ->symbol()
142 ->icon()
143 ->custom($nodeIconPath, $this->getNodeIconAlt($record));
144 }
145
146 if ((int) $record['pos_pk'] === $this->root_node->getId()) {
147 $node = $factory->simple($this->getNodeContent($record), $icon);
148 } else {
149 $authorInfo = $this->getAuthorInformationByNode($record);
150 $creationDate = ilDatePresentation::formatDate(new ilDateTime($record['pos_date'], IL_CAL_DATETIME));
151 $bylineString = $authorInfo->getAuthorShortName() . ', ' . $creationDate;
152
153 $node = $factory->bylined($this->getNodeContent($record), $bylineString, $icon);
154 }
155
156 return $node;
157 }
158
159 protected function getNodeStateToggleCmdClasses($record): array
160 {
161 return [
162 ilRepositoryGUI::class,
163 ilObjForumGUI::class,
164 ];
165 }
166
167 public function getNodeId($a_node): int
168 {
169 return (isset($a_node['pos_pk']) ? (int) $a_node['pos_pk'] : 0);
170 }
171
172 public function getNodeIcon($a_node): string
173 {
174 if ($this->getRootNodeId() === (int) $a_node['pos_pk']) {
175 return ilObject::_getIcon(0, 'tiny', 'frm');
176 }
177
178 return $this->getAuthorInformationByNode($a_node)->getProfilePicture();
179 }
180
181 public function getNodeHref($a_node): string
182 {
183 if ($this->getRootNodeId() === (int) $a_node['pos_pk']) {
184 return '';
185 }
186
187 $this->ctrl->setParameter($this->parent_obj, 'backurl', null);
188
189 if (isset($a_node['counter']) && $a_node['counter'] > 0) {
190 $page = (int) floor(($a_node['counter'] - 1) / $this->max_entries);
191 $this->ctrl->setParameter($this->parent_obj, 'page', $page);
192 }
193
194 if (isset($a_node['post_read']) && $a_node['post_read']) {
195 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
196 $url = $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd, (string) $a_node['pos_pk']);
197 } else {
198 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', $a_node['pos_pk']);
199 $url = $this->ctrl->getLinkTarget($this->parent_obj, 'markPostRead', (string) $a_node['pos_pk']);
200 $this->ctrl->setParameter($this->parent_obj, 'pos_pk', null);
201 }
202
203 $this->ctrl->setParameter($this->parent_obj, 'page', null);
204
205 return $url;
206 }
207
208 public function getNodeContent($a_node): string
209 {
210 return $a_node['pos_subject'];
211 }
212}
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@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)
__construct(string $a_expl_id, object $a_parent_obj, string $a_parent_cmd, private readonly ilForumTopic $thread, private readonly ilForumPost $root_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...
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.
This describes a Tree Control.
Definition: Tree.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68