ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $tree = $this->tree;
106 
107  if ($a_ref_id == 0) {
108  $a_ref_id = $_GET["ref_id"];
109  }
110 
111  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
112  if (ilMemberViewSettings::getInstance()->isActive() and $a_ref_id != ROOT_FOLDER_ID) {
113  $a_start = ilMemberViewSettings::getInstance()->getContainer();
114  } else {
115  $a_start = ROOT_FOLDER_ID;
116  }
117 
118  if ($a_ref_id > 0) {
119  $path = $tree->getPathFull($a_ref_id, $a_start);
120 
121  // add item for each node on path
122  foreach ((array) $path as $key => $row) {
123  if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp", "prg"))) {
124  continue;
125  }
126  if ($row["title"] == "ILIAS" && $row["type"] == "root") {
127  $row["title"] = $this->lng->txt("repository");
128  }
129 
130  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $row["child"]);
131  $this->addItem(
132  $row["title"],
133  $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset"),
134  ilFrameTargetInfo::_getFrame("MainContent"),
135  $row["child"]
136  );
137  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
138  }
139  }
140  }
141 
148  public function addAdministrationItems($a_ref_id = 0)
149  {
150  $tree = $this->tree;
152  $objDefinition = $this->obj_definition;
153  $lng = $this->lng;
154 
155  if ($a_ref_id == 0) {
156  $a_ref_id = $_GET["ref_id"];
157  }
158 
159  if ($a_ref_id > 0) {
160  $path = $tree->getPathFull($a_ref_id);
161 
162  // add item for each node on path
163  foreach ($path as $key => $row) {
164  if (!in_array($row["type"], array("root", "cat", "crs", "fold", "grp"))) {
165  continue;
166  }
167 
168  if ($row["child"] == ROOT_FOLDER_ID) {
169  $row["title"] = $lng->txt("repository");
170  }
171 
172  $class_name = $objDefinition->getClassName($row["type"]);
173  $class = strtolower("ilObj" . $class_name . "GUI");
174  $ilCtrl->setParameterByClass($class, "ref_id", $row["child"]);
175  $this->addItem(
176  $row["title"],
177  $ilCtrl->getLinkTargetbyClass($class, "view"),
178  "",
179  $row["child"]
180  );
181  }
182  }
183  }
184 
185  public function addContextItems($a_ref_id, $a_omit_node = false, $a_stop = 0)
186  {
187  $tree = $this->tree;
188 
189  if ($a_ref_id > 0) {
190  $path = $tree->getPathFull($a_ref_id);
191 
192  // we want to show the full path, from the major container to the item
193  // (folders are not! treated as containers here), at least one parent item
194  $r_path = array_reverse($path);
195  $first = "";
196  $omit = array();
197  $do_omit = false;
198  foreach ($r_path as $key => $row) {
199  if ($first == "") {
200  if (in_array($row["type"], array("root", "cat", "grp", "crs")) &&
201  $row["child"] != $a_ref_id) {
202  $first = $row["child"];
203  }
204  }
205  if ($a_stop == $row["child"]) {
206  $do_omit = true;
207  }
208  $omit[$row["child"]] = $do_omit;
209  }
210 
211  $add_it = false;
212  foreach ($path as $key => $row) {
213  if ($first == $row["child"]) {
214  $add_it = true;
215  }
216 
217 
218  if ($add_it && !$omit[$row["child"]] &&
219  (!$a_omit_node || ($row["child"] != $a_ref_id))) {
220  //echo "-".ilObject::_lookupTitle($row["obj_id"])."-";
221  if ($row["title"] == "ILIAS" && $row["type"] == "root") {
222  $row["title"] = $this->lng->txt("repository");
223  }
224  $this->addItem(
225  $row["title"],
226  "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" . $row["type"] . "_" . $row["child"],
227  "_top",
228  $row["child"],
229  $row["type"]
230  );
231  }
232  }
233  }
234  }
235 
243  public function addItem($a_title, $a_link, $a_frame = "", $a_ref_id = 0, $type = null)
244  {
245  // LTI
246  global $DIC;
247  $ltiview = $DIC['lti'];
248 
249  $ilAccess = $this->access;
250 
251  if ($a_ref_id > 0 && !$ilAccess->checkAccess("visible", "", $a_ref_id)) {
252  return;
253  }
254  // LTI
255  if ($ltiview->isActive()) {
256  $a_frame = "_self";
257  }
258  $this->entries[] = array("title" => $a_title,
259  "link" => $a_link, "frame" => $a_frame, "ref_id" => $a_ref_id, "type" => $type);
260  }
261 
265  public function clearItems()
266  {
267  $this->entries = array();
268  }
269 
273  public function getItems()
274  {
275  return $this->entries;
276  }
277 
281  public function getHTML()
282  {
283  global $DIC;
284  $ltiview = $DIC["lti"];
285  if ($ltiview->isActive() && !$ltiview->show_locator) {
286  return "";
287  }
288  $lng = $this->lng;
290 
291  if ($this->getTextOnly()) {
292  $loc_tpl = new ilTemplate("tpl.locator_text_only.html", true, true, "Services/Locator");
293  } else {
294  $loc_tpl = new ilTemplate("tpl.locator.html", true, true, "Services/Locator");
295  }
296 
297  $items = $this->getItems();
298  $first = true;
299 
300  if (is_array($items)) {
301  foreach ($items as $item) {
302  if (!$first) {
303  $loc_tpl->touchBlock("locator_separator_prefix");
304  }
305 
306  if ($item["ref_id"] > 0) {
307  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
308  $type = ilObject::_lookupType($obj_id);
309 
310  if (!$this->getTextOnly()) {
311  $icon_path = ilObject::_getIcon(
312  $obj_id,
313  "tiny",
314  $type,
315  $this->getOffline()
316  );
317  }
318 
319  $loc_tpl->setCurrentBlock("locator_img");
320  $loc_tpl->setVariable("IMG_SRC", $icon_path);
321  $loc_tpl->setVariable(
322  "IMG_ALT",
323  $lng->txt("obj_" . $type)
324  );
325  $loc_tpl->parseCurrentBlock();
326  }
327 
328  $loc_tpl->setCurrentBlock("locator_item");
329  if ($item["link"] != "") {
330  $loc_tpl->setVariable("LINK_ITEM", $item["link"]);
331  if ($item["frame"] != "") {
332  $loc_tpl->setVariable("LINK_TARGET", ' target="' . $item["frame"] . '" ');
333  }
334  $loc_tpl->setVariable("ITEM", $item["title"]);
335  } else {
336  $loc_tpl->setVariable("PREFIX", $item["title"]);
337  }
338  $loc_tpl->parseCurrentBlock();
339 
340  $first = false;
341  }
342  } else {
343  $loc_tpl->setVariable("NOITEM", "&nbsp;");
344  $loc_tpl->touchBlock("locator");
345  }
346  $loc_tpl->setVariable("TXT_BREADCRUMBS", $lng->txt("breadcrumb_navigation"));
347 
348  return trim($loc_tpl->get());
349  }
350 
354  public function getTextVersion()
355  {
356  $lng = $this->lng;
358 
359  $items = $this->getItems();
360  $first = true;
361 
362  $str = "";
363  if (is_array($items)) {
364  foreach ($items as $item) {
365  if (!$first) {
366  $str.= " > ";
367  }
368 
369  $str.= $item["title"];
370 
371  $first = false;
372  }
373  }
374 
375  return $str;
376  }
377 } // END class.LocatorGUI
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
getHTML()
Get locator HTML.
addItem($a_title, $a_link, $a_frame="", $a_ref_id=0, $type=null)
add locator item
clearItems()
Clear all Items.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
addContextItems($a_ref_id, $a_omit_node=false, $a_stop=0)
getItems()
Get all locator entries.
getTextOnly()
Get Only text, no HTML.
addAdministrationItems($a_ref_id=0)
add administration tree items
locator handling class
global $ilCtrl
Definition: ilias.php:18
getTextVersion()
Get text version.
setTextOnly($a_textonly)
Set Only text, no HTML.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct()
Constructor.
settings()
Definition: settings.php:2
static _getFrame($a_class, $a_type='')
Get content frame name.
global $ilSetting
Definition: privfeed.php:17
static getInstance()
Get instance.
addRepositoryItems($a_ref_id=0)
add repository item
setOffline($a_offline)
$key
Definition: croninfo.php:18