ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilLearningProgress.php
Go to the documentation of this file.
1<?php
2
26{
27 // Static
28 public static function _tracProgress(
29 int $a_user_id,
30 int $a_obj_id,
31 int $a_ref_id,
32 string $a_obj_type = ''
33 ): bool {
34 ilChangeEvent::_recordReadEvent(
35 $a_obj_type,
36 $a_ref_id,
37 $a_obj_id,
38 $a_user_id
39 );
40
41 ilLPStatus::setInProgressIfNotAttempted($a_obj_id, $a_user_id);
42
43 return true;
44 }
45
46 public static function _getProgress(int $a_user_id, int $a_obj_id): array
47 {
48 $events = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
49
50 $progress = [];
51 foreach ($events as $row) {
52 $tmp_date = new ilDateTime($row['last_access'], IL_CAL_UNIX);
53 $row['last_access'] = $tmp_date->get(IL_CAL_UNIX);
54
55 $tmp_date = new ilDateTime($row['first_access'], IL_CAL_DATETIME);
56 $row['first_access'] = $tmp_date->get(IL_CAL_UNIX);
57
58 if ($progress) {
59 $progress['spent_seconds'] += (int) $row['spent_seconds'];
60 $progress['access_time'] = max(
61 $progress['access_time'],
62 (int) $row['last_access']
63 );
64 $progress['access_time_min'] = min(
65 $progress['access_time_min'],
66 (int) $row['first_access']
67 );
68 } else {
69 $progress['obj_id'] = (int) $row['obj_id'];
70 $progress['user_id'] = (int) $row['usr_id'];
71 $progress['spent_seconds'] = (int) $row['spent_seconds'];
72 $progress['access_time'] = (int) $row['last_access'];
73 $progress['access_time_min'] = (int) $row['first_access'];
74 $progress['visits'] = (int) $row['read_count'];
75 }
76 }
77 return $progress;
78 }
79
83 public static function _lookupProgressByObjId(int $a_obj_id): array
84 {
85 $progress = [];
86 foreach (ilChangeEvent::_lookupReadEvents($a_obj_id) as $row) {
87 if (isset($progress[$row['usr_id']])) {
88 $progress[$row['usr_id']]['spent_seconds'] += (int) $row['spent_seconds'];
89 $progress[$row['usr_id']]['read_count'] += (int) $row['read_count'];
90 $progress[$row['usr_id']]['ts'] = max(
91 (int) $row['last_access'],
92 (int) $progress[$row['usr_id']]['ts']
93 );
94 } else {
95 $progress[$row['usr_id']]['spent_seconds'] = (int) $row['spent_seconds'];
96 $progress[$row['usr_id']]['read_count'] = (int) $row['read_count'];
97 $progress[$row['usr_id']]['ts'] = (int) $row['last_access'];
98 }
99 $progress[$row['usr_id']]['usr_id'] = (int) $row['usr_id'];
100 $progress[$row['usr_id']]['obj_id'] = (int) $row['obj_id'];
101 }
102 return $progress;
103 }
104}
const IL_CAL_UNIX
const IL_CAL_DATETIME
Class ilChangeEvent tracks change events on repository objects.
static _lookupReadEvents($obj_id, $usr_id=null)
Reads all read events which occured on the object.
@classDescription Date and time handling
static setInProgressIfNotAttempted(int $a_obj_id, int $a_user_id)
This function shoudl be clalled for normal "read events".
static _getProgress(int $a_user_id, int $a_obj_id)
static _lookupProgressByObjId(int $a_obj_id)
lookup progress for a specific object
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')