ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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;
107 
108  $items = array();
109 
110  foreach ($this->items as $it)
111  {
112  if ($tree->isInTree($it["ref_id"]))
113  {
114  $items[$it["ref_id"].":".$it["sub_obj_id"]] = $it;
115  }
116  }
117  // less than 10? -> get items from db
118  if (count($items) < 10 && $ilUser->getId() != ANONYMOUS_USER_ID)
119  {
120  $set = $ilDB->query("SELECT last_visited FROM usr_data ".
121  " WHERE usr_id = ".$ilDB->quote($ilUser->getId(), "integer")
122  );
123  $rec = $ilDB->fetchAssoc($set);
124  $db_entries = unserialize($rec["last_visited"]);
125  $cnt = count($items);
126  if (is_array($db_entries))
127  {
128  foreach ($db_entries as $rec)
129  {
130  include_once("./Services/Link/classes/class.ilLink.php");
131 
132  if ($cnt <= 10 && ! isset($items[$rec["ref_id"].":".$rec["sub_obj_id"]]))
133  {
134  if ($tree->isInTree($rec["ref_id"]))
135  {
136  $link = ($rec["goto_link"] != "")
137  ? $rec["goto_link"]
138  : ilLink::_getLink($rec["ref_id"]);
139  if ($rec["sub_obj_id"] != "")
140  {
141  $title = $rec["title"];
142  }
143  else
144  {
146  }
147  $items[$rec["ref_id"].":".$rec["sub_obj_id"]] = array("id" => $rec["ref_id"].":".$rec["sub_obj_id"],
148  "ref_id" => $rec["ref_id"], "link" => $link, "title" => $title,
149  "type" => $rec["type"], "sub_obj_id" => $rec["sub_obj_id"], "goto_link" => $rec["goto_link"]);
150  $cnt++;
151  }
152  }
153  }
154  }
155  }
156 //var_dump($items);
157  return $items;
158  }
159 
166  function deleteDBEntries()
167  {
168  global $ilUser, $ilDB;
169 
170  // update entries in db
171  $ilDB->update("usr_data",
172  array(
173  "last_visited" => array("clob", serialize(array()))),
174  array(
175  "usr_id" => array("integer", $ilUser->getId()))
176  );
177  }
178 
186  {
187  $_SESSION["il_nav_history"] = serialize(array());
188  }
189 
190 }
191 ?>