1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5* locator handling class 6* 7* This class supplies an implementation for the locator. 8* The locator will send its output to ist own frame, enabling more flexibility in 9* the design of the desktop. 10* 11* @author Arjan Ammerlaan <a.l.ammerlaan@web.de> 12* @version $Id$ 13* 14*/ 15class ilLocatorGUI 16{ 17 /** 18 * @var ilTree 19 */ 20 protected $tree; 21 22 /** 23 * @var ilCtrl 24 */ 25 protected $ctrl; 26 27 /** 28 * @var ilObjectDefinition 29 */ 30 protected $obj_definition; 31 32 /** 33 * @var ilAccessHandler 34 */ 35 protected $access; 36 37 /** 38 * @var ilSetting 39 */ 40 protected $settings; 41 42 protected $lng; 43 protected $entries; 44 45 /** 46 * Constructor 47 * 48 */ 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 66 /** 67 * Set Only text, no HTML. 68 * 69 * @param boolean $a_textonly Only text, no HTML 70 */ 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 86 /** 87 * Get Only text, no HTML. 88 * 89 * @return boolean Only text, no HTML 90 */ 91 public function getTextOnly() 92 { 93 return $this->textonly; 94 } 95 96 /** 97 * add repository item 98 * 99 * @param int $a_ref_id current ref id (optional); 100 * if empty $_GET["ref_id"] is used 101 */ 102 public function addRepositoryItems($a_ref_id = 0) 103 { 104 $setting = $this->settings; 105 $tree = $this->tree; 106 $ilCtrl = $this->ctrl; 107 108 if ($a_ref_id == 0) { 109 $a_ref_id = $_GET["ref_id"]; 110 } 111 112 include_once './Services/Container/classes/class.ilMemberViewSettings.php'; 113 if (ilMemberViewSettings::getInstance()->isActive() and $a_ref_id != ROOT_FOLDER_ID) { 114 $a_start = ilMemberViewSettings::getInstance()->getContainer(); 115 } else { 116 $a_start = ROOT_FOLDER_ID; 117 } 118 119 if ($a_ref_id > 0) { 120 $path = $tree->getPathFull($a_ref_id, $a_start); 121 122 // check if path contains crs 123 $crs_ref_id = 0; 124 foreach ($path as $k => $v) { 125 if ($v["type"] == "crs") { 126 $crs_ref_id = $v["child"]; 127 } 128 } 129 if (!$setting->get("rep_breadcr_crs")) { // no overwrite 130 $crs_ref_id = 0; 131 } elseif ($setting->get("rep_breadcr_crs_overwrite")) { // overwrite 132 // course wants full path 133 if (ilContainer::_lookupContainerSetting(ilObject::_lookupObjId($crs_ref_id), "rep_breacrumb") == ilObjCourseGUI::BREADCRUMB_FULL_PATH) { 134 $crs_ref_id = 0; 135 } 136 // course wants default and default wants full path 137 if (ilContainer::_lookupContainerSetting(ilObject::_lookupObjId($crs_ref_id), "rep_breacrumb") == ilObjCourseGUI::BREADCRUMB_DEFAULT && !$setting->get("rep_breadcr_crs_default")) { 138 $crs_ref_id = 0; 139 } 140 } 141 142 // add item for each node on path 143 foreach ((array) $path as $key => $row) { 144 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp", "prg", "lso"))) { 145 continue; 146 } 147 if ($crs_ref_id > 0 && $row["child"] == $crs_ref_id) { 148 $crs_ref_id = 0; 149 } 150 if ($crs_ref_id > 0) { 151 continue; 152 } 153 154 if ($row["title"] == "ILIAS" && $row["type"] == "root") { 155 $row["title"] = $this->lng->txt("repository"); 156 } 157 158 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $row["child"]); 159 $this->addItem( 160 $row["title"], 161 $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset"), 162 ilFrameTargetInfo::_getFrame("MainContent"), 163 $row["child"] 164 ); 165 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]); 166 } 167 } 168 } 169 170 /** 171 * add administration tree items 172 * 173 * @param int $a_ref_id current ref id (optional); 174 * if empty $_GET["ref_id"] is used 175 */ 176 public function addAdministrationItems($a_ref_id = 0) 177 { 178 $tree = $this->tree; 179 $ilCtrl = $this->ctrl; 180 $objDefinition = $this->obj_definition; 181 $lng = $this->lng; 182 183 if ($a_ref_id == 0) { 184 $a_ref_id = $_GET["ref_id"]; 185 } 186 187 if ($a_ref_id > 0) { 188 $path = $tree->getPathFull($a_ref_id); 189 190 // add item for each node on path 191 foreach ($path as $key => $row) { 192 if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp"))) { 193 continue; 194 } 195 196 if ($row["child"] == ROOT_FOLDER_ID) { 197 $row["title"] = $lng->txt("repository"); 198 } 199 200 $class_name = $objDefinition->getClassName($row["type"]); 201 $class = strtolower("ilObj" . $class_name . "GUI"); 202 $ilCtrl->setParameterByClass($class, "ref_id", $row["child"]); 203 $this->addItem( 204 $row["title"], 205 $ilCtrl->getLinkTargetbyClass($class, "view"), 206 "", 207 $row["child"] 208 ); 209 } 210 } 211 } 212 213 public function addContextItems($a_ref_id, $a_omit_node = false, $a_stop = 0) 214 { 215 $tree = $this->tree; 216 217 if ($a_ref_id > 0) { 218 $path = $tree->getPathFull($a_ref_id); 219 220 // we want to show the full path, from the major container to the item 221 // (folders are not! treated as containers here), at least one parent item 222 $r_path = array_reverse($path); 223 $first = ""; 224 $omit = array(); 225 $do_omit = false; 226 foreach ($r_path as $key => $row) { 227 if ($first == "") { 228 if (in_array($row["type"], array("root", "cat", "grp", "crs")) && 229 $row["child"] != $a_ref_id) { 230 $first = $row["child"]; 231 } 232 } 233 if ($a_stop == $row["child"]) { 234 $do_omit = true; 235 } 236 $omit[$row["child"]] = $do_omit; 237 } 238 239 $add_it = false; 240 foreach ($path as $key => $row) { 241 if ($first == $row["child"]) { 242 $add_it = true; 243 } 244 245 246 if ($add_it && !$omit[$row["child"]] && 247 (!$a_omit_node || ($row["child"] != $a_ref_id))) { 248 //echo "-".ilObject::_lookupTitle($row["obj_id"])."-"; 249 if ($row["title"] == "ILIAS" && $row["type"] == "root") { 250 $row["title"] = $this->lng->txt("repository"); 251 } 252 $this->addItem( 253 $row["title"], 254 "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" . $row["type"] . "_" . $row["child"], 255 "_top", 256 $row["child"], 257 $row["type"] 258 ); 259 } 260 } 261 } 262 } 263 264 /** 265 * add locator item 266 * 267 * @param string $a_title item title 268 * @param string $a_link item link 269 * @param string $a_frame frame target 270 */ 271 public function addItem($a_title, $a_link, $a_frame = "", $a_ref_id = 0, $type = null) 272 { 273 // LTI 274 global $DIC; 275 $ltiview = $DIC['lti']; 276 277 $ilAccess = $this->access; 278 279 if ($a_ref_id > 0 && !$ilAccess->checkAccess("visible", "", $a_ref_id)) { 280 return; 281 } 282 // LTI 283 if ($ltiview->isActive()) { 284 $a_frame = "_self"; 285 } 286 $this->entries[] = array("title" => $a_title, 287 "link" => $a_link, "frame" => $a_frame, "ref_id" => $a_ref_id, "type" => $type); 288 } 289 290 /** 291 * Clear all Items 292 */ 293 public function clearItems() 294 { 295 $this->entries = array(); 296 } 297 298 /** 299 * Get all locator entries. 300 */ 301 public function getItems() 302 { 303 return $this->entries; 304 } 305 306 /** 307 * Get locator HTML 308 */ 309 public function getHTML() 310 { 311 $lng = $this->lng; 312 $ilSetting = $this->settings; 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", " "); 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 374 /** 375 * Get text version 376 */ 377 public function getTextVersion() 378 { 379 $lng = $this->lng; 380 $ilSetting = $this->settings; 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 401