ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilPathGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private int $startnode;
24 private int $endnode;
25
26 private bool $textOnly = true;
27 private bool $useImages = false;
28 private bool $hide_leaf = true;
29 private bool $display_cut = false;
30
31 protected ilLanguage $lng;
32 protected ilTree $tree;
35 protected \ILIAS\Refinery\Factory $refinery;
37
41 public function __construct()
42 {
43 global $DIC;
44
45 $this->startnode = (int) ROOT_FOLDER_ID;
46 $this->endnode = (int) ROOT_FOLDER_ID;
47 $this->tree = $DIC->repositoryTree();
48 $this->lng = $DIC->language();
49 $this->ctrl = $DIC['ilCtrl'];
50 $this->objectDefinition = $DIC['objDefinition'];
51 $this->refinery = $DIC->refinery();
52 $this->access = $DIC->access();
53 }
54
61 public function getPath(int $a_startnode, int $a_endnode): string
62 {
63 $this->startnode = $a_startnode;
64 $this->endnode = $a_endnode;
65
66 return $this->getHTML();
67 }
68
74 public function enableTextOnly(bool $a_status): void
75 {
76 $this->textOnly = $a_status;
77 }
78
79 public function textOnly(): bool
80 {
81 return $this->textOnly;
82 }
83
87 public function enableHideLeaf(bool $a_status): void
88 {
89 $this->hide_leaf = $a_status;
90 }
91
92 public function hideLeaf(): bool
93 {
94 return $this->hide_leaf;
95 }
96
97 public function setUseImages(bool $a_status): void
98 {
99 $this->useImages = $a_status;
100 }
101
106 public function getUseImages(): bool
107 {
108 return $this->useImages;
109 }
110
114 public function enableDisplayCut(bool $a_status): void
115 {
116 $this->display_cut = $a_status;
117 }
118
122 public function displayCut(): bool
123 {
124 return $this->display_cut;
125 }
126
130 protected function getHTML(): string
131 {
132 if ($this->textOnly()) {
133 $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "components/ILIAS/Locator");
134
135 $first = true;
136
137 // Display cut
138 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
139 $tpl->setCurrentBlock('locator_item');
140 $tpl->setVariable('ITEM', "...");
141 $tpl->parseCurrentBlock();
142
143 $first = false;
144 }
145
146 foreach ($this->getPathIds() as $ref_id) {
148 $title = $this->buildTitle($obj_id);
149
150 if ($first) {
151 if ($ref_id == ROOT_FOLDER_ID) {
152 $title = $this->lng->txt('repository');
153 }
154 } else {
155 $tpl->touchBlock('locator_separator_prefix');
156 }
157
158 $tpl->setCurrentBlock('locator_item');
159 $tpl->setVariable('ITEM', $title);
160 $tpl->parseCurrentBlock();
161 $first = false;
162 }
163 return $tpl->get();
164 } else {
165 // With images and links
166
167 $tpl = new ilTemplate('tpl.locator.html', true, true, 'components/ILIAS/Locator');
168
169 $first = true;
170
171 // Display cut
172 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
173 $tpl->setCurrentBlock('locator_item');
174 $tpl->setVariable('ITEM', "...");
175 $tpl->parseCurrentBlock();
176
177 $first = false;
178 }
179
180 foreach ($this->getPathIds() as $ref_id) {
182 $title = $this->buildTitle($obj_id);
183 $type = ilObject::_lookupType($obj_id);
184
185 if ($first) {
186 if ($ref_id == ROOT_FOLDER_ID) {
187 $title = $this->lng->txt('repository');
188 }
189 } else {
190 $tpl->touchBlock('locator_separator_prefix');
191 }
192 if ($this->getUseImages()) {
193 $tpl->setCurrentBlock('locator_img');
194 $tpl->setVariable('IMG_SRC', ilObject::_getIcon($obj_id, "small", $type));
195 $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
196 $tpl->parseCurrentBlock();
197 }
198
199 if (!$this->tree->isDeleted($ref_id) &&
200 ($this->access->checkAccess('visible', '', (int) $ref_id)
201 || $this->access->checkAccess('read', '', (int) $ref_id))) {
202 $tpl->setCurrentBlock('locator_item');
203 $tpl->setVariable('LINK_ITEM', $this->buildLink($ref_id, $type));
204 $tpl->setVariable('ITEM', $title);
205 $tpl->parseCurrentBlock();
206 } else {
207 $tpl->setCurrentBlock('locator_item');
208 $tpl->setVariable('ITEM_READ_ONLY', $title);
209 $tpl->parseCurrentBlock();
210 }
211
212 $first = false;
213 }
214 $tpl->setVariable("TXT_BREADCRUMBS", $this->lng->txt("breadcrumb_navigation"));
215 return $tpl->get();
216 }
217 }
218
219 protected function buildTitle(int $a_obj_id): string
220 {
221 $type = ilObject::_lookupType($a_obj_id);
222 if ($this->objectDefinition->isAdministrationObject($type)) {
223 return $this->lng->txt('obj_' . $type);
224 }
225 return ilObject::_lookupTitle($a_obj_id);
226 }
227
228 protected function buildLink(int $ref_id, string $type): string
229 {
230 if ($this->objectDefinition->isAdministrationObject($type)) {
231 $current_parameters = $this->ctrl->getParameterArrayByClass(ilAdministrationGUI::class);
232 $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $ref_id);
233 $link = $this->ctrl->getLinkTargetByClass(ilAdministrationGUI::class, 'jump');
234 $this->ctrl->clearParameterByClass(ilAdministrationGUI::class, 'ref_id');
235 if (isset($current_parameters['ref_id'])) {
236 $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $current_parameters['ref_id']);
237 }
238 return $link;
239 }
240 return $this->refinery->encode()->htmlAttributeValue()->transform(
241 ilLink::_getLink($ref_id, $type)
242 );
243 }
244
248 protected function getPathIds(): array
249 {
250 $path = $this->tree->getPathId($this->endnode, $this->startnode);
251 if ($this->hideLeaf() && count($path)) {
252 unset($path[count($path) - 1]);
253 }
254 return $path;
255 }
256}
language handling
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
getUseImages()
get use images
getHTML()
get html
getPath(int $a_startnode, int $a_endnode)
get path
ilLanguage $lng
displayCut()
Display a cut with "...".
ILIAS Refinery Factory $refinery
setUseImages(bool $a_status)
ilAccessHandler $access
ilCtrlInterface $ctrl
enableDisplayCut(bool $a_status)
Display a cut with "...".
buildLink(int $ref_id, string $type)
__construct()
Constructor.
enableTextOnly(bool $a_status)
render path as text only
buildTitle(int $a_obj_id)
ilObjectDefinition $objectDefinition
enableHideLeaf(bool $a_status)
Hide leaf node in path.
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26