ILIAS  release_8 Revision v8.24
class.ilLMNavigationStatus.php
Go to the documentation of this file.
1<?php
2
28{
29 protected ?int $current_page_id = null;
30 protected bool $chapter_has_no_active_page = false;
31 protected bool $deactivated_page = false;
33 protected ilLMTree $lm_tree;
34 protected ilObjUser $user;
35 protected ilSetting $lm_set;
36 protected int $requested_back_page;
37 protected string $cmd;
38 protected int $focus_id;
39 protected int $requested_obj_id;
40
41 public function __construct(
43 int $request_obj_id,
48 string $cmd,
49 int $focus_id
50 ) {
51 $this->user = $user;
52 $this->requested_obj_id = $request_obj_id;
53 $this->lm_tree = $lm_tree;
54 $this->lm = $lm;
55 $this->lm_set = $lm_set;
56 $this->requested_back_page = (int) $requested_back_page;
57 $this->cmd = $cmd;
58 $this->focus_id = $focus_id;
59
60 $this->determineStatus();
61 }
62
66 public function isChapterWithoutActivePage(): bool
67 {
69 }
70
71 public function isDeactivatedPage(): bool
72 {
74 }
75
76 public function getCurrentPage(): int
77 {
79 }
80
81 protected function determineStatus(): void
82 {
84
85 $this->chapter_has_no_active_page = false;
86 $this->deactivated_page = false;
87
89 if ($requested_obj_id > 0 && ilLMObject::_lookupContObjID($requested_obj_id) !== $this->lm->getId()) {
91 }
92
93 // determine object id
94 if ($requested_obj_id == 0) {
95 $obj_id = $this->lm_tree->getRootId();
96
97 if ($this->cmd == "resume") {
98 if ($user->getId() != ANONYMOUS_USER_ID && ($this->focus_id == 0)) {
99 $last_accessed_page = ilObjLearningModuleAccess::_getLastAccessedPage($this->lm->getRefId(), $user->getId());
100 // if last accessed page was final page do nothing, start over
101 if ($last_accessed_page &&
102 $last_accessed_page != $this->lm_tree->getLastActivePage()) {
103 $obj_id = $last_accessed_page;
104 }
105 }
106 }
107 } else {
108 $obj_id = $requested_obj_id;
109 $active = ilLMPage::_lookupActive(
110 $obj_id,
111 $this->lm->getType(),
112 (bool) $this->lm_set->get("time_scheduled_page_activation")
113 );
114
115 if (!$active &&
116 ilLMPageObject::_lookupType($obj_id) == "pg") {
117 $this->deactivated_page = true;
118 }
119 }
120 // obj_id not in tree -> it is a unassigned page -> return page id
121 if (!$this->lm_tree->isInTree($obj_id)) {
122 $this->current_page_id = $obj_id;
123 return;
124 }
125
126 $curr_node = $this->lm_tree->getNodeData($obj_id);
127
128 $active = ilLMPage::_lookupActive(
129 $obj_id,
130 $this->lm->getType(),
131 (bool) $this->lm_set->get("time_scheduled_page_activation")
132 );
133
134 $show = $active;
135
136 // look, whether activation data should be shown
137 $act_data = ilLMPage::_lookupActivationData((int) $curr_node["obj_id"], $this->lm->getType());
138 if ($act_data["show_activation_info"] ?? false) {
139 $show = true;
140 }
141
142 if ($curr_node["type"] == "pg" &&
143 $show) { // page in tree -> return page id
144 $page_id = $curr_node["obj_id"];
145 } else { // no page -> search for next page and return its id
146 $succ_node = true;
147 $active = false;
148 $page_id = $obj_id;
149 while ($succ_node && !$active) {
150 $succ_node = $this->lm_tree->fetchSuccessorNode($page_id, "pg");
151 if (!is_null($succ_node)) {
152 $page_id = $succ_node["obj_id"];
153 $active = ilLMPage::_lookupActive(
154 $page_id,
155 $this->lm->getType(),
156 (bool) $this->lm_set->get("time_scheduled_page_activation")
157 );
158 }
159 }
160
161 if (is_null($succ_node) || $succ_node["type"] != "pg") {
162 $this->chapter_has_no_active_page = true;
163 $this->current_page_id = 0;
164 return;
165 }
166
167 // if public access get first public page in chapter
168 if ($user->getId() == ANONYMOUS_USER_ID &&
169 $this->lm->getPublicAccessMode() == 'selected') {
170 $public = ilLMObject::_isPagePublic($page_id);
171
172 while ($public === false && $page_id > 0) {
173 $succ_node = $this->lm_tree->fetchSuccessorNode($page_id, 'pg');
174 $page_id = $succ_node['obj_id'];
175 $public = ilLMObject::_isPagePublic($page_id);
176 }
177 }
178
179 // check whether page found is within "clicked" chapter
180 if ($this->lm_tree->isInTree($page_id)) {
181 $path = $this->lm_tree->getPathId($page_id);
182 if (!in_array($requested_obj_id, $path)) {
183 $this->chapter_has_no_active_page = true;
184 }
185 }
186 }
187
188 $this->current_page_id = $page_id;
189 }
190
191 public function getBackPageId(): int
192 {
193 $page_id = $this->current_page_id;
194
195 if (empty($page_id)) {
196 return 0;
197 }
198
200
201 // process navigation for free page
202 return $back_pg;
203 }
204
205 public function getSuccessorPageId(): int
206 {
207 $page_id = $this->current_page_id;
208 $user_id = $this->user->getId();
209 $succ_node = null;
210
211 // determine successor page_id
212 $found = false;
213
214 // empty chapter
215 if ($this->chapter_has_no_active_page &&
216 ilLMObject::_lookupType($this->requested_obj_id) == "st") {
218 } else {
219 if ($this->deactivated_page) {
221 } else {
222 $c_id = $page_id;
223 }
224 }
225 while (!$found) {
226 $succ_node = null;
227 if ($this->lm_tree->isInTree($c_id)) {
228 $succ_node = $this->lm_tree->fetchSuccessorNode($c_id, "pg");
229 }
230 if (is_array($succ_node)) {
231 $c_id = $succ_node["obj_id"];
232
233 $active = ilLMPage::_lookupActive(
234 $c_id,
235 $this->lm->getType(),
236 (bool) $this->lm_set->get("time_scheduled_page_activation")
237 );
238 }
239 if (is_array($succ_node) && $succ_node["obj_id"] > 0 &&
240 $user_id == ANONYMOUS_USER_ID &&
241 ($this->lm->getPublicAccessMode() == "selected" &&
242 !ilLMObject::_isPagePublic($succ_node["obj_id"]))) {
243 $found = false;
244 } else {
245 if (is_array($succ_node) && $succ_node["obj_id"] > 0 && !$active) {
246 // look, whether activation data should be shown
247 $act_data = ilLMPage::_lookupActivationData((int) $succ_node["obj_id"], $this->lm->getType());
248 if ($act_data["show_activation_info"] &&
249 (ilUtil::now() < $act_data["activation_start"])) {
250 $found = true;
251 } else {
252 $found = false;
253 }
254 } else {
255 $found = true;
256 }
257 }
258 }
259 if (is_array($succ_node)) {
260 return (int) $succ_node["obj_id"];
261 }
262
263 return 0;
264 }
265
266 public function getPredecessorPageId(): int
267 {
268 $page_id = $this->current_page_id;
269 $user_id = $this->user->getId();
270 $pre_node = null;
271
272 // determine predecessor page id
273 $found = false;
274 if ($this->deactivated_page) {
276 } else {
277 $c_id = $page_id;
278 }
279 while (!$found) {
280 $pre_node = null;
281 if ($this->lm_tree->isInTree($c_id)) {
282 $pre_node = $this->lm_tree->fetchPredecessorNode($c_id, "pg");
283 }
284 if (is_array($pre_node)) {
285 $c_id = $pre_node["obj_id"];
286 $active = ilLMPage::_lookupActive(
287 $c_id,
288 $this->lm->getType(),
289 (bool) $this->lm_set->get("time_scheduled_page_activation")
290 );
291 }
292 if (is_array($pre_node) && $pre_node["obj_id"] > 0 &&
293 $user_id == ANONYMOUS_USER_ID &&
294 ($this->lm->getPublicAccessMode() == "selected" &&
295 !ilLMObject::_isPagePublic($pre_node["obj_id"]))) {
296 $found = false;
297 } else {
298 if (is_array($pre_node) && $pre_node["obj_id"] > 0 && !$active) {
299 // look, whether activation data should be shown
300 $act_data = ilLMPage::_lookupActivationData((int) $pre_node["obj_id"], $this->lm->getType());
301 if ($act_data["show_activation_info"] &&
302 (ilUtil::now() < $act_data["activation_start"])) {
303 $found = true;
304 } else {
305 $found = false;
306 }
307 } else {
308 $found = true;
309 }
310 }
311 }
312 if (is_array($pre_node)) {
313 return (int) $pre_node["obj_id"];
314 }
315
316 return 0;
317 }
318}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isChapterWithoutActivePage()
Has current chapter no active page?
__construct(ilObjUser $user, int $request_obj_id, ilLMTree $lm_tree, ilObjLearningModule $lm, ilSetting $lm_set, string $requested_back_page, string $cmd, int $focus_id)
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _isPagePublic(int $a_node_id, bool $a_check_public_mode=false)
static _lookupType(int $a_obj_id, int $a_lm_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getLastAccessedPage(int $a_ref_id, int $a_user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
static _lookupActivationData(int $a_id, string $a_parent_type, string $a_lang="-")
Lookup activation data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static now()
Return current timestamp in Y-m-d H:i:s format.
const ANONYMOUS_USER_ID
Definition: constants.php:27
$path
Definition: ltiservices.php:32