ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
33 {
34  public $db = null;
35 
36  public function __construct()
37  {
38  global $ilDB;
39 
40  $this->db = $ilDB;
41  }
42 
43  // Static
44  public static function _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type = '')
45  {
46  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
47  ilChangeEvent::_recordReadEvent($a_obj_type, $a_ref_id, $a_obj_id, $a_user_id);
48 
49  require_once 'Services/Tracking/classes/class.ilLPStatus.php';
50  ilLPStatus::setInProgressIfNotAttempted($a_obj_id, $a_user_id);
51 
52  return true;
53  }
54 
55  public static function _getProgress($a_user_id, $a_obj_id)
56  {
57  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
58  $events = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
59 
60  include_once './Services/Calendar/classes/class.ilDateTime.php';
61 
62  foreach ($events as $row) {
63  $tmp_date = new ilDateTime($row['last_access'], IL_CAL_UNIX);
64  $row['last_access'] = $tmp_date->get(IL_CAL_UNIX);
65 
66  $tmp_date = new ilDateTime($row['first_access'], IL_CAL_DATETIME);
67  $row['first_access'] = $tmp_date->get(IL_CAL_UNIX);
68 
69  if ($progress) {
70  $progress['spent_seconds'] += $row['spent_seconds'];
71  $progress['access_time'] = max($progress['access_time'], $row['last_access']);
72  $progress['access_time_min'] = min($progress['access_time_min'], $row['first_access']);
73  } else {
74  $progress['obj_id'] = $row['obj_id'];
75  $progress['user_id'] = $row['usr_id'];
76  $progress['spent_seconds'] = $row['spent_seconds'];
77  $progress['access_time'] = $row['last_access'];
78  $progress['access_time_min'] = $row['first_access'];
79  $progress['visits'] = $row['read_count'];
80  }
81  }
82  return $progress ? $progress : array();
83  }
84 
92  public static function _lookupProgressByObjId($a_obj_id)
93  {
94  include_once('./Services/Tracking/classes/class.ilChangeEvent.php');
95  foreach (ilChangeEvent::_lookupReadEvents($a_obj_id) as $row) {
96  if (isset($progress[$row['usr_id']])) {
97  $progress[$row['usr_id']]['spent_seconds'] += $row['spent_seconds'];
98  $progress[$row['usr_id']]['read_count'] += $row['read_count'];
99  $progress[$row['usr_id']]['ts'] = max($row['last_access'], $progress[$row['usr_id']]['ts']);
100  } else {
101  $progress[$row['usr_id']]['spent_seconds'] = $row['spent_seconds'];
102  $progress[$row['usr_id']]['read_count'] = $row['read_count'];
103  $progress[$row['usr_id']]['ts'] = $row['last_access'];
104  }
105  $progress[$row['usr_id']]['usr_id'] = $row['usr_id'];
106  $progress[$row['usr_id']]['obj_id'] = $row['obj_id'];
107  }
108  return $progress ? $progress : array();
109  }
110 
111  /* deprecated
112  function _updateProgress($data)
113  {
114  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
115  ilChangeEvent::_recordReadEvent($data['type'], $data['ref_id'],
116  $data['obj_id'], $data['usr_id']);
117  }
118  */
119 }
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
const IL_CAL_DATETIME
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
const IL_CAL_UNIX
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
Date and time handling
static _lookupReadEvents($obj_id, $usr_id=null)
Reads all read events which occured on the object which happened after the last time the user caught ...
Create styles array
The data for the language used.
static setInProgressIfNotAttempted($a_obj_id, $a_user_id)
This function shoudl be clalled for normal "read events".
global $ilDB
static _getProgress($a_user_id, $a_obj_id)