ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
17 protected $user;
18
22 protected $db;
23
27 protected $tree;
28
32 protected $obj_definition;
33
37 protected $plugin_admin;
38
39
40 private $items;
41
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->user = $DIC->user();
52 $this->db = $DIC->database();
53 $this->tree = $DIC->repositoryTree();
54 $this->obj_definition = $DIC["objDefinition"];
55 $this->plugin_admin = $DIC["ilPluginAdmin"];
56 $this->items = array();
57 $items = null;
58 if (isset($_SESSION["il_nav_history"])) {
59 $items = unserialize($_SESSION["il_nav_history"]);
60 }
61 if (is_array($items)) {
62 $this->items = $items;
63 }
64 }
65
70 public function addItem(
71 $a_ref_id,
72 $a_link,
73 $a_type,
74 $a_title = "",
75 $a_sub_obj_id = "",
76 $a_goto_link = ""
77 ) {
80
81 // never store?
82 if ($ilUser->prefs["store_last_visited"] == 2) {
83 return;
84 }
85
86 $a_sub_obj_id = $a_sub_obj_id . "";
87
88 if ($a_title == "" && $a_ref_id > 0) {
89 $obj_id = ilObject::_lookupObjId($a_ref_id);
90 if (ilObject::_exists($obj_id)) {
91 $a_title = ilObject::_lookupTitle($obj_id);
92 }
93 }
94
95 $id = $a_ref_id . ":" . $a_sub_obj_id;
96
97 $new_items[$id] = array("id" => $id,"ref_id" => $a_ref_id, "link" => $a_link, "title" => $a_title,
98 "type" => $a_type, "sub_obj_id" => $a_sub_obj_id, "goto_link" => $a_goto_link);
99
100 $cnt = 1;
101 foreach ($this->items as $key => $item) {
102 if ($item["id"] != $id && $cnt <= 10) {
103 $new_items[$item["id"]] = $item;
104 $cnt++;
105 }
106 }
107
108 // put items in session
109 $this->items = $new_items;
110
111 $items = serialize($this->items);
112 $_SESSION["il_nav_history"] = $items;
113 //var_dump($this->getItems());
114
115
116 // only store in session?
117 if ($ilUser->prefs["store_last_visited"] == 1) {
118 return;
119 }
120
121
122 // update entries in db
123 $ilDB->update(
124 "usr_data",
125 array(
126 "last_visited" => array("clob", serialize($this->getItems()))),
127 array(
128 "usr_id" => array("integer", $ilUser->getId()))
129 );
130 }
131
135 public function getItems()
136 {
140 $objDefinition = $this->obj_definition;
141 $ilPluginAdmin = $this->plugin_admin;
142
143 $items = array();
144
145 foreach ($this->items as $it) {
146 if ($tree->isInTree($it["ref_id"]) &&
147 (
148 !$objDefinition->isPluginTypeName($it["type"]) ||
149 $ilPluginAdmin->isActive(
151 "Repository",
152 "robj",
153 ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $it["type"])
154 )
155 )) {
156 $items[$it["ref_id"] . ":" . $it["sub_obj_id"]] = $it;
157 }
158 }
159 // less than 10? -> get items from db
160 if (count($items) < 10 && $ilUser->getId() != ANONYMOUS_USER_ID) {
161 $set = $ilDB->query(
162 "SELECT last_visited FROM usr_data " .
163 " WHERE usr_id = " . $ilDB->quote($ilUser->getId(), "integer")
164 );
165 $rec = $ilDB->fetchAssoc($set);
166 $db_entries = unserialize($rec["last_visited"]);
167 $cnt = count($items);
168 if (is_array($db_entries)) {
169 foreach ($db_entries as $rec) {
170 include_once("./Services/Link/classes/class.ilLink.php");
171
172 if ($cnt <= 10 && !isset($items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]])) {
173 if ($tree->isInTree($rec["ref_id"]) &&
174 (
175 !$objDefinition->isPluginTypeName($rec["type"]) ||
176 $ilPluginAdmin->isActive(
178 "Repository",
179 "robj",
180 ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $rec["type"])
181 )
182 )) {
183 $link = ($rec["goto_link"] != "")
184 ? $rec["goto_link"]
185 : ilLink::_getLink($rec["ref_id"]);
186 if ($rec["sub_obj_id"] != "") {
187 $title = $rec["title"];
188 } else {
190 }
191 $items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]] = array("id" => $rec["ref_id"] . ":" . $rec["sub_obj_id"],
192 "ref_id" => $rec["ref_id"], "link" => $link, "title" => $title,
193 "type" => $rec["type"], "sub_obj_id" => $rec["sub_obj_id"], "goto_link" => $rec["goto_link"]);
194 $cnt++;
195 }
196 }
197 }
198 }
199 }
200 //var_dump($items);
201 return $items;
202 }
203
210 public function deleteDBEntries()
211 {
214
215 // update entries in db
216 $ilDB->update(
217 "usr_data",
218 array(
219 "last_visited" => array("clob", serialize(array()))),
220 array(
221 "usr_id" => array("integer", $ilUser->getId()))
222 );
223 }
224
231 public function deleteSessionEntries()
232 {
233 $_SESSION["il_nav_history"] = serialize(array());
234 }
235}
user()
Definition: user.php:4
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
Navigation History of Repository Items.
addItem( $a_ref_id, $a_link, $a_type, $a_title="", $a_sub_obj_id="", $a_goto_link="")
Add an item to the stack.
deleteDBEntries()
Delete DB entries.
deleteSessionEntries()
Delete session entries.
getItems()
Get navigation item stack.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static lookupNameForId($a_ctype, $a_cname, $a_slot_id, $a_plugin_id)
Lookup name for id.
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92