ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPObjSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 protected int $obj_id;
29 protected string $obj_type;
30 protected int $obj_mode;
32
33 protected bool $is_stored = false;
34
35 public const LP_MODE_DEACTIVATED = 0;
36 public const LP_MODE_TLT = 1;
37 public const LP_MODE_VISITS = 2;
38 public const LP_MODE_MANUAL = 3;
39 public const LP_MODE_OBJECTIVES = 4;
40 public const LP_MODE_COLLECTION = 5;
41 public const LP_MODE_SCORM = 6;
42 public const LP_MODE_TEST_FINISHED = 7;
43 public const LP_MODE_TEST_PASSED = 8;
44 public const LP_MODE_EXERCISE_RETURNED = 9;
45 public const LP_MODE_EVENT = 10;
46 public const LP_MODE_MANUAL_BY_TUTOR = 11;
47 public const LP_MODE_SCORM_PACKAGE = 12;
48 public const LP_MODE_UNDEFINED = 13;
49 public const LP_MODE_PLUGIN = 14;
50 public const LP_MODE_COLLECTION_TLT = 15;
51 public const LP_MODE_COLLECTION_MANUAL = 16;
52 public const LP_MODE_QUESTIONS = 17;
53 public const LP_MODE_SURVEY_FINISHED = 18;
54 public const LP_MODE_VISITED_PAGES = 19;
55 public const LP_MODE_CONTENT_VISITED = 20;
56 public const LP_MODE_COLLECTION_MOBS = 21;
57 public const LP_MODE_STUDY_PROGRAMME = 22;
59 public const LP_MODE_CMIX_COMPLETED = 24;
61 public const LP_MODE_CMIX_PASSED = 26;
65 public const LP_MODE_LTI_OUTCOME = 31;
66 public const LP_MODE_COURSE_REFERENCE = 32;
68
69 public const LP_DEFAULT_VISITS = 30;
70
71 protected static array $map = array(
72
73 self::LP_MODE_DEACTIVATED => array('ilLPStatus',
74 'trac_mode_deactivated',
75 'trac_mode_deactivated_info_new'
76 )
77
78 ,
79 self::LP_MODE_TLT => array('ilLPStatusTypicalLearningTime',
80 'trac_mode_tlt',
81 'trac_mode_tlt_info'
82 ) // info has dynamic part!
83
84 ,
85 self::LP_MODE_VISITS => array('ilLPStatusVisits',
86 'trac_mode_visits',
87 'trac_mode_visits_info'
88 )
89
90 ,
91 self::LP_MODE_MANUAL => array('ilLPStatusManual',
92 'trac_mode_manual',
93 'trac_mode_manual_info'
94 )
95
96 ,
97 self::LP_MODE_OBJECTIVES => array('ilLPStatusObjectives',
98 'trac_mode_objectives',
99 'trac_mode_objectives_info'
100 )
101
102 ,
103 self::LP_MODE_COLLECTION => array('ilLPStatusCollection',
104 'trac_mode_collection',
105 'trac_mode_collection_info'
106 )
107
108 ,
109 self::LP_MODE_SCORM => array('ilLPStatusSCORM',
110 'trac_mode_scorm',
111 'trac_mode_scorm_info'
112 )
113
114 ,
115 self::LP_MODE_TEST_FINISHED => array('ilLPStatusTestFinished',
116 'trac_mode_test_finished',
117 'trac_mode_test_finished_info'
118 )
119
120 ,
121 self::LP_MODE_TEST_PASSED => array('ilLPStatusTestPassed',
122 'trac_mode_test_passed',
123 'trac_mode_test_passed_info'
124 )
125
126 ,
127 self::LP_MODE_EXERCISE_RETURNED => array('ilLPStatusExerciseReturned',
128 'trac_mode_exercise_returned',
129 'trac_mode_exercise_returned_info'
130 )
131
132 ,
133 self::LP_MODE_EVENT => array('ilLPStatusEvent',
134 'trac_mode_event',
135 'trac_mode_event_info'
136 )
137
138 ,
139 self::LP_MODE_MANUAL_BY_TUTOR => array('ilLPStatusManualByTutor',
140 'trac_mode_manual_by_tutor',
141 'trac_mode_manual_by_tutor_info'
142 )
143
144 ,
145 self::LP_MODE_SCORM_PACKAGE => array('ilLPStatusSCORMPackage',
146 'trac_mode_scorm_package',
147 'trac_mode_scorm_package_info'
148 )
149
150 ,
151 self::LP_MODE_UNDEFINED => null
152
153 ,
154 self::LP_MODE_PLUGIN => array('ilLPStatusPlugin',
155 'trac_mode_plugin',
156 ''
157 ) // no settings screen, so no info needed
158
159 ,
160 self::LP_MODE_COLLECTION_TLT => array('ilLPStatusCollectionTLT',
161 'trac_mode_collection_tlt',
162 'trac_mode_collection_tlt_info'
163 )
164
165 ,
166 self::LP_MODE_COLLECTION_MANUAL => array('ilLPStatusCollectionManual',
167 'trac_mode_collection_manual',
168 'trac_mode_collection_manual_info'
169 )
170
171 ,
172 self::LP_MODE_QUESTIONS => array('ilLPStatusQuestions',
173 'trac_mode_questions',
174 'trac_mode_questions_info'
175 )
176
177 ,
178 self::LP_MODE_SURVEY_FINISHED => array('ilLPStatusSurveyFinished',
179 'trac_mode_survey_finished',
180 'trac_mode_survey_finished_info'
181 )
182
183 ,
184 self::LP_MODE_VISITED_PAGES => array('ilLPStatusVisitedPages',
185 'trac_mode_visited_pages',
186 'trac_mode_visited_pages_info'
187 )
188
189 ,
190 self::LP_MODE_CONTENT_VISITED => array('ilLPStatusContentVisited',
191 'trac_mode_content_visited',
192 'trac_mode_content_visited_info'
193 )
194
195 ,
196 self::LP_MODE_COLLECTION_MOBS => array('ilLPStatusCollectionMobs',
197 'trac_mode_collection_mobs',
198 'trac_mode_collection_mobs_info'
199 )
200
201 ,
202 self::LP_MODE_STUDY_PROGRAMME => array('ilLPStatusStudyProgramme',
203 'trac_mode_study_programme',
204 ''
205 )
206
207 ,
208 self::LP_MODE_INDIVIDUAL_ASSESSMENT => array('ilLPStatusIndividualAssessment',
209 'trac_mode_individual_assessment',
210 'trac_mode_individual_assessment_info'
211 )
212
213 ,
214 self::LP_MODE_CMIX_COMPLETED => array(ilLPStatusCmiXapiCompleted::class,
215 'trac_mode_cmix_completed',
216 'trac_mode_cmix_completed_info'
217 )
218
219 ,
220 self::LP_MODE_CMIX_COMPL_WITH_FAILED => array(ilLPStatusCmiXapiCompletedWithFailed::class,
221 'trac_mode_cmix_compl_with_failed',
222 'trac_mode_cmix_compl_with_failed_info'
223 )
224
225 ,
226 self::LP_MODE_CMIX_PASSED => array(ilLPStatusCmiXapiPassed::class,
227 'trac_mode_cmix_passed',
228 'trac_mode_cmix_passed_info'
229 )
230
231 ,
232 self::LP_MODE_CMIX_PASSED_WITH_FAILED => array(ilLPStatusCmiXapiPassedWithFailed::class,
233 'trac_mode_cmix_passed_with_failed',
234 'trac_mode_cmix_passed_with_failed_info'
235 )
236
237 ,
238 self::LP_MODE_CMIX_COMPLETED_OR_PASSED => array(ilLPStatusCmiXapiCompletedOrPassed::class,
239 'trac_mode_cmix_completed_or_passed',
240 'trac_mode_cmix_completed_or_passed_info'
241 )
242
243 ,
244 self::LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED => array(ilLPStatusCmiXapiCompletedOrPassedWithFailed::class,
245 'trac_mode_cmix_compl_or_passed_with_failed',
246 'trac_mode_cmix_compl_or_passed_with_failed_info'
247 )
248
249 ,
250 self::LP_MODE_LTI_OUTCOME => array(ilLPStatusLtiOutcome::class,
251 'trac_mode_lti_outcome',
252 'trac_mode_lti_outcome_info'
253 )
254
255 ,
256 self::LP_MODE_COURSE_REFERENCE => [
257 'ilLPStatusCourseReference',
258 'trac_mode_course_reference',
259 'trac_mode_course_reference_info'
260 ],
261
262 self::LP_MODE_CONTRIBUTION_TO_DISCUSSION => [
263 ilLPStatusContributionToDiscussion::class,
264 'trac_mode_contribution_to_discussion',
265 'trac_mode_contribution_to_discussion_info'
266 ],
267 );
268
271
272 public function __construct(int $a_obj_id)
273 {
274 global $DIC;
275
276 $this->db = $DIC->database();
277 $this->objectDataCache = $DIC['ilObjDataCache'];
278
279 $this->obj_id = $a_obj_id;
280
281 if (!$this->read()) {
282 $this->obj_type = $this->objectDataCache->lookupType($this->obj_id);
283
284 $olp = ilObjectLP::getInstance($this->obj_id);
285 $this->obj_mode = $olp->getDefaultMode();
286 }
287 }
288
294 public function cloneSettings(int $a_new_obj_id): bool
295 {
296 global $DIC;
297
298 $ilDB = $DIC['ilDB'];
299
300 $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) " .
301 "VALUES( " .
302 $this->db->quote($a_new_obj_id, 'integer') . ", " .
303 $this->db->quote($this->getObjType(), 'text') . ", " .
304 $this->db->quote($this->getMode(), 'integer') . ", " .
305 $this->db->quote($this->getVisits(), 'integer') .
306 ")";
307 $res = $this->db->manipulate($query);
308 return true;
309 }
310
311 public function getVisits(): int
312 {
313 return $this->visits;
314 }
315
316 public function setVisits(int $a_visits): void
317 {
318 $this->visits = $a_visits;
319 }
320
321 public function setMode(int $a_mode): void
322 {
323 $this->obj_mode = $a_mode;
324 }
325
326 public function getMode(): int
327 {
328 return $this->obj_mode;
329 }
330
331 public function getObjId(): int
332 {
333 return $this->obj_id;
334 }
335
336 public function getObjType(): string
337 {
338 return $this->obj_type;
339 }
340
341 public function read(): bool
342 {
343 $res = $this->db->query(
344 "SELECT * FROM ut_lp_settings WHERE obj_id = " .
345 $this->db->quote($this->obj_id, 'integer')
346 );
347 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
348 $this->is_stored = true;
349 $this->obj_type = (string) $row->obj_type;
350 $this->obj_mode = (int) $row->u_mode;
351 $this->visits = (int) $row->visits;
352 return true;
353 }
354 return false;
355 }
356
357 public function update(bool $a_refresh_lp = true): bool
358 {
359 if (!$this->is_stored) {
360 return $this->insert();
361 }
362 $query = "UPDATE ut_lp_settings SET u_mode = " . $this->db->quote(
363 $this->getMode(),
364 'integer'
365 ) . ", " .
366 "visits = " . $this->db->quote(
367 $this->getVisits(),
368 'integer'
369 ) . " " .
370 "WHERE obj_id = " . $this->db->quote($this->getObjId(), 'integer');
371 $res = $this->db->manipulate($query);
372 $this->read();
373
374 if ($a_refresh_lp) {
375 $this->doLPRefresh();
376 }
377 return true;
378 }
379
380 public function insert(): bool
381 {
382 $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) " .
383 "VALUES(" .
384 $this->db->quote($this->getObjId(), 'integer') . ", " .
385 $this->db->quote($this->getObjType(), 'text') . ", " .
386 $this->db->quote($this->getMode(), 'integer') . ", " .
387 $this->db->quote($this->getVisits(), 'integer') . // #12482
388 ")";
389 $res = $this->db->manipulate($query);
390 $this->read();
391 $this->doLPRefresh();
392 return true;
393 }
394
395 protected function doLPRefresh(): void
396 {
397 // refresh learning progress
399 }
400
401 public static function _delete(int $a_obj_id): bool
402 {
403 global $DIC;
404
405 $ilDB = $DIC['ilDB'];
406 $query = "DELETE FROM ut_lp_settings WHERE obj_id = " . $ilDB->quote(
407 $a_obj_id,
408 'integer'
409 );
410 $res = $ilDB->manipulate($query);
411 return true;
412 }
413
414 public static function _lookupVisits(int $a_obj_id): int
415 {
416 global $DIC;
417
418 $ilDB = $DIC['ilDB'];
419 $query = "SELECT visits FROM ut_lp_settings " .
420 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
421
422 $res = $ilDB->query($query);
423 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
424 return $row->visits;
425 }
427 }
428
429 public static function _lookupDBModeForObjects(array $a_obj_ids): array
430 {
431 global $DIC;
432
433 $ilDB = $DIC['ilDB'];
434 // this does NOT handle default mode!
435 $res = array();
436 $query = "SELECT obj_id, u_mode FROM ut_lp_settings" .
437 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer");
438 $set = $ilDB->query($query);
439 while ($row = $set->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
440 $res[(int) $row->obj_id] = (int) $row->u_mode;
441 }
442 return $res;
443 }
444
445 public static function _lookupDBMode(int $a_obj_id): ?int
446 {
447 global $DIC;
448
449 $ilDB = $DIC['ilDB'];
450 // this does NOT handle default mode!
451 $query = "SELECT u_mode FROM ut_lp_settings" .
452 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
453 $res = $ilDB->query($query);
454 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
455 return (int) $row->u_mode;
456 }
457 return null;
458 }
459
460 public static function _mode2Text(int $a_mode): string
461 {
462 global $DIC;
463
464 $lng = $DIC->language();
465 if (array_key_exists($a_mode, self::$map) &&
466 is_array(self::$map[$a_mode])) {
467 return $lng->txt(self::$map[$a_mode][1]);
468 }
469 return '';
470 }
471
472 public static function _mode2InfoText(int $a_mode): string
473 {
474 global $DIC;
475
476 $lng = $DIC->language();
477 if (array_key_exists($a_mode, self::$map) &&
478 is_array(self::$map[$a_mode])) {
479 $info = $lng->txt(self::$map[$a_mode][2]);
480 if ($a_mode == self::LP_MODE_TLT) {
481 // dynamic content
483 }
484 return $info;
485 }
486 return '';
487 }
488
489 public static function getClassMap(): array
490 {
491 $res = array();
492 foreach (self::$map as $mode => $item) {
493 if ($item) {
494 $res[$mode] = $item[0];
495 }
496 }
497 return $res;
498 }
499
500 public static function _deleteByObjId(int $a_obj_id): void
501 {
502 global $DIC;
503
504 $ilDB = $DIC['ilDB'];
505 // we are only removing settings for now
506 // invalid ut_lp_collections-entries are filtered
507 // ut_lp_marks is deemed private user data
508
509 $ilDB->manipulate(
510 "DELETE FROM ut_lp_settings" .
511 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer")
512 );
513 }
514}
static _delete(int $a_obj_id)
static _lookupDBMode(int $a_obj_id)
const LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED
static _mode2InfoText(int $a_mode)
static _deleteByObjId(int $a_obj_id)
update(bool $a_refresh_lp=true)
setVisits(int $a_visits)
static _mode2Text(int $a_mode)
static _lookupVisits(int $a_obj_id)
const LP_MODE_CONTRIBUTION_TO_DISCUSSION
static _lookupDBModeForObjects(array $a_obj_ids)
ilObjectDataCache $objectDataCache
cloneSettings(int $a_new_obj_id)
Clone settings @access public.
__construct(int $a_obj_id)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
class ilObjectDataCache
static getInstance(int $obj_id)
$info
Definition: entry_point.php:21
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26