ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLMNavigationStatus.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
15
19 protected $current_page_id = null;
20
24 protected $chapter_has_no_active_page = false;
25
29 protected $deactivated_page = false;
30
34 protected $lm;
35
39 protected $lm_tree;
40
44 protected $user;
45
49 protected $lm_set;
50
55
59 protected $cmd;
60
64 protected $focus_id;
65
70
81 public function __construct(
83 int $request_obj_id,
88 string $cmd,
89 int $focus_id
90 ) {
91 $this->user = $user;
92 $this->requested_obj_id = (int) $request_obj_id;
93 $this->lm_tree = $lm_tree;
94 $this->lm = $lm;
95 $this->lm_set = $lm_set;
96 $this->requested_back_page = (int) $requested_back_page;
97 $this->cmd = $cmd;
98 $this->focus_id = $focus_id;
99
100 $this->determineStatus();
101 }
102
109 {
111 }
112
118 public function isDeactivatedPage()
119 {
121 }
122
128 public function getCurrentPage()
129 {
131 }
132
133
137 protected function determineStatus()
138 {
140
141 $this->chapter_has_no_active_page = false;
142 $this->deactivated_page = false;
143
145 if ($requested_obj_id > 0 && ilLMObject::_lookupContObjID($requested_obj_id) != $this->lm->getId()) {
147 }
148
149 // determine object id
150 if ($requested_obj_id == 0) {
151 $obj_id = $this->lm_tree->getRootId();
152
153 if ($this->cmd == "resume") {
154 if ($user->getId() != ANONYMOUS_USER_ID && ((int) $this->focus_id == 0)) {
155 $last_accessed_page = ilObjLearningModuleAccess::_getLastAccessedPage($this->lm->getRefId(), $user->getId());
156 // if last accessed page was final page do nothing, start over
157 if ($last_accessed_page &&
158 $last_accessed_page != $this->lm_tree->getLastActivePage()) {
159 $obj_id = $last_accessed_page;
160 }
161 }
162 }
163 } else {
164 $obj_id = $requested_obj_id;
165 $active = ilLMPage::_lookupActive(
166 $obj_id,
167 $this->lm->getType(),
168 $this->lm_set->get("time_scheduled_page_activation")
169 );
170
171 if (!$active &&
172 ilLMPageObject::_lookupType($obj_id) == "pg") {
173 $this->deactivated_page = true;
174 }
175 }
176
177 // obj_id not in tree -> it is a unassigned page -> return page id
178 if (!$this->lm_tree->isInTree($obj_id)) {
179 $this->current_page_id = $obj_id;
180 return null;
181 }
182
183 $curr_node = $this->lm_tree->getNodeData($obj_id);
184
185 $active = ilLMPage::_lookupActive(
186 $obj_id,
187 $this->lm->getType(),
188 $this->lm_set->get("time_scheduled_page_activation")
189 );
190
191 if ($curr_node["type"] == "pg" &&
192 $active) { // page in tree -> return page id
193 $page_id = $curr_node["obj_id"];
194 } else { // no page -> search for next page and return its id
195 $succ_node = true;
196 $active = false;
197 $page_id = $obj_id;
198 while ($succ_node && !$active) {
199 $succ_node = $this->lm_tree->fetchSuccessorNode($page_id, "pg");
200 $page_id = $succ_node["obj_id"];
201 $active = ilLMPage::_lookupActive(
202 $page_id,
203 $this->lm->getType(),
204 $this->lm_set->get("time_scheduled_page_activation")
205 );
206 }
207
208 if ($succ_node["type"] != "pg") {
209 $this->chapter_has_no_active_page = true;
210 $this->current_page_id = 0;
211 return null;
212 }
213
214 // if public access get first public page in chapter
215 if ($user->getId() == ANONYMOUS_USER_ID &&
216 $this->lm->getPublicAccessMode() == 'selected') {
217 $public = ilLMObject::_isPagePublic($page_id);
218
219 while ($public === false && $page_id > 0) {
220 $succ_node = $this->lm_tree->fetchSuccessorNode($page_id, 'pg');
221 $page_id = $succ_node['obj_id'];
222 $public = ilLMObject::_isPagePublic($page_id);
223 }
224 }
225
226 // check whether page found is within "clicked" chapter
227 if ($this->lm_tree->isInTree($page_id)) {
228 $path = $this->lm_tree->getPathId($page_id);
229 if (!in_array($requested_obj_id, $path)) {
230 $this->chapter_has_no_active_page = true;
231 }
232 }
233 }
234
235 $this->current_page_id = $page_id;
236 }
237
242 public function getBackPageId() : int
243 {
244 $page_id = $this->current_page_id;
245
246 if (empty($page_id)) {
247 return 0;
248 }
249
251
252 // process navigation for free page
253 if (!$this->lm_tree->isInTree($page_id)) {
254 return $back_pg;
255 }
256 return $back_pg;
257 }
258
262 public function getSuccessorPageId() : int
263 {
264 $page_id = $this->current_page_id;
265 $user_id = $this->user->getId();
266
267 // determine successor page_id
268 $found = false;
269
270 // empty chapter
271 if ($this->chapter_has_no_active_page &&
272 ilLMObject::_lookupType($this->requested_obj_id) == "st") {
274 } else {
275 if ($this->deactivated_page) {
277 } else {
278 $c_id = $page_id;
279 }
280 }
281 while (!$found) {
282 $succ_node = $this->lm_tree->fetchSuccessorNode($c_id, "pg");
283 $c_id = $succ_node["obj_id"];
284
285 $active = ilLMPage::_lookupActive(
286 $c_id,
287 $this->lm->getType(),
288 $this->lm_set->get("time_scheduled_page_activation")
289 );
290
291 if ($succ_node["obj_id"] > 0 &&
292 $user_id == ANONYMOUS_USER_ID &&
293 ($this->lm->getPublicAccessMode() == "selected" &&
294 !ilLMObject::_isPagePublic($succ_node["obj_id"]))) {
295 $found = false;
296 } else {
297 if ($succ_node["obj_id"] > 0 && !$active) {
298 // look, whether activation data should be shown
299 $act_data = ilLMPage::_lookupActivationData((int) $succ_node["obj_id"], $this->lm->getType());
300 if ($act_data["show_activation_info"] &&
301 (ilUtil::now() < $act_data["activation_start"])) {
302 $found = true;
303 } else {
304 $found = false;
305 }
306 } else {
307 $found = true;
308 }
309 }
310 }
311 if (is_array($succ_node)) {
312 return (int) $succ_node["obj_id"];
313 }
314
315 return 0;
316 }
317
322 public function getPredecessorPageId() : int
323 {
324 $page_id = $this->current_page_id;
325 $user_id = $this->user->getId();
326
327 // determine predecessor page id
328 $found = false;
329 if ($this->deactivated_page) {
331 } else {
332 $c_id = $page_id;
333 }
334 while (!$found) {
335 $pre_node = $this->lm_tree->fetchPredecessorNode($c_id, "pg");
336 $c_id = $pre_node["obj_id"];
337 $active = ilLMPage::_lookupActive(
338 $c_id,
339 $this->lm->getType(),
340 $this->lm_set->get("time_scheduled_page_activation")
341 );
342 if ($pre_node["obj_id"] > 0 &&
343 $user_id == ANONYMOUS_USER_ID &&
344 ($this->lm->getPublicAccessMode() == "selected" &&
345 !ilLMObject::_isPagePublic($pre_node["obj_id"]))) {
346 $found = false;
347 } else {
348 if ($pre_node["obj_id"] > 0 && !$active) {
349 // look, whether activation data should be shown
350 $act_data = ilLMPage::_lookupActivationData((int) $pre_node["obj_id"], $this->lm->getType());
351 if ($act_data["show_activation_info"] &&
352 (ilUtil::now() < $act_data["activation_start"])) {
353 $found = true;
354 } else {
355 $found = false;
356 }
357 } else {
358 $found = true;
359 }
360 }
361 }
362 if (is_array($pre_node)) {
363 return (int) $pre_node["obj_id"];
364 }
365
366 return 0;
367 }
368}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Checks current navigation request status.
__construct(ilObjUser $user, int $request_obj_id, ilLMTree $lm_tree, ilObjLearningModule $lm, ilSetting $lm_set, $requested_back_page, string $cmd, int $focus_id)
Constructor.
getCurrentPage()
Has current chapter no avtive page?
isDeactivatedPage()
Has current chapter no avtive page?
isChapterWithoutActivePage()
Has current chapter no avtive page?
getPredecessorPageId()
Get predecessor page id.
getBackPageId()
Get back link page id.
static _lookupType($a_obj_id, $a_lm_id=0)
Lookup type.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static _isPagePublic($a_node_id, $a_check_public_mode=false)
static _getLastAccessedPage($a_ref_id, $a_user_id="")
get last accessed page
Class ilObjLearningModule.
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
static _lookupActivationData($a_id, $a_parent_type, $a_lang="-")
Lookup activation data.
ILIAS Setting Class.
static now()
Return current timestamp in Y-m-d H:i:s format.
const ANONYMOUS_USER_ID
Definition: constants.php:25