ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 if ($this->cmd == "resume") {
97 if ($user->getId() != ANONYMOUS_USER_ID && ($this->focus_id == 0)) {
98 $last_accessed_page = ilObjLearningModuleAccess::_getLastAccessedPage($this->lm->getRefId(), $user->getId());
99 // if last accessed page was final page do nothing, start over
100 if ($last_accessed_page &&
101 $last_accessed_page != $this->lm_tree->getLastActivePage()) {
102 $obj_id = $last_accessed_page;
103 }
104 }
105 }
106 } else {
107 $obj_id = $requested_obj_id;
108 $active = ilLMPage::_lookupActive(
109 $obj_id,
110 $this->lm->getType(),
111 $this->lm_set->get("time_scheduled_page_activation")
112 );
113
114 if (!$active &&
115 ilLMPageObject::_lookupType($obj_id) == "pg") {
116 $this->deactivated_page = true;
117 }
118 }
119 // obj_id not in tree -> it is a unassigned page -> return page id
120 if (!$this->lm_tree->isInTree($obj_id)) {
121 $this->current_page_id = $obj_id;
122 return;
123 }
124 $curr_node = $this->lm_tree->getNodeData($obj_id);
125 $active = ilLMPage::_lookupActive(
126 $obj_id,
127 $this->lm->getType(),
128 (bool) $this->lm_set->get("time_scheduled_page_activation")
129 );
130 $show = $active;
131
132 // look, whether activation data should be shown
133 $act_data = ilLMPage::_lookupActivationData((int) $curr_node["obj_id"], $this->lm->getType());
134 if ($act_data["show_activation_info"] ?? false) {
135 $show = true;
136 }
137
138 if ($curr_node["type"] == "pg" &&
139 $show) { // page in tree -> return page id
140 $page_id = $curr_node["obj_id"];
141 } else { // no page -> search for next page and return its id
142 $succ_node = true;
143 $active = false;
144 $page_id = $obj_id;
145 while ($succ_node && !$active) {
146 $succ_node = $this->lm_tree->fetchSuccessorNode($page_id, "pg");
147 if (!is_null($succ_node)) {
148 $page_id = $succ_node["obj_id"];
149 $active = ilLMPage::_lookupActive(
150 $page_id,
151 $this->lm->getType(),
152 $this->lm_set->get("time_scheduled_page_activation")
153 );
154 if (!$active) {
155 // look, whether activation data should be shown
156 $act_data = ilLMPage::_lookupActivationData((int) $page_id, $this->lm->getType());
157 if ($act_data["show_activation_info"] ?? false) {
158 $active = true;
159 if (ilLMPageObject::_lookupType($page_id) == "pg") {
160 $this->deactivated_page = true;
161 }
162 }
163 }
164 }
165 }
166
167 if (is_null($succ_node) || $succ_node["type"] != "pg") {
168 $this->chapter_has_no_active_page = true;
169 $this->current_page_id = 0;
170 return;
171 }
172
173 // check whether page found is within "clicked" chapter
174 if ($this->lm_tree->isInTree($page_id)) {
175 $path = $this->lm_tree->getPathId($page_id);
176 if (!in_array($requested_obj_id, $path)) {
177 $this->chapter_has_no_active_page = true;
178 }
179 }
180 }
181
182 $this->current_page_id = $page_id;
183 }
184
185 public function getBackPageId(): int
186 {
187 $page_id = $this->current_page_id;
188
189 if (empty($page_id)) {
190 return 0;
191 }
192
194
195 // process navigation for free page
196 return $back_pg;
197 }
198
199 public function getSuccessorPageId(): int
200 {
201 $page_id = $this->current_page_id;
202 $user_id = $this->user->getId();
203 $succ_node = null;
204
205 // determine successor page_id
206 $found = false;
207
208 // empty chapter
209 if ($this->chapter_has_no_active_page &&
210 ilLMObject::_lookupType($this->requested_obj_id) == "st") {
212 } else {
213 if ($this->deactivated_page) {
215 } else {
216 $c_id = $page_id;
217 }
218 }
219 while (!$found) {
220 $succ_node = null;
221 if ($this->lm_tree->isInTree($c_id)) {
222 $succ_node = $this->lm_tree->fetchSuccessorNode($c_id, "pg");
223 }
224 if (is_array($succ_node)) {
225 $c_id = $succ_node["obj_id"];
226
227 $active = ilLMPage::_lookupActive(
228 $c_id,
229 $this->lm->getType(),
230 $this->lm_set->get("time_scheduled_page_activation")
231 );
232 }
233 if (is_array($succ_node) && $succ_node["obj_id"] > 0 && !$active) {
234 // look, whether activation data should be shown
235 $act_data = ilLMPage::_lookupActivationData((int) $succ_node["obj_id"], $this->lm->getType());
236 if ($act_data["show_activation_info"] &&
237 (ilUtil::now() < $act_data["activation_start"])) {
238 $found = true;
239 } else {
240 $found = false;
241 }
242 } else {
243 $found = true;
244 }
245 }
246 if (is_array($succ_node)) {
247 return (int) $succ_node["obj_id"];
248 }
249
250 return 0;
251 }
252
253 public function getPredecessorPageId(): int
254 {
255 $page_id = $this->current_page_id;
256 $user_id = $this->user->getId();
257 $pre_node = null;
258
259 // determine predecessor page id
260 $found = false;
261 if ($this->deactivated_page) {
263 } else {
264 $c_id = $page_id;
265 }
266 while (!$found) {
267 $pre_node = null;
268 if ($this->lm_tree->isInTree($c_id)) {
269 $pre_node = $this->lm_tree->fetchPredecessorNode($c_id, "pg");
270 }
271 if (is_array($pre_node)) {
272 $c_id = $pre_node["obj_id"];
273 $active = ilLMPage::_lookupActive(
274 $c_id,
275 $this->lm->getType(),
276 (bool) $this->lm_set->get("time_scheduled_page_activation")
277 );
278 }
279 if (is_array($pre_node) && $pre_node["obj_id"] > 0 && !$active) {
280 // look, whether activation data should be shown
281 $act_data = ilLMPage::_lookupActivationData((int) $pre_node["obj_id"], $this->lm->getType());
282 if ($act_data["show_activation_info"] &&
283 (ilUtil::now() < $act_data["activation_start"])) {
284 $found = true;
285 } else {
286 $found = false;
287 }
288 } else {
289 $found = true;
290 }
291 }
292 if (is_array($pre_node)) {
293 return (int) $pre_node["obj_id"];
294 }
295
296 return 0;
297 }
298}
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 _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.
ILIAS Setting Class.
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:30