ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilNavigationHistory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 protected \ILIAS\Repository\LastVisited\NavigationSessionRepository $repo;
29 protected ilObjUser $user;
30 protected ilDBInterface $db;
31 protected ilTree $tree;
34 private array $items;
35
36 public function __construct()
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 }
50
55 public function addItem(
56 int $a_ref_id,
57 string $a_link,
58 string $a_type,
59 string $a_title = "",
60 ?int $a_sub_obj_id = null,
61 string $a_goto_link = ""
62 ): void {
63 $ilUser = $this->user;
65
66 // never store?
67 if ((int) ($ilUser->getPref("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->getPref("store_last_visited") ?? 0) == 1) {
100 return;
101 }
102
103 // update entries in db
104 $ilUser->updateLastVisited($this->getItems());
105 }
106
110 public function getItems(): array
111 {
112 $tree = $this->tree;
113 $ilDB = $this->db;
114 $ilUser = $this->user;
115 $objDefinition = $this->obj_definition;
116 $component_repository = $this->component_repository;
117
118 $items = array();
119
120 foreach ($this->items as $it) {
121 if (
122 $tree->isInTree($it["ref_id"]) &&
123 (
124 !$objDefinition->isPluginTypeName($it["type"]) ||
125 (
126 $component_repository->hasPluginId($it["type"]) &&
127 $component_repository->getPluginById($it["type"])->isActive()
128 )
129 )
130 ) {
131 $items[$it["ref_id"] . ":" . $it["sub_obj_id"]] = $it;
132 }
133 }
134 // less than 10? -> get items from db
135 if (count($items) < 10 && $ilUser->getId() !== ANONYMOUS_USER_ID) {
136 $db_entries = $ilUser->getLastVisited();
137 $cnt = count($items);
138 foreach ($db_entries as $rec) {
139 if (
140 $cnt <= 10 &&
141 !isset($items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]]) &&
142 $tree->isInTree((int) $rec["ref_id"]) &&
143 (
144 !$objDefinition->isPluginTypeName($rec["type"]) ||
145 (
146 $component_repository->hasPluginId($rec["type"]) &&
147 $component_repository->getPluginById($rec["type"])->isActive()
148 )
149 )
150 ) {
151 $link = ($rec["goto_link"] != "")
152 ? $rec["goto_link"]
153 : ilLink::_getLink((int) $rec["ref_id"]);
154 if ($rec["sub_obj_id"] != "") {
155 $title = $rec["title"];
156 } elseif ($rec["type"] === "sess") {
157 try {
158 $sess = new ilObjSession((int) $rec["ref_id"]);
159 $title = $sess->getPresentationTitle();
161 $title = ilObject::_lookupTitle(ilObject::_lookupObjId((int) $rec["ref_id"]));
162 }
163 } else {
164 $title = ilObject::_lookupTitle(ilObject::_lookupObjId((int) $rec["ref_id"]));
165 }
166 $items[$rec["ref_id"] . ":" . $rec["sub_obj_id"]] = array("id" => $rec["ref_id"] . ":" . $rec["sub_obj_id"],
167 "ref_id" => $rec["ref_id"], "link" => $link, "title" => $title,
168 "type" => $rec["type"], "sub_obj_id" => $rec["sub_obj_id"], "goto_link" => $rec["goto_link"]);
169 $cnt++;
170 }
171 }
172 }
173 return $items;
174 }
175
176 public function deleteDBEntries(): void
177 {
178 $ilUser = $this->user;
179 $ilDB = $this->db;
180
181 // update entries in db
182 $ilDB->update(
183 "usr_data",
184 array(
185 "last_visited" => array("clob", serialize(array()))),
186 array(
187 "usr_id" => array("integer", $ilUser->getId()))
188 );
189 }
190
191 public function deleteSessionEntries(): void
192 {
193 $this->repo->setHistory([]);
194 }
195}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Last visited history for repository items.
ilObjectDefinition $obj_definition
ILIAS Repository LastVisited NavigationSessionRepository $repo
ilComponentRepository $component_repository
getItems()
Get navigation item stack.
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.
User class.
parses the objects.xml it handles the xml-description of all ilias objects
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
isInTree(?int $a_node_id)
get all information of a node.
const ANONYMOUS_USER_ID
Definition: constants.php:27
Readable part of repository interface to ilComponentDataDB.
getPluginById(string $id)
Get a plugin by id.
hasPluginId(string $id)
Check if a plugin exists.
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26