ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilNavigationHistory.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
13 {
14 
15  private $items;
16 
22  public function __construct()
23  {
24  $this->items = array();
25  $items = null;
26  if (isset($_SESSION["il_nav_history"]))
27  {
28  $items = unserialize($_SESSION["il_nav_history"]);
29  }
30  if (is_array($items))
31  {
32  $this->items = $items;
33  }
34  }
35 
40  public function addItem($a_ref_id, $a_link, $a_type, $a_title = "", $a_sub_obj_id = "",
41  $a_goto_link = "")
42  {
43  global $ilUser, $ilDB;
44 
45  // never store?
46  if ($ilUser->prefs["store_last_visited"] == 2)
47  {
48  return;
49  }
50 
51  $a_sub_obj_id = $a_sub_obj_id."";
52 
53  if ($a_title == "" && $a_ref_id > 0)
54  {
55  $obj_id = ilObject::_lookupObjId($a_ref_id);
56  if (ilObject::_exists($obj_id))
57  {
58  $a_title = ilObject::_lookupTitle($obj_id);
59  }
60  }
61 
62  $id = $a_ref_id.":".$a_sub_obj_id;
63 
64  $new_items[$id] = array("id" => $id,"ref_id" => $a_ref_id, "link" => $a_link, "title" => $a_title,
65  "type" => $a_type, "sub_obj_id" => $a_sub_obj_id, "goto_link" => $a_goto_link);
66 
67  $cnt = 1;
68  foreach($this->items as $key => $item)
69  {
70  if ($item["id"] != $id && $cnt <= 10)
71  {
72  $new_items[$item["id"]] = $item;
73  $cnt++;
74  }
75  }
76 
77  // put items in session
78  $this->items = $new_items;
79 
80  $items = serialize($this->items);
81  $_SESSION["il_nav_history"] = $items;
82 //var_dump($this->getItems());
83 
84 
85  // only store in session?
86  if ($ilUser->prefs["store_last_visited"] == 1)
87  {
88  return;
89  }
90 
91 
92  // update entries in db
93  $ilDB->update("usr_data",
94  array(
95  "last_visited" => array("clob", serialize($this->getItems()))),
96  array(
97  "usr_id" => array("integer", $ilUser->getId()))
98  );
99  }
100 
104  public function getItems()
105  {
106  global $tree, $ilDB, $ilUser, $objDefinition, $ilPluginAdmin;
107 
108  $items = array();
109 
110  foreach ($this->items as $it)
111  {
112  if ($tree->isInTree($it["ref_id"]) &&
113  (!$objDefinition->isPluginTypeName($it["type"]) ||
114  $ilPluginAdmin->isActive(IL_COMP_SERVICE, "Repository", "robj",
115  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $it["type"]))
116  ))
117  {
118  $items[$it["ref_id"].":".$it["sub_obj_id"]] = $it;
119  }
120  }
121  // less than 10? -> get items from db
122  if (count($items) < 10 && $ilUser->getId() != ANONYMOUS_USER_ID)
123  {
124  $set = $ilDB->query("SELECT last_visited FROM usr_data ".
125  " WHERE usr_id = ".$ilDB->quote($ilUser->getId(), "integer")
126  );
127  $rec = $ilDB->fetchAssoc($set);
128  $db_entries = unserialize($rec["last_visited"]);
129  $cnt = count($items);
130  if (is_array($db_entries))
131  {
132  foreach ($db_entries as $rec)
133  {
134  include_once("./Services/Link/classes/class.ilLink.php");
135 
136  if ($cnt <= 10 && ! isset($items[$rec["ref_id"].":".$rec["sub_obj_id"]]))
137  {
138  if ($tree->isInTree($rec["ref_id"]) &&
139  (!$objDefinition->isPluginTypeName($rec["type"]) ||
140  $ilPluginAdmin->isActive(IL_COMP_SERVICE, "Repository", "robj",
141  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $rec["type"]))
142  ))
143  {
144  $link = ($rec["goto_link"] != "")
145  ? $rec["goto_link"]
146  : ilLink::_getLink($rec["ref_id"]);
147  if ($rec["sub_obj_id"] != "")
148  {
149  $title = $rec["title"];
150  }
151  else
152  {
154  }
155  $items[$rec["ref_id"].":".$rec["sub_obj_id"]] = array("id" => $rec["ref_id"].":".$rec["sub_obj_id"],
156  "ref_id" => $rec["ref_id"], "link" => $link, "title" => $title,
157  "type" => $rec["type"], "sub_obj_id" => $rec["sub_obj_id"], "goto_link" => $rec["goto_link"]);
158  $cnt++;
159  }
160  }
161  }
162  }
163  }
164 //var_dump($items);
165  return $items;
166  }
167 
174  function deleteDBEntries()
175  {
176  global $ilUser, $ilDB;
177 
178  // update entries in db
179  $ilDB->update("usr_data",
180  array(
181  "last_visited" => array("clob", serialize(array()))),
182  array(
183  "usr_id" => array("integer", $ilUser->getId()))
184  );
185  }
186 
194  {
195  $_SESSION["il_nav_history"] = serialize(array());
196  }
197 
198 }
199 ?>
$_SESSION["AccountId"]
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
deleteSessionEntries()
Delete session entries.
static _lookupTitle($a_id)
lookup object title
$a_type
Definition: workflow.php:93
static lookupNameForId($a_ctype, $a_cname, $a_slot_id, $a_plugin_id)
Lookup name for id.
getItems()
Get navigation item stack.
static _lookupObjId($a_id)
$ilUser
Definition: imgupload.php:18
Navigation History of Repository Items.
Create styles array
The data for the language used.
global $ilDB
addItem($a_ref_id, $a_link, $a_type, $a_title="", $a_sub_obj_id="", $a_goto_link="")
Add an item to the stack.
const IL_COMP_SERVICE
deleteDBEntries()
Delete DB entries.