76 if ($parent_obj_id == null)
78 $pset = $ilDB->query(
'SELECT r2.obj_id par_obj_id FROM object_reference r1 '.
79 'JOIN tree t ON t.child = r1.ref_id '.
80 'JOIN object_reference r2 ON r2.ref_id = t.parent '.
81 'WHERE r1.obj_id = '.$ilDB->quote($obj_id,
'integer'));
83 while ($prec = $ilDB->fetchAssoc($pset))
85 $nid = $ilDB->nextId(
"write_event");
86 $query = sprintf(
'INSERT INTO write_event '.
87 '(write_id, obj_id, parent_obj_id, usr_id, action, ts) VALUES '.
88 '(%s, %s, %s, %s, %s, '.$ilDB->now().
')',
89 $ilDB->quote($nid,
'integer'),
90 $ilDB->quote($obj_id,
'integer'),
91 $ilDB->quote($prec[
"par_obj_id"],
'integer'),
92 $ilDB->quote(
$usr_id,
'integer'),
93 $ilDB->quote($action,
'text'));
95 $aff = $ilDB->manipulate(
$query);
100 $nid = $ilDB->nextId(
"write_event");
101 $query = sprintf(
'INSERT INTO write_event '.
102 '(write_id, obj_id, parent_obj_id, usr_id, action, ts) '.
103 'VALUES (%s,%s,%s,%s,%s,'.$ilDB->now().
')',
104 $ilDB->quote($nid,
'integer'),
105 $ilDB->quote($obj_id,
'integer'),
106 $ilDB->quote($parent_obj_id,
'integer'),
107 $ilDB->quote(
$usr_id,
'integer'),
108 $ilDB->quote($action,
'text'));
109 $aff = $ilDB->manipulate(
$query);
127 include_once(
'Services/Tracking/classes/class.ilObjUserTracking.php');
131 $query = sprintf(
'SELECT * FROM read_event '.
132 'WHERE obj_id = %s '.
134 $ilDB->quote($obj_id,
'integer'),
135 $ilDB->quote(
$usr_id,
'integer'));
140 $row = $ilDB->fetchObject($res);
142 $query = sprintf(
'UPDATE read_event SET '.
143 'read_count = read_count + 1, '.
144 'spent_seconds = %s, '.
146 'WHERE obj_id = %s '.
148 $ilDB->quote((time() -
$row->last_access) <= $validTimeSpan ?
$row->spent_seconds + time() -
$row->last_access :
$row->spent_seconds,
'integer'),
149 $ilDB->quote(time(),
'integer'),
150 $ilDB->quote($obj_id,
'integer'),
151 $ilDB->quote(
$usr_id,
'integer'));
152 $aff = $ilDB->manipulate(
$query);
156 $query = sprintf(
'INSERT INTO read_event (obj_id,usr_id,last_access,read_count,spent_seconds,first_access) '.
157 'VALUES (%s,%s,%s,%s,%s,'.$ilDB->now().
') ',
158 $ilDB->quote($obj_id,
'integer'),
159 $ilDB->quote(
$usr_id,
'integer'),
160 $ilDB->quote(time(),
'integer'),
161 $ilDB->quote(1,
'integer'),
162 $ilDB->quote(0,
'integer'));
164 $aff = $ilDB->manipulate(
$query);
167 if ($isCatchupWriteEvents)
185 $query =
"SELECT obj_id FROM catch_write_events ".
186 "WHERE obj_id = ".$ilDB->quote($obj_id ,
'integer').
" ".
187 "AND usr_id = ".$ilDB->quote(
$usr_id ,
'integer');
191 $query =
"UPDATE catch_write_events ".
192 "SET ts = ".($timestamp == null ? $ilDB->now() : $ilDB->quote(
$timestamp,
'timestamp')).
" ".
193 "WHERE usr_id = ".$ilDB->quote(
$usr_id ,
'integer').
" ".
194 "AND obj_id = ".$ilDB->quote($obj_id ,
'integer');
199 $query =
"INSERT INTO catch_write_events (ts,obj_id,usr_id) ".
202 $ilDB->quote($obj_id,
'integer').
", ".
203 $ilDB->quote(
$usr_id,
'integer').
" ".
280 "FROM catch_write_events ".
281 "WHERE obj_id=".$ilDB->quote($obj_id ,
'integer').
" ".
282 "AND usr_id=".$ilDB->quote(
$usr_id ,
'integer');
283 $r = $ilDB->query(
$q);
286 $catchup =
$row[
'ts'];
291 $query = sprintf(
'SELECT * FROM write_event '.
292 'WHERE obj_id = %s '.
295 $ilDB->quote($obj_id,
'integer'),
296 $ilDB->quote(
$usr_id,
'integer'));
301 $query = sprintf(
'SELECT * FROM write_event '.
302 'WHERE obj_id = %s '.
306 $ilDB->quote($obj_id,
'integer'),
307 $ilDB->quote(
$usr_id,
'integer'),
308 $ilDB->quote($catchup,
'timestamp'));
312 while(
$row = $ilDB->fetchAssoc(
$res))
333 "FROM catch_write_events ".
334 "WHERE obj_id=".$ilDB->quote($obj_id ,
'integer').
" ".
335 "AND usr_id=".$ilDB->quote(
$usr_id ,
'integer');
336 $r = $ilDB->query(
$q);
339 $catchup =
$row[
'ts'];
345 $query = sprintf(
'SELECT * FROM write_event '.
346 'WHERE obj_id = %s '.
348 $ilDB->quote($obj_id,
'integer'),
349 $ilDB->quote(
$usr_id,
'integer'));
355 $query = sprintf(
'SELECT * FROM write_event '.
356 'WHERE obj_id = %s '.
359 $ilDB->quote($obj_id,
'integer'),
360 $ilDB->quote(
$usr_id,
'integer'),
361 $ilDB->quote($catchup,
'timestamp'));
365 $numRows =
$res->numRows();
371 return ($catchup == null) ? 1 : 2;
398 "FROM catch_write_events ".
399 "WHERE obj_id=".$ilDB->quote($parent_obj_id).
" ".
400 "AND usr_id=".$ilDB->quote(
$usr_id);
401 $r = $ilDB->query(
$q);
404 $catchup =
$row[
'ts'];
410 $query = sprintf(
'SELECT * FROM write_event '.
411 'WHERE parent_obj_id = %s '.
413 $ilDB->quote($parent_obj_id,
'integer'),
414 $ilDB->quote(
$usr_id,
'integer'));
420 $query = sprintf(
'SELECT * FROM write_event '.
421 'WHERE parent_obj_id = %s '.
424 $ilDB->quote($parent_obj_id,
'integer'),
425 $ilDB->quote(
$usr_id,
'integer'),
426 $ilDB->quote($catchup,
'timestamp'));
429 $numRows =
$res->numRows();
435 return ($catchup == null) ? 1 : 2;
492 $query = sprintf(
'SELECT * FROM read_event '.
493 'WHERE obj_id = %s '.
494 'ORDER BY last_access DESC',
495 $ilDB->quote($obj_id,
'integer'));
500 $query = sprintf(
'SELECT * FROM read_event '.
501 'WHERE obj_id = %s '.
503 'ORDER BY last_access DESC',
504 $ilDB->quote($obj_id,
'integer'),
505 $ilDB->quote(
$usr_id,
'integer'));
510 while (
$row = $ilDB->fetchAssoc(
$res))
512 $events[$counter][
'obj_id'] =
$row[
'obj_id'];
513 $events[$counter][
'usr_id'] =
$row[
'usr_id'];
514 $events[$counter][
'last_access'] =
$row[
'last_access'];
515 $events[$counter][
'read_count'] =
$row[
'read_count'];
516 $events[$counter][
'spent_seconds'] =
$row[
'spent_seconds'];
517 $events[$counter][
'first_access'] =
$row[
'first_access'];
522 return $events ? $events : array();
535 $query = sprintf(
'SELECT DISTINCT(usr_id) usr FROM read_event '.
536 'WHERE obj_id = %s ',
537 $ilDB->quote($a_obj_id,
'integer'));
539 while(
$row = $ilDB->fetchObject($res))
541 $users[] =
$row->usr;
543 return $users ? $users : array();
554 return 'change event tracking is already active';
566 $set = $ilDB->query(sprintf(
'SELECT r1.obj_id,r2.obj_id p,d.owner,%s,d.create_date '.
567 'FROM object_data d '.
568 'LEFT JOIN write_event w ON d.obj_id = w.obj_id '.
569 'JOIN object_reference r1 ON d.obj_id=r1.obj_id '.
570 'JOIN tree t ON t.child=r1.ref_id '.
571 'JOIN object_reference r2 on r2.ref_id=t.parent '.
572 'WHERE w.obj_id IS NULL',
573 $ilDB->quote(
'create',
'text')));
574 while ($rec = $ilDB->fetchAssoc($set))
576 $nid = $ilDB->nextId(
"write_event");
577 $query =
'INSERT INTO write_event '.
578 '(write_id, obj_id,parent_obj_id,usr_id,action,ts) VALUES ('.
579 $ilDB->quote($nid,
"integer").
",".
580 $ilDB->quote($rec[
"obj_id"],
"integer").
",".
581 $ilDB->quote($rec[
"p"],
"integer").
",".
582 $ilDB->quote($rec[
"owner"],
"integer").
",".
583 $ilDB->quote(
"create",
"text").
",".
584 $ilDB->quote($rec[
"create_date"],
"timestamp").
589 if ($ilDB->isError(
$res) || $ilDB->isError(
$res->result))
591 return 'couldn\'t insert initial data into table "write_event": '.
592 (($ilDB->isError($r->result)) ? $r->result->getMessage() : $r->getMessage());
597 $ilias->setSetting(
'enable_change_event_tracking',
'1');
610 $ilias->setSetting(
'enable_change_event_tracking',
'0');
621 return $ilias->getSetting(
'enable_change_event_tracking',
'0') ==
'1';
635 $query = sprintf(
'DELETE FROM write_event WHERE obj_id = %s ',
636 $ilDB->quote($a_obj_id,
'integer'));
637 $aff = $ilDB->manipulate(
$query);
639 $query = sprintf(
'DELETE FROM read_event WHERE obj_id = %s ',
640 $ilDB->quote($a_obj_id,
'integer'));
641 $aff = $ilDB->manipulate(
$query);