ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLocatorGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
20 protected $tree;
21
25 protected $ctrl;
26
30 protected $obj_definition;
31
35 protected $access;
36
40 protected $settings;
41
42 protected $lng;
43 protected $entries;
44
49 public function __construct()
50 {
51 global $DIC;
52
53 $this->tree = $DIC->repositoryTree();
54 $this->ctrl = $DIC->ctrl();
55 $this->obj_definition = $DIC["objDefinition"];
56 $this->access = $DIC->access();
57 $this->settings = $DIC->settings();
58 $lng = $DIC->language();
59
60 $this->lng = $lng;
61 $this->entries = array();
62 $this->setTextOnly(false);
63 $this->offline = false;
64 }
65
71 public function setTextOnly($a_textonly)
72 {
73 $this->textonly = $a_textonly;
74 }
75
76 public function setOffline($a_offline)
77 {
78 $this->offline = $a_offline;
79 }
80
81 public function getOffline()
82 {
83 return $this->offline;
84 }
85
91 public function getTextOnly()
92 {
93 return $this->textonly;
94 }
95
102 public function addRepositoryItems($a_ref_id = 0)
103 {
104 $setting = $this->settings;
106 $ilCtrl = $this->ctrl;
107
108 if ($a_ref_id == 0) {
109 $a_ref_id = $_GET["ref_id"];
110 }
111
112 $a_start = ROOT_FOLDER_ID;
113 if ($a_ref_id > 0) {
114 $path = $tree->getPathFull($a_ref_id, $a_start);
115
116 // check if path contains crs
117 $crs_ref_id = 0;
118 foreach ($path as $k => $v) {
119 if ($v["type"] == "crs") {
120 $crs_ref_id = $v["child"];
121 }
122 }
123 if (!$setting->get("rep_breadcr_crs")) { // no overwrite
124 $crs_ref_id = 0;
125 } elseif ($setting->get("rep_breadcr_crs_overwrite")) { // overwrite
126 // course wants full path
128 $crs_ref_id = 0;
129 }
130 // course wants default and default wants full path
131 if (ilContainer::_lookupContainerSetting(ilObject::_lookupObjId($crs_ref_id), "rep_breacrumb") == ilObjCourseGUI::BREADCRUMB_DEFAULT && !$setting->get("rep_breadcr_crs_default")) {
132 $crs_ref_id = 0;
133 }
134 }
135
136 // add item for each node on path
137 foreach ((array) $path as $key => $row) {
138 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp", "prg", "lso"))) {
139 continue;
140 }
141 if ($crs_ref_id > 0 && $row["child"] == $crs_ref_id) {
142 $crs_ref_id = 0;
143 }
144 if ($crs_ref_id > 0) {
145 continue;
146 }
147
148 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
149 $row["title"] = $this->lng->txt("repository");
150 }
151
152 $this->addItem(
153 $row["title"],
154 ilLink::_getLink($row["child"]),
155 ilFrameTargetInfo::_getFrame("MainContent"),
156 $row["child"]
157 );
158 }
159 }
160 }
161
168 public function addAdministrationItems($a_ref_id = 0)
169 {
171 $ilCtrl = $this->ctrl;
172 $objDefinition = $this->obj_definition;
174
175 if ($a_ref_id == 0) {
176 $a_ref_id = $_GET["ref_id"];
177 }
178
179 if ($a_ref_id > 0) {
180 $path = $tree->getPathFull($a_ref_id);
181
182 // add item for each node on path
183 foreach ($path as $key => $row) {
184 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp"))) {
185 continue;
186 }
187
188 if ($row["child"] == ROOT_FOLDER_ID) {
189 $row["title"] = $lng->txt("repository");
190 }
191
192 $class_name = $objDefinition->getClassName($row["type"]);
193 $class = strtolower("ilObj" . $class_name . "GUI");
194 $ilCtrl->setParameterByClass($class, "ref_id", $row["child"]);
195 $this->addItem(
196 $row["title"],
197 $ilCtrl->getLinkTargetbyClass($class, "view"),
198 "",
199 $row["child"]
200 );
201 }
202 }
203 }
204
205 public function addContextItems($a_ref_id, $a_omit_node = false, $a_stop = 0)
206 {
208
209 if ($a_ref_id > 0) {
210 $path = $tree->getPathFull($a_ref_id);
211
212 // we want to show the full path, from the major container to the item
213 // (folders are not! treated as containers here), at least one parent item
214 $r_path = array_reverse($path);
215 $first = "";
216 $omit = array();
217 $do_omit = false;
218 foreach ($r_path as $key => $row) {
219 if ($first == "") {
220 if (in_array($row["type"], array("root", "cat", "grp", "crs")) &&
221 $row["child"] != $a_ref_id) {
222 $first = $row["child"];
223 }
224 }
225 if ($a_stop == $row["child"]) {
226 $do_omit = true;
227 }
228 $omit[$row["child"]] = $do_omit;
229 }
230
231 $add_it = false;
232 foreach ($path as $key => $row) {
233 if ($first == $row["child"]) {
234 $add_it = true;
235 }
236
237
238 if ($add_it && !$omit[$row["child"]] &&
239 (!$a_omit_node || ($row["child"] != $a_ref_id))) {
240 //echo "-".ilObject::_lookupTitle($row["obj_id"])."-";
241 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
242 $row["title"] = $this->lng->txt("repository");
243 }
244 $this->addItem(
245 $row["title"],
246 "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" . $row["type"] . "_" . $row["child"],
247 "_top",
248 $row["child"],
249 $row["type"]
250 );
251 }
252 }
253 }
254 }
255
263 public function addItem($a_title, $a_link, $a_frame = "", $a_ref_id = 0, $type = null)
264 {
265 // LTI
266 global $DIC;
267 $ltiview = $DIC['lti'];
268
269 $ilAccess = $this->access;
270
271 if ($a_ref_id > 0 && !$ilAccess->checkAccess("visible", "", $a_ref_id)) {
272 return;
273 }
274 // LTI
275 if ($ltiview->isActive()) {
276 $a_frame = "_self";
277 }
278 $this->entries[] = array(
279 "title" => strip_tags(
280 $a_title,
282 ),
283 "link" => $a_link,
284 "frame" => $a_frame,
285 "ref_id" => $a_ref_id,
286 "type" => $type
287 );
288 }
289
293 public function clearItems()
294 {
295 $this->entries = array();
296 }
297
301 public function getItems()
302 {
303 return $this->entries;
304 }
305
309 public function getHTML()
310 {
313
314 if ($this->getTextOnly()) {
315 $loc_tpl = new ilTemplate("tpl.locator_text_only.html", true, true, "Services/Locator");
316 } else {
317 $loc_tpl = new ilTemplate("tpl.locator.html", true, true, "Services/Locator");
318 }
319
320 $items = $this->getItems();
321 $first = true;
322
323 if (is_array($items)) {
324 foreach ($items as $item) {
325 if (!$first) {
326 $loc_tpl->touchBlock("locator_separator_prefix");
327 }
328
329 if ($item["ref_id"] > 0) {
330 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
331 $type = ilObject::_lookupType($obj_id);
332
333 if (!$this->getTextOnly()) {
334 $icon_path = ilObject::_getIcon(
335 $obj_id,
336 "tiny",
337 $type,
338 $this->getOffline()
339 );
340 }
341
342 $loc_tpl->setCurrentBlock("locator_img");
343 $loc_tpl->setVariable("IMG_SRC", $icon_path);
344 $loc_tpl->setVariable(
345 "IMG_ALT",
346 $lng->txt("obj_" . $type)
347 );
348 $loc_tpl->parseCurrentBlock();
349 }
350
351 $loc_tpl->setCurrentBlock("locator_item");
352 if ($item["link"] != "") {
353 $loc_tpl->setVariable("LINK_ITEM", $item["link"]);
354 if ($item["frame"] != "") {
355 $loc_tpl->setVariable("LINK_TARGET", ' target="' . $item["frame"] . '" ');
356 }
357 $loc_tpl->setVariable("ITEM", $item["title"]);
358 } else {
359 $loc_tpl->setVariable("PREFIX", $item["title"]);
360 }
361 $loc_tpl->parseCurrentBlock();
362
363 $first = false;
364 }
365 } else {
366 $loc_tpl->setVariable("NOITEM", "&nbsp;");
367 $loc_tpl->touchBlock("locator");
368 }
369 $loc_tpl->setVariable("TXT_BREADCRUMBS", $lng->txt("breadcrumb_navigation"));
370
371 return trim($loc_tpl->get());
372 }
373
377 public function getTextVersion()
378 {
381
382 $items = $this->getItems();
383 $first = true;
384
385 $str = "";
386 if (is_array($items)) {
387 foreach ($items as $item) {
388 if (!$first) {
389 $str .= " > ";
390 }
391
392 $str .= $item["title"];
393
394 $first = false;
395 }
396 }
397
398 return $str;
399 }
400} // END class.LocatorGUI
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _getFrame($a_class, $a_type='')
Get content frame name.
locator handling class
addContextItems($a_ref_id, $a_omit_node=false, $a_stop=0)
getTextOnly()
Get Only text, no HTML.
__construct()
Constructor.
addRepositoryItems($a_ref_id=0)
add repository item
clearItems()
Clear all Items.
addAdministrationItems($a_ref_id=0)
add administration tree items
getItems()
Get all locator entries.
setTextOnly($a_textonly)
Set Only text, no HTML.
getHTML()
Get locator HTML.
addItem($a_title, $a_link, $a_frame="", $a_ref_id=0, $type=null)
add locator item
setOffline($a_offline)
getTextVersion()
Get text version.
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
static _lookupObjId($a_id)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
special template class to simplify handling of ITX/PEAR
const CLIENT_ID
Definition: constants.php:39
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
global $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2