ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
39 
40  $ilDB = $DIC['ilDB'];
41 
42  $this->db = $ilDB;
43  }
44 
45  // Static
46  public static function _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type = '')
47  {
48  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
49  ilChangeEvent::_recordReadEvent($a_obj_type, $a_ref_id, $a_obj_id, $a_user_id);
50 
51  require_once 'Services/Tracking/classes/class.ilLPStatus.php';
52  ilLPStatus::setInProgressIfNotAttempted($a_obj_id, $a_user_id);
53 
54  return true;
55  }
56 
57  public static function _getProgress($a_user_id, $a_obj_id)
58  {
59  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
60  $events = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
61 
62  include_once './Services/Calendar/classes/class.ilDateTime.php';
63 
64  foreach ($events as $row) {
65  $tmp_date = new ilDateTime($row['last_access'], IL_CAL_UNIX);
66  $row['last_access'] = $tmp_date->get(IL_CAL_UNIX);
67 
68  $tmp_date = new ilDateTime($row['first_access'], IL_CAL_DATETIME);
69  $row['first_access'] = $tmp_date->get(IL_CAL_UNIX);
70 
71  if ($progress) {
72  $progress['spent_seconds'] += $row['spent_seconds'];
73  $progress['access_time'] = max($progress['access_time'], $row['last_access']);
74  $progress['access_time_min'] = min($progress['access_time_min'], $row['first_access']);
75  } else {
76  $progress['obj_id'] = $row['obj_id'];
77  $progress['user_id'] = $row['usr_id'];
78  $progress['spent_seconds'] = $row['spent_seconds'];
79  $progress['access_time'] = $row['last_access'];
80  $progress['access_time_min'] = $row['first_access'];
81  $progress['visits'] = $row['read_count'];
82  }
83  }
84  return $progress ? $progress : array();
85  }
86 
94  public static function _lookupProgressByObjId($a_obj_id)
95  {
96  include_once('./Services/Tracking/classes/class.ilChangeEvent.php');
97  foreach (ilChangeEvent::_lookupReadEvents($a_obj_id) as $row) {
98  if (isset($progress[$row['usr_id']])) {
99  $progress[$row['usr_id']]['spent_seconds'] += $row['spent_seconds'];
100  $progress[$row['usr_id']]['read_count'] += $row['read_count'];
101  $progress[$row['usr_id']]['ts'] = max($row['last_access'], $progress[$row['usr_id']]['ts']);
102  } else {
103  $progress[$row['usr_id']]['spent_seconds'] = $row['spent_seconds'];
104  $progress[$row['usr_id']]['read_count'] = $row['read_count'];
105  $progress[$row['usr_id']]['ts'] = $row['last_access'];
106  }
107  $progress[$row['usr_id']]['usr_id'] = $row['usr_id'];
108  $progress[$row['usr_id']]['obj_id'] = $row['obj_id'];
109  }
110  return $progress ? $progress : array();
111  }
112 
113  /* deprecated
114  function _updateProgress($data)
115  {
116  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
117  ilChangeEvent::_recordReadEvent($data['type'], $data['ref_id'],
118  $data['obj_id'], $data['usr_id']);
119  }
120  */
121 }
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
global $DIC
Definition: saml.php:7
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
if($argc< 2) $events
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 ...
$row
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)