ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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;
36
40 public function __construct()
41 {
42 global $DIC;
43
44 $this->startnode = (int) ROOT_FOLDER_ID;
45 $this->endnode = (int) ROOT_FOLDER_ID;
46 $this->tree = $DIC->repositoryTree();
47 $this->lng = $DIC->language();
48 $this->ctrl = $DIC['ilCtrl'];
49 $this->objectDefinition = $DIC['objDefinition'];
50 $this->refinery = $DIC->refinery();
51 }
52
59 public function getPath(int $a_startnode, int $a_endnode): string
60 {
61 $this->startnode = $a_startnode;
62 $this->endnode = $a_endnode;
63
64 return $this->getHTML();
65 }
66
72 public function enableTextOnly(bool $a_status): void
73 {
74 $this->textOnly = $a_status;
75 }
76
77 public function textOnly(): bool
78 {
79 return $this->textOnly;
80 }
81
85 public function enableHideLeaf(bool $a_status): void
86 {
87 $this->hide_leaf = $a_status;
88 }
89
90 public function hideLeaf(): bool
91 {
92 return $this->hide_leaf;
93 }
94
95 public function setUseImages(bool $a_status): void
96 {
97 $this->useImages = $a_status;
98 }
99
104 public function getUseImages(): bool
105 {
106 return $this->useImages;
107 }
108
112 public function enableDisplayCut(bool $a_status): void
113 {
114 $this->display_cut = $a_status;
115 }
116
120 public function displayCut(): bool
121 {
122 return $this->display_cut;
123 }
124
128 protected function getHTML(): string
129 {
130 if ($this->textOnly()) {
131 $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "components/ILIAS/Locator");
132
133 $first = true;
134
135 // Display cut
136 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
137 $tpl->setCurrentBlock('locator_item');
138 $tpl->setVariable('ITEM', "...");
139 $tpl->parseCurrentBlock();
140
141 $first = false;
142 }
143
144 foreach ($this->getPathIds() as $ref_id) {
146 $title = $this->buildTitle($obj_id);
147
148 if ($first) {
149 if ($ref_id == ROOT_FOLDER_ID) {
150 $title = $this->lng->txt('repository');
151 }
152 } else {
153 $tpl->touchBlock('locator_separator_prefix');
154 }
155
156 $tpl->setCurrentBlock('locator_item');
157 $tpl->setVariable('ITEM', $title);
158 $tpl->parseCurrentBlock();
159 $first = false;
160 }
161 return $tpl->get();
162 } else {
163 // With images and links
164
165 $tpl = new ilTemplate('tpl.locator.html', true, true, 'components/ILIAS/Locator');
166
167 $first = true;
168
169 // Display cut
170 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
171 $tpl->setCurrentBlock('locator_item');
172 $tpl->setVariable('ITEM', "...");
173 $tpl->parseCurrentBlock();
174
175 $first = false;
176 }
177
178 foreach ($this->getPathIds() as $ref_id) {
180 $title = $this->buildTitle($obj_id);
181 $type = ilObject::_lookupType($obj_id);
182
183 if ($first) {
184 if ($ref_id == ROOT_FOLDER_ID) {
185 $title = $this->lng->txt('repository');
186 }
187 } else {
188 $tpl->touchBlock('locator_separator_prefix');
189 }
190 if ($this->getUseImages()) {
191 $tpl->setCurrentBlock('locator_img');
192 $tpl->setVariable('IMG_SRC', ilObject::_getIcon($obj_id, "small", $type));
193 $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
194 $tpl->parseCurrentBlock();
195 }
196
197 if (!$this->tree->isDeleted($ref_id)) {
198 $tpl->setCurrentBlock('locator_item');
199 $tpl->setVariable('LINK_ITEM', $this->buildLink($ref_id, $type));
200 $tpl->setVariable('ITEM', $title);
201 $tpl->parseCurrentBlock();
202 } else {
203 $tpl->setCurrentBlock('locator_item');
204 $tpl->setVariable('ITEM_READ_ONLY', $title);
205 $tpl->parseCurrentBlock();
206 }
207
208 $first = false;
209 }
210 $tpl->setVariable("TXT_BREADCRUMBS", $this->lng->txt("breadcrumb_navigation"));
211 return $tpl->get();
212 }
213 }
214
215 protected function buildTitle(int $a_obj_id): string
216 {
217 $type = ilObject::_lookupType($a_obj_id);
218 if ($this->objectDefinition->isAdministrationObject($type)) {
219 return $this->lng->txt('obj_' . $type);
220 }
221 return ilObject::_lookupTitle($a_obj_id);
222 }
223
224 protected function buildLink(int $ref_id, string $type): string
225 {
226 if ($this->objectDefinition->isAdministrationObject($type)) {
227 $current_parameters = $this->ctrl->getParameterArrayByClass(ilAdministrationGUI::class);
228 $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $ref_id);
229 $link = $this->ctrl->getLinkTargetByClass(ilAdministrationGUI::class, 'jump');
230 $this->ctrl->clearParameterByClass(ilAdministrationGUI::class, 'ref_id');
231 if (isset($current_parameters['ref_id'])) {
232 $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $current_parameters['ref_id']);
233 }
234 return $link;
235 }
236 return $this->refinery->encode()->htmlAttributeValue()->transform(
237 ilLink::_getLink($ref_id, $type)
238 );
239 }
240
244 protected function getPathIds(): array
245 {
246 $path = $this->tree->getPathId($this->endnode, $this->startnode);
247 if ($this->hideLeaf() && count($path)) {
248 unset($path[count($path) - 1]);
249 }
250 return $path;
251 }
252}
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)
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
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