ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLearningProgress.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
31 {
32  // Static
33  public static function _tracProgress(
34  int $a_user_id,
35  int $a_obj_id,
36  int $a_ref_id,
37  string $a_obj_type = ''
38  ): bool {
40  $a_obj_type,
41  $a_ref_id,
42  $a_obj_id,
43  $a_user_id
44  );
45 
46  ilLPStatus::setInProgressIfNotAttempted($a_obj_id, $a_user_id);
47 
48  return true;
49  }
50 
51  public static function _getProgress(int $a_user_id, int $a_obj_id): array
52  {
53  $events = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
54 
55  $progress = [];
56  foreach ($events as $row) {
57  $tmp_date = new ilDateTime($row['last_access'], IL_CAL_UNIX);
58  $row['last_access'] = $tmp_date->get(IL_CAL_UNIX);
59 
60  $tmp_date = new ilDateTime($row['first_access'], IL_CAL_DATETIME);
61  $row['first_access'] = $tmp_date->get(IL_CAL_UNIX);
62 
63  if ($progress) {
64  $progress['spent_seconds'] += (int) $row['spent_seconds'];
65  $progress['access_time'] = max(
66  $progress['access_time'],
67  (int) $row['last_access']
68  );
69  $progress['access_time_min'] = min(
70  $progress['access_time_min'],
71  (int) $row['first_access']
72  );
73  } else {
74  $progress['obj_id'] = (int) $row['obj_id'];
75  $progress['user_id'] = (int) $row['usr_id'];
76  $progress['spent_seconds'] = (int) $row['spent_seconds'];
77  $progress['access_time'] = (int) $row['last_access'];
78  $progress['access_time_min'] = (int) $row['first_access'];
79  $progress['visits'] = (int) $row['read_count'];
80  }
81  }
82  return $progress;
83  }
84 
88  public static function _lookupProgressByObjId(int $a_obj_id): array
89  {
90  $progress = [];
91  foreach (ilChangeEvent::_lookupReadEvents($a_obj_id) as $row) {
92  if (isset($progress[$row['usr_id']])) {
93  $progress[$row['usr_id']]['spent_seconds'] += (int) $row['spent_seconds'];
94  $progress[$row['usr_id']]['read_count'] += (int) $row['read_count'];
95  $progress[$row['usr_id']]['ts'] = max(
96  (int) $row['last_access'],
97  (int) $progress[$row['usr_id']]['ts']
98  );
99  } else {
100  $progress[$row['usr_id']]['spent_seconds'] = (int) $row['spent_seconds'];
101  $progress[$row['usr_id']]['read_count'] = (int) $row['read_count'];
102  $progress[$row['usr_id']]['ts'] = (int) $row['last_access'];
103  }
104  $progress[$row['usr_id']]['usr_id'] = (int) $row['usr_id'];
105  $progress[$row['usr_id']]['obj_id'] = (int) $row['obj_id'];
106  }
107  return $progress;
108  }
109 }
const IL_CAL_DATETIME
static _getProgress(int $a_user_id, int $a_obj_id)
const IL_CAL_UNIX
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
static setInProgressIfNotAttempted(int $a_obj_id, int $a_user_id)
This function shoudl be clalled for normal "read events".
static _lookupReadEvents($obj_id, $usr_id=null)
Reads all read events which occured on the object.
static _lookupProgressByObjId(int $a_obj_id)
lookup progress for a specific object