76 if ($parent_obj_id == null)
78 $q =
"INSERT IGNORE INTO write_event ".
79 "(obj_id, parent_obj_id, usr_id, action, ts) ".
81 $ilDB->quote($obj_id).
",".
83 $ilDB->quote($usr_id).
",".
84 $ilDB->quote($action).
",".
86 "FROM object_reference AS r1 ".
87 "JOIN tree AS t ON t.child = r1.ref_id ".
88 "JOIN object_reference AS r2 ON r2.ref_id = t.parent ".
89 "WHERE r1.obj_id = ".$ilDB->quote($obj_id);
93 $q =
"INSERT IGNORE INTO write_event ".
94 "(obj_id, parent_obj_id, usr_id, action, ts) ".
96 $ilDB->quote($obj_id).
",".
97 $ilDB->quote($parent_obj_id).
",".
98 $ilDB->quote($usr_id).
",".
99 $ilDB->quote($action).
",".
103 $r = $ilDB->query($q);
118 include_once(
'Services/Tracking/classes/class.ilObjUserTracking.php');
124 $q =
"INSERT INTO read_event ".
125 "(obj_id, usr_id, first_access, last_access, read_count) ".
127 $ilDB->quote($obj_id).
",".
128 $ilDB->quote($usr_id).
",".
133 "read_count=read_count+1, ".
134 "spent_seconds = IF (TIME_TO_SEC(TIMEDIFF(NOW(),last_access))<=".$ilDB->quote($validTimeSpan).
",spent_seconds+TIME_TO_SEC(TIMEDIFF(NOW(),last_access)),spent_seconds),".
137 $r = $ilDB->query($q);
140 if ($isCatchupWriteEvents)
159 $q =
"INSERT INTO catch_write_events ".
160 "(obj_id, usr_id, ts) ".
162 $ilDB->quote($obj_id).
",".
163 $ilDB->quote($usr_id).
",";
167 ") ON DUPLICATE KEY UPDATE ts=NOW()";
171 ") ON DUPLICATE KEY UPDATE ts=".$ilDB->quote(
$timestamp);
174 $r = $ilDB->query($q);
228 "FROM catch_write_events ".
229 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
230 "AND usr_id=".$ilDB->quote($usr_id);
231 $r = $ilDB->query($q);
234 $catchup = $row[
'ts'];
239 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
240 "AND usr_id <> ".$ilDB->quote($usr_id).
" ".
241 ($catchup == null ?
"" :
"AND ts > ".$ilDB->quote($catchup)).
" ".
243 $r = $ilDB->query($q);
266 "FROM catch_write_events ".
267 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
268 "AND usr_id=".$ilDB->quote($usr_id);
269 $r = $ilDB->query($q);
272 $catchup = $row[
'ts'];
276 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
277 "AND usr_id <> ".$ilDB->quote($usr_id).
" ".
278 ($catchup == null ?
"" :
"AND ts > ".$ilDB->quote($catchup)).
" ".
281 $r = $ilDB->query($q);
282 $numRows = $r->numRows();
288 return ($catchup == null) ? 1 : 2;
315 "FROM catch_write_events ".
316 "WHERE obj_id=".$ilDB->quote($parent_obj_id).
" ".
317 "AND usr_id=".$ilDB->quote($usr_id);
318 $r = $ilDB->query($q);
321 $catchup = $row[
'ts'];
325 "WHERE parent_obj_id=".$ilDB->quote($parent_obj_id).
" ".
326 "AND usr_id <> ".$ilDB->quote($usr_id).
" ".
327 ($catchup == null ?
"" :
"AND ts > ".$ilDB->quote($catchup)).
" ".
330 $r = $ilDB->query($q);
331 $numRows = $r->numRows();
337 return ($catchup == null) ? 1 : 2;
396 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
397 "ORDER BY last_access DESC";
403 "WHERE obj_id=".$ilDB->quote($obj_id).
" ".
404 "AND usr_id=".$ilDB->quote($usr_id).
" ".
405 "ORDER BY last_access DESC";
407 $r = $ilDB->query($q);
424 return 'change event tracking is already active';
434 $q =
"INSERT IGNORE INTO write_event ".
435 "(obj_id,parent_obj_id,usr_id,action,ts) ".
436 "SELECT r1.obj_id,r2.obj_id,d.owner,'create',d.create_date ".
437 "FROM object_data AS d ".
438 "JOIN object_reference AS r1 ON d.obj_id=r1.obj_id ".
439 "JOIN tree AS t ON t.child=r1.ref_id ".
440 "JOIN object_reference as r2 on r2.ref_id=t.parent ";
441 $r = $ilDB->db->query($q);
442 if ($ilDB->isError($r) || $ilDB->isError($r->result))
444 return 'couldn\'t insert initial data into table "write_event": '.
445 (($ilDB->isError($r->result)) ? $r->result->getMessage() : $r->getMessage());
450 $ilias->setSetting(
'enable_change_event_tracking',
'1');
463 $ilias->setSetting(
'enable_change_event_tracking',
'0');
474 return $ilias->getSetting(
'enable_change_event_tracking',
'0') ==
'1';