ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilNavigationHistory Class Reference

Last visited history for repository items. More...

+ Collaboration diagram for ilNavigationHistory:

Public Member Functions

 __construct ()
 
 addItem (int $a_ref_id, string $a_link, string $a_type, string $a_title="", ?int $a_sub_obj_id=null, string $a_goto_link="")
 Add an item to the stack. More...
 
 getItems ()
 Get navigation item stack. More...
 
 deleteDBEntries ()
 
 deleteSessionEntries ()
 

Protected Attributes

ILIAS Repository LastVisited NavigationSessionRepository $repo
 
ilObjUser $user
 
ilDBInterface $db
 
ilTree $tree
 
ilObjectDefinition $obj_definition
 
ilComponentRepository $component_repository
 

Private Attributes

array $items
 

Detailed Description

Last visited history for repository items.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ilNavigationHistory.php.

Constructor & Destructor Documentation

◆ __construct()

ilNavigationHistory::__construct ( )

Definition at line 36 of file class.ilNavigationHistory.php.

References $DIC, and ILIAS\Repository\user().

37  {
38  global $DIC;
39 
40  $this->user = $DIC->user();
41  $this->db = $DIC->database();
42  $this->tree = $DIC->repositoryTree();
43  $this->obj_definition = $DIC["objDefinition"];
44  $this->items = array();
45 
46  $this->repo = new \ILIAS\Repository\LastVisited\NavigationSessionRepository();
47  $this->items = $this->repo->getHistory();
48  $this->component_repository = $DIC["component.repository"];
49  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

ilNavigationHistory::addItem ( int  $a_ref_id,
string  $a_link,
string  $a_type,
string  $a_title = "",
?int  $a_sub_obj_id = null,
string  $a_goto_link = "" 
)

Add an item to the stack.

If ref_id is already used, the item is moved to the top.

Definition at line 55 of file class.ilNavigationHistory.php.

References $db, $id, $ilDB, $user, ilObject\_exists(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), and getItems().

Referenced by ilObjIndividualAssessmentGUI\addToNavigationHistory(), ilHTLMPresentationGUI\executeCommand(), ilObjForumGUI\getSafePostCommands(), and ilObjForumGUI\viewThreadObject().

62  : void {
63  $ilUser = $this->user;
64  $ilDB = $this->db;
65 
66  // never store?
67  if ((int) ($ilUser->prefs["store_last_visited"] ?? 0) == 2) {
68  return;
69  }
70 
71  $a_sub_obj_id = (string) $a_sub_obj_id;
72 
73  if ($a_title === "" && $a_ref_id > 0) {
74  $obj_id = ilObject::_lookupObjId($a_ref_id);
75  if (ilObject::_exists($obj_id)) {
76  $a_title = ilObject::_lookupTitle($obj_id);
77  }
78  }
79 
80  $id = $a_ref_id . ":" . $a_sub_obj_id;
81 
82  $new_items[$id] = array("id" => $id,"ref_id" => $a_ref_id, "link" => $a_link, "title" => $a_title,
83  "type" => $a_type, "sub_obj_id" => $a_sub_obj_id, "goto_link" => $a_goto_link);
84 
85  $cnt = 1;
86  foreach ($this->items as $key => $item) {
87  if ($item["id"] != $id && $cnt <= 10) {
88  $new_items[$item["id"]] = $item;
89  $cnt++;
90  }
91  }
92 
93  // put items in session
94  $this->items = $new_items;
95 
96  $this->repo->setHistory($this->items);
97 
98  // only store in session?
99  if ((int) ($ilUser->prefs["store_last_visited"] ?? 0) == 1) {
100  return;
101  }
102 
103 
104  // update entries in db
105  $ilDB->update(
106  "usr_data",
107  array(
108  "last_visited" => array("clob", serialize($this->getItems()))),
109  array(
110  "usr_id" => array("integer", $ilUser->getId()))
111  );
112  }
static _lookupObjId(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupTitle(int $obj_id)
getItems()
Get navigation item stack.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteDBEntries()

ilNavigationHistory::deleteDBEntries ( )

Definition at line 186 of file class.ilNavigationHistory.php.

References $db, $ilDB, and $user.

186  : void
187  {
188  $ilUser = $this->user;
189  $ilDB = $this->db;
190 
191  // update entries in db
192  $ilDB->update(
193  "usr_data",
194  array(
195  "last_visited" => array("clob", serialize(array()))),
196  array(
197  "usr_id" => array("integer", $ilUser->getId()))
198  );
199  }

◆ deleteSessionEntries()

ilNavigationHistory::deleteSessionEntries ( )

Definition at line 201 of file class.ilNavigationHistory.php.

201  : void
202  {
203  $this->repo->setHistory([]);
204  }

◆ getItems()

ilNavigationHistory::getItems ( )

Get navigation item stack.

Definition at line 117 of file class.ilNavigationHistory.php.

References $component_repository, $db, $ilDB, $items, $obj_definition, $tree, $user, ilObject\_lookupObjId(), ilObject\_lookupTitle(), ANONYMOUS_USER_ID, ilComponentRepository\getPluginById(), ilComponentRepository\hasPluginId(), and ilTree\isInTree().

Referenced by addItem().

117  : array
118  {
119  $tree = $this->tree;
120  $ilDB = $this->db;
121  $ilUser = $this->user;
122  $objDefinition = $this->obj_definition;
124 
125  $items = array();
126 
127  foreach ($this->items as $it) {
128  if (
129  $tree->isInTree($it["ref_id"]) &&
130  (
131  !$objDefinition->isPluginTypeName($it["type"]) ||
132  (
133  $component_repository->hasPluginId($it["type"]) &&
134  $component_repository->getPluginById($it["type"])->isActive()
135  )
136  )
137  ) {
138  $items[$it["ref_id"] . ":" . $it["sub_obj_id"]] = $it;
139  }
140  }
141  // less than 10? -> get items from db
142  if (count($items) < 10 && $ilUser->getId() !== ANONYMOUS_USER_ID) {
143  $set = $ilDB->query(
144  "SELECT last_visited FROM usr_data " .
145  " WHERE usr_id = " . $ilDB->quote($ilUser->getId(), "integer")
146  );
147  $rec = $ilDB->fetchAssoc($set);
148  $db_entries = unserialize((string) $rec["last_visited"], ["allowed_classes" => false]);
149  $cnt = count($items);
150  if (is_array($db_entries)) {
151  foreach ($db_entries as $rec) {
152  if (
153  $cnt <= 10 &&
154  !isset($items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]]) &&
155  $tree->isInTree((int) $rec["ref_id"]) &&
156  (
157  !$objDefinition->isPluginTypeName($rec["type"]) ||
158  (
159  $component_repository->hasPluginId($rec["type"]) &&
160  $component_repository->getPluginById($rec["type"])->isActive()
161  )
162  )
163  ) {
164  $link = ($rec["goto_link"] != "")
165  ? $rec["goto_link"]
166  : ilLink::_getLink((int) $rec["ref_id"]);
167  if ($rec["sub_obj_id"] != "") {
168  $title = $rec["title"];
169  } elseif ($rec["type"] === "sess") {
170  $sess = new ilObjSession($rec["ref_id"]);
171  $title = $sess->getPresentationTitle();
172  } else {
173  $title = ilObject::_lookupTitle(ilObject::_lookupObjId((int) $rec["ref_id"]));
174  }
175  $items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]] = array("id" => $rec["ref_id"] . ":" . $rec["sub_obj_id"],
176  "ref_id" => $rec["ref_id"], "link" => $link, "title" => $title,
177  "type" => $rec["type"], "sub_obj_id" => $rec["sub_obj_id"], "goto_link" => $rec["goto_link"]);
178  $cnt++;
179  }
180  }
181  }
182  }
183  return $items;
184  }
hasPluginId(string $id)
Check if a plugin exists.
const ANONYMOUS_USER_ID
Definition: constants.php:27
isInTree(?int $a_node_id)
get all information of a node.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
ilObjectDefinition $obj_definition
getPluginById(string $id)
Get a plugin by id.
ilComponentRepository $component_repository
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $component_repository

ilComponentRepository ilNavigationHistory::$component_repository
protected

Definition at line 33 of file class.ilNavigationHistory.php.

Referenced by getItems().

◆ $db

ilDBInterface ilNavigationHistory::$db
protected

Definition at line 30 of file class.ilNavigationHistory.php.

Referenced by addItem(), deleteDBEntries(), and getItems().

◆ $items

array ilNavigationHistory::$items
private

Definition at line 34 of file class.ilNavigationHistory.php.

Referenced by getItems().

◆ $obj_definition

ilObjectDefinition ilNavigationHistory::$obj_definition
protected

Definition at line 32 of file class.ilNavigationHistory.php.

Referenced by getItems().

◆ $repo

ILIAS Repository LastVisited NavigationSessionRepository ilNavigationHistory::$repo
protected

Definition at line 28 of file class.ilNavigationHistory.php.

◆ $tree

ilTree ilNavigationHistory::$tree
protected

Definition at line 31 of file class.ilNavigationHistory.php.

Referenced by getItems().

◆ $user

ilObjUser ilNavigationHistory::$user
protected

Definition at line 29 of file class.ilNavigationHistory.php.

Referenced by addItem(), deleteDBEntries(), and getItems().


The documentation for this class was generated from the following file: