ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLocatorGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 protected ?int $ref_id = null;
30 protected bool $textonly;
31 protected bool $offline = false;
32 protected ilTree $tree;
33 protected ilCtrl $ctrl;
37 protected ilLanguage $lng;
38 protected array $entries = [];
39 protected bool $initialised = false;
40
41 public function __construct()
42 {
43 $this->entries = array();
44 $this->offline = false;
45 $this->setTextOnly(false);
46 }
47
48 protected function init(): void
49 {
50 global $DIC;
51
52 if ($this->initialised) {
53 return;
54 }
55 $this->tree = $DIC->repositoryTree();
56 $this->ctrl = $DIC->ctrl();
57 $this->obj_definition = $DIC["objDefinition"];
58 $this->access = $DIC->access();
59 $this->settings = $DIC->settings();
60 $lng = $DIC->language();
61
62 $this->lng = $lng;
63 $this->ref_id = ($DIC->http()->wrapper()->query()->has("ref_id"))
64 ? $DIC->http()->wrapper()->query()->retrieve("ref_id", $DIC->refinery()->kindlyTo()->int())
65 : null;
66 if ($this->ref_id == 0) {
67 $this->ref_id = null;
68 }
69 }
70
71 public function setTextOnly(bool $a_textonly): void
72 {
73 $this->textonly = $a_textonly;
74 }
75
76 public function setOffline(bool $a_offline): void
77 {
78 $this->offline = $a_offline;
79 }
80
81 public function getOffline(): bool
82 {
83 return $this->offline;
84 }
85
86 public function getTextOnly(): bool
87 {
88 return $this->textonly;
89 }
90
96 public function addRepositoryItems(int $a_ref_id = 0): void
97 {
98 $this->init();
99 $setting = $this->settings;
101 $ilCtrl = $this->ctrl;
102
103 if ($a_ref_id == 0) {
104 $a_ref_id = $this->ref_id;
105 }
106
107 $a_start = ROOT_FOLDER_ID;
108 if ($a_ref_id > 0) {
109 $path = $tree->getPathFull($a_ref_id, $a_start);
110
111 // check if path contains crs
112 $crs_ref_id = 0;
113 foreach ($path as $k => $v) {
114 if ($v["type"] == "crs") {
115 $crs_ref_id = $v["child"];
116 }
117 }
118 if (!$setting->get("rep_breadcr_crs")) { // no overwrite
119 $crs_ref_id = 0;
120 } elseif ($setting->get("rep_breadcr_crs_overwrite")) { // overwrite
121 // course wants full path
123 $crs_ref_id = 0;
124 }
125 // course wants default and default wants full path
126 if (ilContainer::_lookupContainerSetting(ilObject::_lookupObjId($crs_ref_id), "rep_breacrumb") == ilObjCourseGUI::BREADCRUMB_DEFAULT && !$setting->get("rep_breadcr_crs_default")) {
127 $crs_ref_id = 0;
128 }
129 }
130
131 // add item for each node on path
132 foreach ($path as $key => $row) {
133 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp", "prg", "lso"))) {
134 continue;
135 }
136 if ($crs_ref_id > 0 && $row["child"] == $crs_ref_id) {
137 $crs_ref_id = 0;
138 }
139 if ($crs_ref_id > 0) {
140 continue;
141 }
142
143 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
144 $row["title"] = $this->lng->txt("repository");
145 }
146
147 $this->addItem(
148 $row["title"],
149 ilLink::_getLink((int) $row["child"]),
150 ilFrameTargetInfo::_getFrame("MainContent"),
151 $row["child"]
152 );
153 }
154 }
155 }
156
161 public function addAdministrationItems(int $a_ref_id = 0): void
162 {
163 $this->init();
164 $tree = $this->tree;
165 $ilCtrl = $this->ctrl;
166 $objDefinition = $this->obj_definition;
168
169 if ($a_ref_id == 0) {
170 $a_ref_id = $this->ref_id;
171 }
172
173 if ($a_ref_id > 0) {
174 $path = $tree->getPathFull($a_ref_id);
175
176 // add item for each node on path
177 foreach ($path as $key => $row) {
178 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp"))) {
179 continue;
180 }
181
182 if ($row["child"] == ROOT_FOLDER_ID) {
183 $row["title"] = $lng->txt("repository");
184 }
185
186 $class_name = $objDefinition->getClassName($row["type"]);
187 $class = strtolower("ilObj" . $class_name . "GUI");
188 $ilCtrl->setParameterByClass($class, "ref_id", $row["child"]);
189 $this->addItem(
190 $row["title"],
191 $ilCtrl->getLinkTargetByClass($class, "view"),
192 "",
193 $row["child"]
194 );
195 }
196 }
197 }
198
199 public function addContextItems(
200 int $a_ref_id,
201 bool $a_omit_node = false,
202 int $a_stop = 0
203 ): void {
204 $this->init();
206
207 if ($a_ref_id > 0) {
208 $path = $tree->getPathFull($a_ref_id);
209
210 // we want to show the full path, from the major container to the item
211 // (folders are not! treated as containers here), at least one parent item
212 $r_path = array_reverse($path);
213 $first = "";
214 $omit = array();
215 $do_omit = false;
216 foreach ($r_path as $key => $row) {
217 if ($first == "") {
218 if (in_array($row["type"], array("root", "cat", "grp", "crs")) &&
219 $row["child"] != $a_ref_id) {
220 $first = $row["child"];
221 }
222 }
223 if ($a_stop == $row["child"]) {
224 $do_omit = true;
225 }
226 $omit[$row["child"]] = $do_omit;
227 }
228
229 $add_it = false;
230 foreach ($path as $key => $row) {
231 if ($first == $row["child"]) {
232 $add_it = true;
233 }
234
235
236 if ($add_it && !$omit[$row["child"]] &&
237 (!$a_omit_node || ($row["child"] != $a_ref_id))) {
238 //echo "-".ilObject::_lookupTitle($row["obj_id"])."-";
239 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
240 $row["title"] = $this->lng->txt("repository");
241 }
242 $this->addItem(
243 $row["title"],
244 "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" . $row["type"] . "_" . $row["child"],
245 "_top",
246 $row["child"],
247 $row["type"]
248 );
249 }
250 }
251 }
252 }
253
254 public function addItem(
255 string $a_title,
256 string $a_link,
257 string $a_frame = "",
258 int $a_ref_id = 0,
259 ?string $type = null
260 ): void {
262 global $DIC;
263 $ltiview = $DIC['lti'];
264
265 $this->init();
266
267 $ilAccess = $this->access;
268
269 if ($a_ref_id > 0 && !$ilAccess->checkAccess("visible", "", $a_ref_id)) {
270 return;
271 }
272 // LTI
273 if ($ltiview->isActive()) {
274 $a_frame = "_self";
275 }
276 $this->entries[] = array(
277 "title" => $DIC->refinery()->encode()->htmlSpecialCharsAsEntities()->transform(
278 $a_title
279 ),
280 "link" => $a_link,
281 "frame" => $a_frame,
282 "ref_id" => $a_ref_id,
283 "type" => $type
284 );
285 }
286
287 public function clearItems(): void
288 {
289 $this->entries = array();
290 }
291
292 public function getItems(): array
293 {
294 return $this->entries;
295 }
296
297 public function getHTML(): string
298 {
299 $this->init();
300 $lng = $this->lng;
301 $icon_path = "";
302
303 if ($this->getTextOnly()) {
304 $loc_tpl = new ilTemplate("tpl.locator_text_only.html", true, true, "components/ILIAS/Locator");
305 } else {
306 $loc_tpl = new ilTemplate("tpl.locator.html", true, true, "components/ILIAS/Locator");
307 }
308
309 $items = $this->getItems();
310 $first = true;
311 if (count($items) > 0) {
312 foreach ($items as $item) {
313 if (!$first) {
314 $loc_tpl->touchBlock("locator_separator_prefix");
315 }
316
317 if ($item["ref_id"] > 0) {
318 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
319 $type = ilObject::_lookupType($obj_id);
320
321 if (!$this->getTextOnly()) {
322 $icon_path = ilObject::_getIcon(
323 $obj_id,
324 "tiny",
325 $type,
326 $this->getOffline()
327 );
328 }
329
330 $loc_tpl->setCurrentBlock("locator_img");
331 $loc_tpl->setVariable("IMG_SRC", $icon_path);
332 $loc_tpl->setVariable(
333 "IMG_ALT",
334 $lng->txt("obj_" . $type)
335 );
336 $loc_tpl->parseCurrentBlock();
337 }
338
339 $loc_tpl->setCurrentBlock("locator_item");
340 if ($item["link"] != "") {
341 $loc_tpl->setVariable("LINK_ITEM", $item["link"]);
342 if ($item["frame"] != "") {
343 $loc_tpl->setVariable("LINK_TARGET", ' target="' . $item["frame"] . '" ');
344 }
345 $loc_tpl->setVariable("ITEM", $item["title"]);
346 } else {
347 $loc_tpl->setVariable("PREFIX", $item["title"]);
348 }
349 $loc_tpl->parseCurrentBlock();
350
351 $first = false;
352 }
353 } else {
354 // $loc_tpl->setVariable("NOITEM", "&nbsp;");
355 // $loc_tpl->touchBlock("locator");
356 }
357
358 return trim($loc_tpl->get());
359 }
360
364 public function getTextVersion(): string
365 {
366 $this->init();
367 $items = $this->getItems();
368 $first = true;
369
370 $str = "";
371 foreach ($items as $item) {
372 if (!$first) {
373 $str .= " > ";
374 }
375
376 $str .= $item["title"];
377
378 $first = false;
379 }
380
381 return $str;
382 }
383}
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
Class ilCtrl provides processing control methods.
static _getFrame(string $a_class)
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOffline(bool $a_offline)
addContextItems(int $a_ref_id, bool $a_omit_node=false, int $a_stop=0)
setTextOnly(bool $a_textonly)
ilAccessHandler $access
addRepositoryItems(int $a_ref_id=0)
ilObjectDefinition $obj_definition
addAdministrationItems(int $a_ref_id=0)
add administration tree items
getTextVersion()
Get text version.
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)
ILIAS Setting Class.
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...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
const CLIENT_ID
Definition: constants.php:41
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$path
Definition: ltiservices.php:30
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26