ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilNavigationHistoryGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
27 {
29  protected ilCtrl $ctrl;
31  protected ilLanguage $lng;
32 
33  public function __construct()
34  {
35  global $DIC;
36 
37  $this->ctrl = $DIC->ctrl();
38  $this->nav_history = $DIC["ilNavigationHistory"];
39  $this->lng = $DIC->language();
40  $this->request = new StandardGUIRequest(
41  $DIC->http(),
42  $DIC->refinery()
43  );
44  }
45 
46  public function executeCommand(): void
47  {
48  $ilCtrl = $this->ctrl;
49 
50  $next_class = $ilCtrl->getNextClass();
51  $cmd = $ilCtrl->getCmd();
52 
53  switch ($next_class) {
54  default:
55  $this->$cmd();
56  break;
57  }
58  }
59 
60  public function getHTML(): string
61  {
62  $ilNavigationHistory = $this->nav_history;
63  $lng = $this->lng;
64 
65  $selection = new ilAdvancedSelectionListGUI();
66  $selection->setFormSelectMode(
67  "url_ref_id",
68  "ilNavHistorySelect",
69  true,
70  "goto.php?target=navi_request",
71  "ilNavHistory",
72  "ilNavHistoryForm",
73  "_top",
74  $lng->txt("go"),
75  "ilNavHistorySubmit"
76  );
77  $selection->setListTitle($lng->txt("last_visited"));
78  $selection->setId("lastvisited");
79  $selection->setSelectionHeaderClass("MMInactive");
80  $selection->setHeaderIcon(ilAdvancedSelectionListGUI::NO_ICON);
81  $selection->setItemLinkClass("small");
82  $selection->setUseImages(true);
83 
84  $items = $ilNavigationHistory->getItems();
85  //$sel_arr = array(0 => "-- ".$lng->txt("last_visited")." --");
86  reset($items);
87  $cnt = 0;
88  foreach ($items as $k => $item) {
89  if ($cnt++ > 20) {
90  break;
91  }
92  if (!isset($item["ref_id"]) || $this->request->getRefId() === 0 ||
93  $item["ref_id"] != $this->request->getRefId() || $k > 0) { // do not list current item
94  $obj_id = ilObject::_lookupObjId((int) $item["ref_id"]);
95  $selection->addItem(
96  $item["title"],
97  $item["ref_id"],
98  $item["link"],
99  ilObject::_getIcon($obj_id, "tiny", $item["type"]),
100  $lng->txt("obj_" . $item["type"]),
101  "_top"
102  );
103  }
104  }
105  $html = $selection->getHTML();
106 
107  if ($html === "") {
108  $selection->addItem(
109  $lng->txt("no_items"),
110  "",
111  "#",
112  "",
113  "",
114  "_top"
115  );
116  $selection->setUseImages(false);
117  $html = $selection->getHTML();
118  }
119  return $html;
120  }
121 
122  public function handleNavigationRequest(): void
123  {
124  $ilNavigationHistory = $this->nav_history;
125  $ilCtrl = $this->ctrl;
126 
127  if ($this->request->getTarget() === "navi_request") {
128  $items = $ilNavigationHistory->getItems();
129  foreach ($items as $item) {
130  if ($item["ref_id"] == $this->request->getUrlRefId()) {
131  ilUtil::redirect($item["link"]);
132  }
133  }
134  reset($items);
135  $item = current($items);
136  if ($this->request->getUrlRefId() === 0 && $item["ref_id"] == $this->request->getRefId()) {
137  $item = next($items); // omit current item
138  }
139  if ($this->request->getUrlRefId() === 0 && $item["link"] != "") {
140  ilUtil::redirect($item["link"]);
141  }
142 
143  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", "");
144  $ilCtrl->setParameterByClass("ilrepositorygui", "getlast", "true");
145  $ilCtrl->redirectByClass("ilrepositorygui", "");
146  }
147  }
148 
149  public function removeEntries(): void
150  {
151  $ilNavigationHistory = $this->nav_history;
152 
153  $ilNavigationHistory->deleteDBEntries();
154  $ilNavigationHistory->deleteSessionEntries();
155  }
156 }
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
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...
static _lookupObjId(int $ref_id)
User Interface Class for Navigation History.
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
global $DIC
Definition: feed.php:28
getNextClass($a_gui_class=null)
Navigation History of Repository Items.
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...