ILIAS  release_8 Revision v8.24
class.ilLPStatus.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
29{
30 protected int $obj_id;
31
32 protected ilDBInterface $db;
34
35 public static $list_gui_cache;
36
37 public const LP_STATUS_NOT_ATTEMPTED = 'trac_no_attempted';
38 public const LP_STATUS_IN_PROGRESS = 'trac_in_progress';
39 public const LP_STATUS_COMPLETED = 'trac_completed';
40 public const LP_STATUS_FAILED = 'trac_failed';
41
43 public const LP_STATUS_IN_PROGRESS_NUM = 1;
44 public const LP_STATUS_COMPLETED_NUM = 2;
45 public const LP_STATUS_FAILED_NUM = 3;
46
47 public const LP_STATUS_REGISTERED = 'trac_registered';
48 public const LP_STATUS_NOT_REGISTERED = 'trac_not_registered';
49 public const LP_STATUS_PARTICIPATED = 'trac_participated';
50 public const LP_STATUS_NOT_PARTICIPATED = 'trac_not_participated';
51
52 public function __construct(int $a_obj_id)
53 {
54 global $DIC;
55
56 $this->obj_id = $a_obj_id;
57 $this->db = $DIC->database();
58 $this->ilObjDataCache = $DIC['ilObjDataCache'];
59 }
60
61 public static function _getCountNotAttempted(int $a_obj_id): int
62 {
63 return 0;
64 }
65
70 public static function _getNotAttempted(int $a_obj_id): array
71 {
72 return array();
73 }
74
75 public static function _getCountInProgress(int $a_obj_id): int
76 {
77 return 0;
78 }
79
80 public static function _getInProgress(int $a_obj_id): array
81 {
82 return array();
83 }
84
85 public static function _getCountCompleted(int $a_obj_id): int
86 {
87 return 0;
88 }
89
94 public static function _getCompleted(int $a_obj_id): array
95 {
96 return array();
97 }
98
103 public static function _getFailed(int $a_obj_id): array
104 {
105 return array();
106 }
107
108 public static function _getCountFailed(int $a_obj_id): int
109 {
110 return 0;
111 }
112
113 public static function _getStatusInfo(int $a_obj_id): array
114 {
115 return array();
116 }
117
118 public static function _getTypicalLearningTime(int $a_obj_id): int
119 {
121 }
122
212 public function _updateStatus(
213 int $a_obj_id,
214 int $a_usr_id,
215 ?object $a_obj = null,
216 bool $a_percentage = false,
217 bool $a_force_raise = false
218 ): void {
219 $log = ilLoggerFactory::getLogger('trac');
220 $log->debug(
221 sprintf(
222 "obj_id: %s, user id: %s, object: %s",
223 $a_obj_id,
224 $a_usr_id,
225 (is_object($a_obj) ? get_class($a_obj) : 'null')
226 )
227 );
228
229 $status = $this->determineStatus($a_obj_id, $a_usr_id, $a_obj);
230 $percentage = $this->determinePercentage($a_obj_id, $a_usr_id, $a_obj);
232 $changed = self::writeStatus(
233 $a_obj_id,
234 $a_usr_id,
235 $status,
236 $percentage,
237 false,
238 $old_status
239 );
240
241 // ak: I don't think that this is a good way to fix 15529, we should not
242 // raise the event, if the status does not change imo.
243 // for now the changes in the next line just prevent the event being raised twice
244 if (!$changed && $a_force_raise) { // #15529
246 $a_obj_id,
247 $a_usr_id,
248 $status,
249 $old_status,
250 $percentage
251 );
252 }
253 }
254
255 public function determinePercentage(
256 int $a_obj_id,
257 int $a_usr_id,
258 ?object $a_obj = null
259 ): int {
260 return 0;
261 }
262
263 public function determineStatus(
264 int $a_obj_id,
265 int $a_usr_id,
266 object $a_obj = null
267 ): int {
268 return 0;
269 }
270
277 public static function checkStatusForObject(
278 int $a_obj_id,
279 ?array $a_users = null
280 ): void {
281 global $DIC;
282
283 $ilDB = $DIC['ilDB'];
284
285 //@todo: there maybe the need to add extra handling for sessions here, since the
286 // "in progress" status is time dependent here. On the other hand, if they registered
287 // to the session, they already accessed the course and should have a "in progress"
288 // anyway. But the status on the session itself may not be correct.
289
290 $sql = "SELECT usr_id FROM ut_lp_marks WHERE " .
291 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
292 " status_dirty = " . $ilDB->quote(1, "integer");
293 if (is_array($a_users) && count($a_users) > 0) {
294 $sql .= " AND " . $ilDB->in("usr_id", $a_users, false, "integer");
295 }
296 $set = $ilDB->query($sql);
297 $dirty = false;
298 if ($rec = $ilDB->fetchAssoc($set)) {
299 $dirty = true;
300 }
301
302 // check if any records are missing
303 $missing = false;
304 if (!$dirty && is_array($a_users) && count($a_users) > 0) {
305 $set = $ilDB->query(
306 "SELECT count(usr_id) cnt FROM ut_lp_marks WHERE " .
307 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
308 $ilDB->in("usr_id", $a_users, false, "integer")
309 );
310 $r = $ilDB->fetchAssoc($set);
311 if ($r["cnt"] < count($a_users)) {
312 $missing = true;
313 }
314 }
315
316 // refresh status, if records are dirty or missing
317 if ($dirty || $missing) {
318 $trac_obj = ilLPStatusFactory::_getInstance($a_obj_id);
319 $trac_obj->refreshStatus($a_obj_id, $a_users);
320 }
321 }
322
323 protected static function raiseEvent(
324 int $a_obj_id,
325 int $a_usr_id,
326 int $a_status,
327 int $a_old_status,
328 int $a_percentage
329 ): void {
330 global $DIC;
331
332 $ilAppEventHandler = $DIC['ilAppEventHandler'];
333
335 $log->debug(
336 "obj_id: " . $a_obj_id . ", user id: " . $a_usr_id . ", status: " .
337 $a_status . ", percentage: " . $a_percentage
338 );
339
340 $ilAppEventHandler->raise(
341 "Services/Tracking",
342 "updateStatus",
343 array(
344 "obj_id" => $a_obj_id,
345 "usr_id" => $a_usr_id,
346 "status" => $a_status,
347 "old_status" => $a_old_status,
348 "percentage" => $a_percentage
349 )
350 );
351 }
352
356 public function refreshStatus(int $a_obj_id, ?array $a_users = null): void
357 {
358 $not_attempted = ilLPStatusWrapper::_getNotAttempted($a_obj_id);
359 foreach ($not_attempted as $user_id) {
360 $percentage = $this->determinePercentage($a_obj_id, $user_id);
361 if (self::writeStatus(
362 $a_obj_id,
363 $user_id,
364 self::LP_STATUS_NOT_ATTEMPTED_NUM,
365 $percentage,
366 true
367 )) {
368 //self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_NOT_ATTEMPTED_NUM, $percentage);
369 }
370 }
371 $in_progress = ilLPStatusWrapper::_getInProgress($a_obj_id);
372 foreach ($in_progress as $user_id) {
373 $percentage = $this->determinePercentage($a_obj_id, $user_id);
374 if (self::writeStatus(
375 $a_obj_id,
376 $user_id,
377 self::LP_STATUS_IN_PROGRESS_NUM,
378 $percentage,
379 true
380 )) {
381 //self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_IN_PROGRESS_NUM, $percentage);
382 }
383 }
384 $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
385 foreach ($completed as $user_id) {
386 $percentage = $this->determinePercentage($a_obj_id, $user_id);
387 if (self::writeStatus(
388 $a_obj_id,
389 $user_id,
390 self::LP_STATUS_COMPLETED_NUM,
391 $percentage,
392 true
393 )) {
394 //self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_COMPLETED_NUM, $percentage);
395 }
396 }
397 $failed = ilLPStatusWrapper::_getFailed($a_obj_id);
398 foreach ($failed as $user_id) {
399 $percentage = $this->determinePercentage($a_obj_id, $user_id);
400 if (self::writeStatus(
401 $a_obj_id,
402 $user_id,
403 self::LP_STATUS_FAILED_NUM,
404 $percentage,
405 true
406 )) {
407 //self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_FAILED_NUM, $percentage);
408 }
409 }
410 if ($a_users) {
411 $missing_users = array_diff(
412 $a_users,
413 $not_attempted + $in_progress + $completed + $failed
414 );
415 if ($missing_users) {
416 foreach ($missing_users as $user_id) {
417 ilLPStatusWrapper::_updateStatus($a_obj_id, $user_id);
418 }
419 }
420 }
421 }
422
426 public static function writeStatus(
427 int $a_obj_id,
428 int $a_user_id,
429 int $a_status,
430 int $a_percentage = 0,
431 bool $a_force_per = false,
432 ?int &$a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM
433 ): bool {
434 global $DIC;
435
436 $ilDB = $DIC->database();
437 $log = $DIC->logger()->trac();
438
439 $log->debug(
440 'Write status for: ' . "obj_id: " . $a_obj_id . ", user id: " . $a_user_id . ", status: " . $a_status . ", percentage: " . $a_percentage . ", force: " . $a_force_per
441 );
442 $update_dependencies = false;
443
444 $a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
445
446 // get status in DB
447 $set = $ilDB->query(
448 "SELECT usr_id,status,status_dirty FROM ut_lp_marks WHERE " .
449 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
450 " usr_id = " . $ilDB->quote($a_user_id, "integer")
451 );
452 $rec = $ilDB->fetchAssoc($set);
453
454 // update
455 if ($rec) {
456 $a_old_status = $rec["status"];
457
458 // status has changed: update
459 if ($rec["status"] != $a_status) {
460 $ret = $ilDB->manipulate(
461 "UPDATE ut_lp_marks SET " .
462 " status = " . $ilDB->quote($a_status, "integer") . "," .
463 " status_changed = " . $ilDB->now() . "," .
464 " status_dirty = " . $ilDB->quote(0, "integer") .
465 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
466 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
467 );
468 if ($ret != 0) {
469 $update_dependencies = true;
470 }
471 } // status has not changed: reset dirty flag
472 elseif ($rec["status_dirty"]) {
473 $ilDB->manipulate(
474 "UPDATE ut_lp_marks SET " .
475 " status_dirty = " . $ilDB->quote(0, "integer") .
476 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
477 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
478 );
479 }
480 } // insert
481 else {
482 // #13783
483 $ilDB->replace(
484 "ut_lp_marks",
485 array(
486 "obj_id" => array("integer", $a_obj_id),
487 "usr_id" => array("integer", $a_user_id)
488 ),
489 array(
490 "status" => array("integer", $a_status),
491 "status_changed" => array("timestamp", date("Y-m-d H:i:s")),
492 // was $ilDB->now()
493 "status_dirty" => array("integer", 0)
494 )
495 );
496
497 $update_dependencies = true;
498 }
499
500 // update percentage
501 if ($a_percentage || $a_force_per) {
502 $a_percentage = max(0, $a_percentage);
503 $a_percentage = min(100, $a_percentage);
504 $ret = $ilDB->manipulate(
505 "UPDATE ut_lp_marks SET " .
506 " percentage = " . $ilDB->quote($a_percentage, "integer") .
507 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
508 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
509 );
510 }
511
512 $log->debug(
513 'Update dependecies is ' . ($update_dependencies ? 'true' : 'false')
514 );
515
516 // update collections
517 if ($update_dependencies) {
518 $log->debug('update dependencies');
519
520 // a change occured - remove existing cache entry
521 ilLPStatusWrapper::_removeStatusCache($a_obj_id, $a_user_id);
522
523 $set = $ilDB->query(
524 "SELECT ut_lp_collections.obj_id obj_id FROM " .
525 "object_reference JOIN ut_lp_collections ON " .
526 "(object_reference.obj_id = " . $ilDB->quote(
527 $a_obj_id,
528 "integer"
529 ) .
530 " AND object_reference.ref_id = ut_lp_collections.item_id)"
531 );
532 while ($rec = $ilDB->fetchAssoc($set)) {
533 if (in_array(
534 ilObject::_lookupType($rec["obj_id"]),
535 array("crs", "grp", "fold")
536 )) {
537 $log->debug(
538 'Calling update status for collection obj_id: ' . $rec['obj_id']
539 );
540 // just to make sure - remove existing cache entry
542 (int) $rec["obj_id"],
543 $a_user_id
544 );
546 (int) $rec["obj_id"],
547 $a_user_id
548 );
549 }
550 }
551
552 // find all course references
553 if (ilObject::_lookupType($a_obj_id) == 'crs') {
554 $log->debug('update references');
555
556 $query = 'select obj_id from container_reference ' .
557 'where target_obj_id = ' . $ilDB->quote(
558 $a_obj_id,
560 );
561 $res = $ilDB->query($query);
562 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
563 $log->debug(
564 'Calling update status for reference obj_id: ' . $row->obj_id
565 );
567 (int) $row->obj_id,
568 $a_user_id
569 );
571 (int) $row->obj_id,
572 $a_user_id
573 );
574 }
575 }
576
577 self::raiseEvent(
578 $a_obj_id,
579 $a_user_id,
580 $a_status,
581 $a_old_status,
582 $a_percentage
583 );
584 }
585
586 return $update_dependencies;
587 }
588
594 public static function setInProgressIfNotAttempted(
595 int $a_obj_id,
596 int $a_user_id
597 ): void {
598 global $DIC;
599
600 $ilDB = $DIC['ilDB'];
601
602 // #11513
603
604 $needs_update = false;
605
606 $set = $ilDB->query(
607 "SELECT usr_id, status FROM ut_lp_marks WHERE " .
608 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
609 " usr_id = " . $ilDB->quote($a_user_id, "integer")
610 );
611 if ($rec = $ilDB->fetchAssoc($set)) {
612 // current status is not attempted, so we need to update
613 if ($rec["status"] == self::LP_STATUS_NOT_ATTEMPTED_NUM) {
614 $needs_update = true;
615 }
616 } else {
617 // no ut_lp_marks yet, we should update
618 $needs_update = true;
619 }
620
621 if ($needs_update) {
622 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
623 }
624 }
625
629 public static function setAllDirty(): void
630 {
631 global $DIC;
632
633 $ilDB = $DIC['ilDB'];
634
635 $ilDB->manipulate(
636 "UPDATE ut_lp_marks SET " .
637 " status_dirty = " . $ilDB->quote(1, "integer")
638 );
639 }
640
644 public static function setDirty(int $a_obj_id): void
645 {
646 global $DIC;
647
648 $ilDB = $DIC['ilDB'];
649
650 $ilDB->manipulate(
651 "UPDATE ut_lp_marks SET " .
652 " status_dirty = " . $ilDB->quote(1, "integer") .
653 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer")
654 );
655 }
656
660 public static function _lookupStatus(
661 int $a_obj_id,
662 int $a_user_id,
663 bool $a_create = true
664 ): ?int {
665 global $DIC;
666
667 $ilDB = $DIC['ilDB'];
668
669 $set = $ilDB->query(
670 "SELECT status FROM ut_lp_marks WHERE " .
671 " status_dirty = " . $ilDB->quote(0, "integer") .
672 " AND usr_id = " . $ilDB->quote($a_user_id, "integer") .
673 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
674 );
675 if ($rec = $ilDB->fetchAssoc($set)) {
676 return (int) $rec["status"];
677 } elseif ($a_create) {
678 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
679 $set = $ilDB->query(
680 "SELECT status FROM ut_lp_marks WHERE " .
681 " status_dirty = " . $ilDB->quote(0, "integer") .
682 " AND usr_id = " . $ilDB->quote($a_user_id, "integer") .
683 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
684 );
685 if ($rec = $ilDB->fetchAssoc($set)) {
686 return (int) $rec["status"];
687 }
688 }
689 return null;
690 }
691
695 public static function _lookupPercentage(
696 int $a_obj_id,
697 int $a_user_id
698 ): ?int {
699 global $DIC;
700
701 $ilDB = $DIC['ilDB'];
702
703 $set = $ilDB->query(
704 "SELECT percentage FROM ut_lp_marks WHERE " .
705 " status_dirty = " . $ilDB->quote(0, "integer") .
706 " AND usr_id = " . $ilDB->quote($a_user_id, "integer") .
707 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
708 );
709 if ($rec = $ilDB->fetchAssoc($set)) {
710 return $rec["percentage"];
711 }
712 return null;
713 }
714
718 public static function _hasUserCompleted(
719 int $a_obj_id,
720 int $a_user_id
721 ): bool {
722 return self::_lookupStatus(
723 $a_obj_id,
724 $a_user_id
725 ) == self::LP_STATUS_COMPLETED_NUM;
726 }
727
731 public static function _lookupStatusChanged(
732 int $a_obj_id,
733 int $a_user_id
734 ): ?string {
735 global $DIC;
736
737 $ilDB = $DIC['ilDB'];
738
739 $set = $ilDB->query(
740 "SELECT status_changed FROM ut_lp_marks WHERE " .
741 " status_dirty = " . $ilDB->quote(0, "integer") .
742 " AND usr_id = " . $ilDB->quote($a_user_id, "integer") .
743 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
744 );
745 if ($rec = $ilDB->fetchAssoc($set)) {
746 return (string) $rec["status_changed"];
747 } else {
748 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
749 $set = $ilDB->query(
750 "SELECT status_changed FROM ut_lp_marks WHERE " .
751 " status_dirty = " . $ilDB->quote(0, "integer") .
752 " AND usr_id = " . $ilDB->quote($a_user_id, "integer") .
753 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer")
754 );
755 if ($rec = $ilDB->fetchAssoc($set)) {
756 return (string) $rec["status_changed"];
757 }
758 }
759 return null;
760 }
761
765 protected static function _lookupStatusForObject(
766 int $a_obj_id,
767 int $a_status,
768 ?array $a_user_ids = null
769 ): array {
770 global $DIC;
771
772 $ilDB = $DIC['ilDB'];
773
774 $sql = "SELECT usr_id, status, status_dirty FROM ut_lp_marks" .
775 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
776 " AND status = " . $ilDB->quote($a_status, "integer");
777 if ($a_user_ids) {
778 $sql .= " AND " . $ilDB->in("usr_id", $a_user_ids, "", "integer");
779 }
780
781 $set = $ilDB->query($sql);
782 $res = array();
783 while ($rec = $ilDB->fetchAssoc($set)) {
784 // @fixme this was broken due to wrong $res['status_dirty'] access
785 // check how to update status without recursion
786 // check consequences of the old implementation
787 if ($rec["status_dirty"]) {
788 // update status and check again
789 if (self::_lookupStatus(
790 $a_obj_id,
791 $rec["usr_id"]
792 ) != $a_status) {
793 // update status: see comment
794 }
795 }
796 $res[] = (int) $rec["usr_id"];
797 }
798
799 return $res;
800 }
801
805 public static function _lookupCompletedForObject(
806 int $a_obj_id,
807 ?array $a_user_ids = null
808 ): array {
809 return self::_lookupStatusForObject(
810 $a_obj_id,
811 self::LP_STATUS_COMPLETED_NUM,
812 $a_user_ids
813 );
814 }
815
819 public static function _lookupFailedForObject(
820 int $a_obj_id,
821 ?array $a_user_ids = null
822 ): array {
823 return self::_lookupStatusForObject(
824 $a_obj_id,
825 self::LP_STATUS_FAILED_NUM,
826 $a_user_ids
827 );
828 }
829
833 public static function _lookupInProgressForObject(
834 int $a_obj_id,
835 ?array $a_user_ids = null
836 ): array {
837 return self::_lookupStatusForObject(
838 $a_obj_id,
839 self::LP_STATUS_IN_PROGRESS_NUM,
840 $a_user_ids
841 );
842 }
843
847 protected static function validateLPForObjects(
848 int $a_user_id,
849 array $a_obj_ids,
850 int $a_parent_ref_id
851 ): array {
852 $lp_invalid = array();
853
854 $memberships = ilObjectLP::getLPMemberships(
855 $a_user_id,
856 $a_obj_ids,
857 $a_parent_ref_id
858 );
859 foreach ($memberships as $obj_id => $status) {
860 if (!$status) {
861 $lp_invalid[] = $obj_id;
862 }
863 }
864
865 return array_diff($a_obj_ids, $lp_invalid);
866 }
867
871 protected static function checkLPModesForObjects(
872 array $a_obj_ids,
873 array &$a_coll_obj_ids
874 ): array {
875 $valid = array();
876
877 // all lp modes with collections (gathered separately)
879
880 // check if objects have LP activated at all (DB entries)
881 $existing = ilLPObjSettings::_lookupDBModeForObjects($a_obj_ids);
882 foreach ($existing as $obj_id => $obj_mode) {
883 if ($obj_mode != ilLPObjSettings::LP_MODE_DEACTIVATED) {
884 $valid[$obj_id] = $obj_id;
885
886 if (in_array($obj_mode, $coll_modes)) {
887 $a_coll_obj_ids[] = $obj_id;
888 }
889 }
890 }
891
892 // missing objects in DB (default mode)
893 $existing_obj_ids = array_keys($existing);
894 if (sizeof($existing) != sizeof($a_obj_ids)) {
895 foreach (array_diff($a_obj_ids, $existing_obj_ids) as $obj_id) {
896 $olp = ilObjectLP::getInstance($obj_id);
897 $mode = $olp->getCurrentMode();
899 // #11141
900 unset($valid[$obj_id]);
901 } elseif ($mode != ilLPObjSettings::LP_MODE_UNDEFINED) {
902 $valid[$obj_id] = $obj_id;
903
904 if (in_array($mode, $coll_modes)) {
905 $a_coll_obj_ids[] = $obj_id;
906 }
907 }
908 }
909 unset($existing);
910 }
911 return array_values($valid);
912 }
913
917 protected static function getLPStatusForObjects(
918 int $a_user_id,
919 array $a_obj_ids
920 ): array {
921 global $DIC;
922
923 $ilDB = $DIC['ilDB'];
924
925 $res = array();
926
927 // get user lp data
928 $sql = "SELECT status, status_dirty, obj_id FROM ut_lp_marks" .
929 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer") .
930 " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
931 $set = $ilDB->query($sql);
932 while ($row = $ilDB->fetchAssoc($set)) {
933 if (!$row["status_dirty"]) {
934 $res[$row["obj_id"]] = $row["status"];
935 } else {
936 $res[$row["obj_id"]] = self::_lookupStatus(
937 $row["obj_id"],
938 $a_user_id
939 );
940 }
941 }
942
943 // process missing user entries (same as dirty entries, see above)
944 foreach ($a_obj_ids as $obj_id) {
945 if (!isset($res[$obj_id])) {
946 $res[$obj_id] = self::_lookupStatus($obj_id, $a_user_id);
947 if ($res[$obj_id] === null) {
948 $res[$obj_id] = self::LP_STATUS_NOT_ATTEMPTED_NUM;
949 }
950 }
951 }
952
953 return $res;
954 }
955
956 public static function preloadListGUIData(array $a_obj_ids): void
957 {
958 global $DIC;
959
961 if ($DIC->http()->wrapper()->query()->has('ref_id')) {
962 $requested_ref_id = $DIC->http()->wrapper()->query()->retrieve(
963 'ref_id',
964 $DIC->refinery()->kindlyTo()->int()
965 );
966 }
967
968 $ilUser = $DIC['ilUser'];
969 $lng = $DIC['lng'];
970
971 $user_id = $ilUser->getId();
972 $res = array();
973 if ($ilUser->getId() != ANONYMOUS_USER_ID &&
977 // -- validate
978
979 // :TODO: we need the parent ref id, but this is awful
980 // this step removes all "not attempted" from the list, which we usually do not want
981 //$a_obj_ids = self::validateLPForObjects($user_id, $a_obj_ids, $requested_ref_id);
982
983 // we are not handling the collections differently yet
984 $coll_obj_ids = array();
985 $a_obj_ids = self::checkLPModesForObjects(
986 $a_obj_ids,
987 $coll_obj_ids
988 );
989
990 // -- gather
991
992 $res = self::getLPStatusForObjects($user_id, $a_obj_ids);
993
994 // -- render
995
996 // value to icon
997 $lng->loadLanguageModule("trac");
999 foreach ($res as $obj_id => $status) {
1000 $res[$obj_id] = [
1001 "image" => $icons->renderIconForStatus($status),
1002 "status" => $status
1003 ];
1004 }
1005 }
1006
1007 self::$list_gui_cache = $res;
1008 }
1009
1013 public static function getListGUIStatus(
1014 int $a_obj_id,
1015 bool $a_image_only = true
1016 ) {
1017 if ($a_image_only) {
1018 $image = '';
1019 if (isset(self::$list_gui_cache[$a_obj_id]["image"])) {
1020 $image = self::$list_gui_cache[$a_obj_id]["image"];
1021 }
1022
1023 return $image;
1024 }
1025 return self::$list_gui_cache[$a_obj_id] ?? "";
1026 }
1027
1028 public static function hasListGUIStatus(int $a_obj_id): bool
1029 {
1030 if (isset(self::$list_gui_cache[$a_obj_id])) {
1031 return true;
1032 }
1033 return false;
1034 }
1035}
static _lookupDBModeForObjects(array $a_obj_ids)
static _getInstance(int $a_obj_id, ?int $a_mode=null)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status 'in_progress'.
static _getFailed(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _removeStatusCache(int $a_obj_id, int $a_usr_id)
static _getNotAttempted(int $a_obj_id)
Static function to read the number of user who have the status 'not_attempted'.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status 'completed'.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
static writeStatus(int $a_obj_id, int $a_user_id, int $a_status, int $a_percentage=0, bool $a_force_per=false, ?int &$a_old_status=self::LP_STATUS_NOT_ATTEMPTED_NUM)
Write status for user and object.
static validateLPForObjects(int $a_user_id, array $a_obj_ids, int $a_parent_ref_id)
Process given objects for lp-relevance.
static preloadListGUIData(array $a_obj_ids)
const LP_STATUS_COMPLETED_NUM
static _lookupPercentage(int $a_obj_id, int $a_user_id)
Lookup percentage.
static setDirty(int $a_obj_id)
Sets status of an object to dirty.
const LP_STATUS_NOT_PARTICIPATED
static _getInProgress(int $a_obj_id)
static _hasUserCompleted(int $a_obj_id, int $a_user_id)
Lookup user object completion.
static getListGUIStatus(int $a_obj_id, bool $a_image_only=true)
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get completed users for object.
static _getTypicalLearningTime(int $a_obj_id)
__construct(int $a_obj_id)
static setInProgressIfNotAttempted(int $a_obj_id, int $a_user_id)
This function shoudl be clalled for normal "read events".
const LP_STATUS_COMPLETED
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getFailed(int $a_obj_id)
const LP_STATUS_NOT_REGISTERED
const LP_STATUS_PARTICIPATED
const LP_STATUS_FAILED
static _lookupStatusChanged(int $a_obj_id, int $a_user_id)
Lookup status changed.
const LP_STATUS_IN_PROGRESS_NUM
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
Get in progress users for object.
ilDBInterface $db
_updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
New status handling (st: status, nr: accesses, p: percentage, t: time spent, m: mark) Learning progre...
static checkLPModesForObjects(array $a_obj_ids, array &$a_coll_obj_ids)
Process lp modes for given objects.
static _getCountCompleted(int $a_obj_id)
static _getNotAttempted(int $a_obj_id)
static raiseEvent(int $a_obj_id, int $a_usr_id, int $a_status, int $a_old_status, int $a_percentage)
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_REGISTERED
static _getCountNotAttempted(int $a_obj_id)
ilObjectDataCache $ilObjDataCache
static _getCountInProgress(int $a_obj_id)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get failed users for object.
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
static setAllDirty()
Sets all status to dirty.
static $list_gui_cache
refreshStatus(int $a_obj_id, ?array $a_users=null)
Refresh status.
static getLPStatusForObjects(int $a_user_id, array $a_obj_ids)
Get LP status for given objects (and user)
static _getCompleted(int $a_obj_id)
static checkStatusForObject(int $a_obj_id, ?array $a_users=null)
This function checks whether the status for a given number of users is dirty and must be recalculated...
const LP_STATUS_FAILED_NUM
static _lookupStatusForObject(int $a_obj_id, int $a_status, ?array $a_user_ids=null)
Get users with given status for object.
static _getStatusInfo(int $a_obj_id)
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
static hasListGUIStatus(int $a_obj_id)
static _getCountFailed(int $a_obj_id)
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static getLogger(string $a_component_id)
Get component logger.
static _getTypicalLearningTimeSeconds(int $a_rbac_id, int $a_obj_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLPMemberships(int $usr_id, array $obj_ids, ?int $parent_ref_id=null, bool $mapped_ref_ids=false)
Get all objects where given user is member (from LP POV)
static getInstance(int $obj_id)
static _lookupType(int $id, bool $reference=false)
const ANONYMOUS_USER_ID
Definition: constants.php:27
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
$valid
$requested_ref_id
Definition: feed.php:40
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query
$log
Definition: result.php:33
$lng