ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilHistory Class Reference

This class methods for maintain history enties for objects. More...

+ Collaboration diagram for ilHistory:

Static Public Member Functions

static _createEntry ( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
 Creates a new history entry for an object. More...
 
static _getEntriesForObject ($a_obj_id, $a_obj_type="")
 get all history entries for an object More...
 
static _compareHistArray ($a, $b)
 
static _removeEntriesForObject ($a_obj_id)
 remove all history entries for an object More...
 
static _copyEntriesForObject ($a_src_id, $a_dst_id)
 copy all history entries for an object More...
 
static _getEntryByHistoryID ($a_hist_entry_id)
 returns a single history entry More...
 
static _removeEntryByHistoryID ($a_hist_entry_id)
 Removes a single entry from the history. More...
 
static _changeUserId ($a_hist_entry_id, $new_user_id)
 Changes the user id of the specified history entry. More...
 

Detailed Description

This class methods for maintain history enties for objects.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 10 of file class.ilHistory.php.

Member Function Documentation

◆ _changeUserId()

static ilHistory::_changeUserId (   $a_hist_entry_id,
  $new_user_id 
)
static

Changes the user id of the specified history entry.

Parameters
int$a_hist_entry_idThe history entry to change the user id.
int$new_user_idThe new user id.

Definition at line 301 of file class.ilHistory.php.

References $DIC, $ilDB, and array.

Referenced by ilObjFile\rollback().

302  {
303  global $DIC;
304 
305  $ilDB = $DIC->database();
306 
307  $ilDB->update(
308  "history",
309  array("usr_id" => array("integer", $new_user_id)),
310  array("id" => array("integer", $a_hist_entry_id))
311  );
312  }
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ _compareHistArray()

static ilHistory::_compareHistArray (   $a,
  $b 
)
static

Definition at line 185 of file class.ilHistory.php.

186  {
187  if ($a["date"] == $b["date"]) {
188  return 0;
189  }
190  return ($a["date"] < $b["date"]) ? -1 : 1;
191  }

◆ _copyEntriesForObject()

static ilHistory::_copyEntriesForObject (   $a_src_id,
  $a_dst_id 
)
static

copy all history entries for an object

Parameters
integer$a_src_idsource object id
integer$a_dst_iddestination object id
Returns
boolean

Definition at line 220 of file class.ilHistory.php.

References $DIC, $id, $ilDB, $r, $row, array, and ilUtil\now().

Referenced by ilObjFile\doCloneObject().

221  {
222  global $DIC;
223 
224  $ilDB = $DIC->database();
225 
226  $q = "SELECT * FROM history WHERE obj_id = " .
227  $ilDB->quote($a_src_id, "integer");
228  $r = $ilDB->query($q);
229 
230  while ($row = $ilDB->fetchObject($r)) {
231  $id = $ilDB->nextId("history");
232  $ilDB->insert("history", array(
233  "id" => array("integer", $id),
234  "obj_id" => array("integer", $a_dst_id),
235  "obj_type" => array("text", $row->obj_type),
236  "action" => array("text", $row->action),
237  "hdate" => array("timestamp", ilUtil::now()),
238  "usr_id" => array("integer", $row->usr_id),
239  "info_params" => array("text", $row->info_params),
240  "user_comment" => array("clob", $row->user_comment)
241  ));
242 
243  /*
244  $q = "INSERT INTO history (obj_id, obj_type, action, hdate, usr_id, info_params, user_comment) VALUES ".
245  "(".
246  $ilDB->quote($a_dst_id).", ".
247  $ilDB->quote($row->obj_type).", ".
248  $ilDB->quote($row->action).", ".
249  $ilDB->quote($row->hdate).", ".
250  $ilDB->quote($row->usr_id).", ".
251  $ilDB->quote($row->info_params).", ".
252  $ilDB->quote($row->user_comment).
253  ")";
254 
255  $ilDB->query($q);*/
256  }
257 
258  return true;
259  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static now()
Return current timestamp in Y-m-d H:i:s format.
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createEntry()

static ilHistory::_createEntry (   $a_obj_id,
  $a_action,
  $a_info_params = "",
  $a_obj_type = "",
  $a_user_comment = "",
  $a_update_last = false 
)
static

Creates a new history entry for an object.

The information text parameters have to be separated by comma. The information text has to be stored in a langage variable "hist_<object_type>_<action>". This text can contain placeholders %1, %2, ... for each parameter. The placehoders are replaced by the parameters in ilHistoryTableGUI.

Please note that the object type must be specified, if the object is not derived from ilObject.

Parameters
int$a_obj_idobject id
string$a_actionaction
string$a_info_paramsinformation text parameters, separated by comma or as an array
string$a_obj_typeobject type (must only be set, if object is not in object_data table)
string$a_user_commentuser comment

Definition at line 31 of file class.ilHistory.php.

References $DIC, $id, $ilDB, $ilUser, $key, ilObject\_lookupType(), array, and ilUtil\now().

Referenced by ilLinkResourceItems\add(), ilPageEditorGUI\addChangeComment(), ilObjFile\addFileVersion(), ilObjContentObjectGUI\confirmedDelete(), ilLMObject\create(), ilObjFileDAV\createNewVersion(), ilObjFile\createProperties(), ilLinkResourceItems\delete(), ilObjContentObject\executeDragDrop(), ilObjFile\replaceFile(), ilObjFile\rollback(), ilLinkResourceItems\update(), ilFileXMLParser\updateFileContents(), and ilLMPageObjectGUI\updateHistory().

38  {
39  global $DIC;
40 
41  $ilDB = $DIC->database();
42  $ilUser = $DIC->user();
43 
44  if ($a_obj_type == "") {
45  $a_obj_type = ilObject::_lookupType($a_obj_id);
46  }
47 
48  if (is_array($a_info_params)) {
49  foreach ($a_info_params as $key => $param) {
50  $a_info_params[$key] = str_replace(",", "&#044;", $param);
51  }
52  $a_info_params = implode(",", $a_info_params);
53  }
54 
55  // get last entry of object
56  $last_entry_sql = "SELECT * FROM history WHERE " .
57  " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
58  " obj_type = " . $ilDB->quote($a_obj_type, "text") . " ORDER BY hdate DESC";
59  $last_entry_set = $ilDB->query($last_entry_sql);
60  $last_entry = $ilDB->fetchAssoc($last_entry_set);
61 
62  // note: insert is forced if last entry already has a comment and a
63  // new comment is given too OR
64  // if entry should not be updated OR
65  // if current action or user id are not equal with last entry
66  if (($a_user_comment != "" && $last_entry["user_comment"] != "")
67  || !$a_update_last || $a_action != $last_entry["action"]
68  || $ilUser->getId() != $last_entry["usr_id"]) {
69  $id = $ilDB->nextId("history");
70  $ilDB->insert("history", array(
71  "id" => array("integer", $id),
72  "obj_id" => array("integer", $a_obj_id),
73  "obj_type" => array("text", $a_obj_type),
74  "action" => array("text", $a_action),
75  "hdate" => array("timestamp", ilUtil::now()),
76  "usr_id" => array("integer", $ilUser->getId()),
77  "info_params" => array("text", $a_info_params),
78  "user_comment" => array("clob", $a_user_comment)
79  ));
80 
81  /*$query = "INSERT INTO history (id, obj_id, obj_type, action, hdate, usr_id, info_params, user_comment) VALUES ".
82  "(".
83  $ilDB->quote($id).", ".
84  $ilDB->quote($a_obj_id).", ".
85  $ilDB->quote($a_obj_type).", ".
86  $ilDB->quote($a_action).", ".
87  "now(), ".
88  $ilDB->quote($ilUser->getId()).", ".
89  $ilDB->quote($a_info_params).", ".
90  $ilDB->quote($a_user_comment).
91  ")";
92  $ilDB->query($query);*/
93  } else {
94  // if entry should be updated, update user comment only
95  // if it is set (this means, user comment has been empty
96  // because if old and new comment are given, an INSERT is forced
97  // see if statement above)
98  //$uc_str = ($a_user_comment != "")
99  // ? ", user_comment = ".$ilDB->quote($a_user_comment)
100  // : "";
101  /*$query = "UPDATE history SET ".
102  " hdate = now() ".
103  $uc_str.
104  " WHERE id = ".$ilDB->quote($last_entry["id"]);
105  $ilDB->query($query);*/
106 
107  $fields = array(
108  "hdate" => array("timestamp", ilUtil::now())
109  );
110  if ($a_user_comment != "") {
111  $fields["user_comment"] = array("clob", $a_user_comment);
112  }
113 
114  $ilDB->update("history", $fields, array(
115  "id" => array("integer", $id)
116  ));
117  }
118  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static now()
Return current timestamp in Y-m-d H:i:s format.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getEntriesForObject()

static ilHistory::_getEntriesForObject (   $a_obj_id,
  $a_obj_type = "" 
)
static

get all history entries for an object

Parameters
int$a_obj_idobject id
Returns
array array of history entries (arrays with keys "date", "user_id", "obj_id", "action", "info_params")

Definition at line 128 of file class.ilHistory.php.

References $DIC, $ilDB, $query, ilObject\_lookupType(), and array.

Referenced by ilECSFileSettings\buildJson(), ilHistoryTableGUI\getDataFromDb(), ilObjFile\getVersions(), ilObjFile\rollback(), and ilFileXMLWriter\start().

129  {
130  global $DIC;
131 
132  $ilDB = $DIC->database();
133 
134  if ($a_obj_type == "") {
135  $a_obj_type = ilObject::_lookupType($a_obj_id);
136  }
137 
138  $query = "SELECT * FROM history WHERE obj_id = " .
139  $ilDB->quote($a_obj_id, "integer") . " AND " .
140  "obj_type = " . $ilDB->quote($a_obj_type, "text") .
141  " ORDER BY hdate DESC";
142 
143  $hist_set = $ilDB->query($query);
144 
145  $hist_items = array();
146  while ($hist_rec = $ilDB->fetchAssoc($hist_set)) {
147  $hist_items[] = array("date" => $hist_rec["hdate"],
148  "user_id" => $hist_rec["usr_id"],
149  "obj_id" => $hist_rec["obj_id"],
150  "obj_type" => $hist_rec["obj_type"],
151  "action" => $hist_rec["action"],
152  "info_params" => $hist_rec["info_params"],
153  "user_comment" => $hist_rec["user_comment"],
154  "hist_entry_id" => $hist_rec["id"],
155  "title" => $hist_rec["title"]);
156  }
157 
158  if ($a_obj_type == "lm") {
159  $query = "SELECT h.*, l.title as title FROM history h, lm_data l WHERE " .
160  " l.lm_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
161  " l.obj_id = h.obj_id AND " .
162  " (h.obj_type=" . $ilDB->quote($a_obj_type . ":pg", "text") . " OR h.obj_type=" . $ilDB->quote($a_obj_type . ":st", "text") . ") " .
163  " ORDER BY h.hdate DESC";
164 
165  $hist_set = $ilDB->query($query);
166  while ($hist_rec = $ilDB->fetchAssoc($hist_set)) {
167  $hist_items[] = array("date" => $hist_rec["hdate"],
168  "user_id" => $hist_rec["usr_id"],
169  "obj_id" => $hist_rec["obj_id"],
170  "obj_type" => $hist_rec["obj_type"],
171  "action" => $hist_rec["action"],
172  "info_params" => $hist_rec["info_params"],
173  "user_comment" => $hist_rec["user_comment"],
174  "hist_entry_id" => $hist_rec["id"],
175  "title" => $hist_rec["title"]);
176  }
177  usort($hist_items, array("ilHistory", "_compareHistArray"));
178  $hist_items2 = array_reverse($hist_items);
179  return $hist_items2;
180  }
181 
182  return $hist_items;
183  }
global $DIC
Definition: saml.php:7
$query
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getEntryByHistoryID()

static ilHistory::_getEntryByHistoryID (   $a_hist_entry_id)
static

returns a single history entry

Definition at line 266 of file class.ilHistory.php.

References $DIC, $ilDB, and $r.

Referenced by ilObjFile\determineFileSize(), ilObjFile\getFile(), and ilObjFile\getSpecificVersion().

267  {
268  global $DIC;
269 
270  $ilDB = $DIC->database();
271 
272  $q = "SELECT * FROM history WHERE id = " .
273  $ilDB->quote($a_hist_entry_id, "integer");
274  $r = $ilDB->query($q);
275 
276  return $ilDB->fetchAssoc($r);
277  }
global $DIC
Definition: saml.php:7
$r
Definition: example_031.php:79
global $ilDB
+ Here is the caller graph for this function:

◆ _removeEntriesForObject()

static ilHistory::_removeEntriesForObject (   $a_obj_id)
static

remove all history entries for an object

Parameters
int$a_obj_idobject id
Returns
boolean

Definition at line 200 of file class.ilHistory.php.

References $DIC, $ilDB, and $r.

Referenced by ilObjFile\deleteVersions(), ilObjBibliographic\doDelete(), and ilObjFile\doDelete().

201  {
202  global $DIC;
203 
204  $ilDB = $DIC->database();
205 
206  $q = "DELETE FROM history WHERE obj_id = " .
207  $ilDB->quote($a_obj_id, "integer");
208  $r = $ilDB->manipulate($q);
209 
210  return true;
211  }
global $DIC
Definition: saml.php:7
$r
Definition: example_031.php:79
global $ilDB
+ Here is the caller graph for this function:

◆ _removeEntryByHistoryID()

static ilHistory::_removeEntryByHistoryID (   $a_hist_entry_id)
static

Removes a single entry from the history.

Parameters
int$a_hist_entry_idThe id of the entry to remove.

Definition at line 284 of file class.ilHistory.php.

References $DIC, and $ilDB.

Referenced by ilObjFile\deleteVersions().

285  {
286  global $DIC;
287 
288  $ilDB = $DIC->database();
289 
290  $q = "DELETE FROM history WHERE id = " .
291  $ilDB->quote($a_hist_entry_id, "integer");
292  $ilDB->manipulate($q);
293  }
global $DIC
Definition: saml.php:7
global $ilDB
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: