ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
ilHistory Class Reference

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

+ Collaboration diagram for ilHistory:

Public Member Functions

 _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...
 
 _getEntriesForObject ($a_obj_id, $a_obj_type="")
 get all history entries for an object More...
 
 _compareHistArray ($a, $b)
 
 _removeEntriesForObject ($a_obj_id)
 remove all history entries for an object More...
 
 _copyEntriesForObject ($a_src_id, $a_dst_id)
 copy all history entries for an object More...
 
 _getEntryByHistoryID ($a_hist_entry_id)
 returns a single history entry More...
 

Static Public Member Functions

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 298 of file class.ilHistory.php.

References $ilDB.

Referenced by ilObjFile\rollback().

299  {
300  global $ilDB;
301 
302  $ilDB->update("history",
303  array("usr_id" => array("integer", $new_user_id)),
304  array("id" => array("integer", $a_hist_entry_id)));
305  }
global $ilDB
+ Here is the caller graph for this function:

◆ _compareHistArray()

ilHistory::_compareHistArray (   $a,
  $b 
)

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

189  {
190  if ($a["date"] == $b["date"])
191  {
192  return 0;
193  }
194  return ($a["date"] < $b["date"]) ? -1 : 1;
195  }

◆ _copyEntriesForObject()

ilHistory::_copyEntriesForObject (   $a_src_id,
  $a_dst_id 
)

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 222 of file class.ilHistory.php.

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

Referenced by ilObjFile\doCloneObject().

223  {
224  global $ilDB;
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  {
232  $id = $ilDB->nextId("history");
233  $ilDB->insert("history", array(
234  "id" => array("integer", $id),
235  "obj_id" => array("integer", $a_dst_id),
236  "obj_type" => array("text", $row->obj_type),
237  "action" => array("text", $row->action),
238  "hdate" => array("timestamp", ilUtil::now()),
239  "usr_id" => array("integer", $row->usr_id),
240  "info_params" => array("text", $row->info_params),
241  "user_comment" => array("clob", $row->user_comment)
242  ));
243 
244  /*
245  $q = "INSERT INTO history (obj_id, obj_type, action, hdate, usr_id, info_params, user_comment) VALUES ".
246  "(".
247  $ilDB->quote($a_dst_id).", ".
248  $ilDB->quote($row->obj_type).", ".
249  $ilDB->quote($row->action).", ".
250  $ilDB->quote($row->hdate).", ".
251  $ilDB->quote($row->usr_id).", ".
252  $ilDB->quote($row->info_params).", ".
253  $ilDB->quote($row->user_comment).
254  ")";
255 
256  $ilDB->query($q);*/
257  }
258 
259  return true;
260  }
static now()
Return current timestamp in Y-m-d H:i:s format.
$r
Definition: example_031.php:79
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createEntry()

ilHistory::_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.

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 $ilDB, $ilUser, ilObject\_lookupType(), 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().

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

◆ _getEntriesForObject()

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

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 129 of file class.ilHistory.php.

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

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

130  {
131  global $ilDB;
132 
133  if ($a_obj_type == "")
134  {
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  {
148  $hist_items[] = array("date" => $hist_rec["hdate"],
149  "user_id" => $hist_rec["usr_id"],
150  "obj_id" => $hist_rec["obj_id"],
151  "obj_type" => $hist_rec["obj_type"],
152  "action" => $hist_rec["action"],
153  "info_params" => $hist_rec["info_params"],
154  "user_comment" => $hist_rec["user_comment"],
155  "hist_entry_id" => $hist_rec["id"],
156  "title" => $hist_rec["title"]);
157  }
158 
159  if ($a_obj_type == "lm" || $a_obj_type == "dbk")
160  {
161  $query = "SELECT h.*, l.title as title FROM history h, lm_data l WHERE ".
162  " l.lm_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
163  " l.obj_id = h.obj_id AND ".
164  " (h.obj_type=".$ilDB->quote($a_obj_type.":pg", "text")." OR h.obj_type=".$ilDB->quote($a_obj_type.":st", "text").") ".
165  " ORDER BY h.hdate DESC";
166 
167  $hist_set = $ilDB->query($query);
168  while ($hist_rec = $ilDB->fetchAssoc($hist_set))
169  {
170  $hist_items[] = array("date" => $hist_rec["hdate"],
171  "user_id" => $hist_rec["usr_id"],
172  "obj_id" => $hist_rec["obj_id"],
173  "obj_type" => $hist_rec["obj_type"],
174  "action" => $hist_rec["action"],
175  "info_params" => $hist_rec["info_params"],
176  "user_comment" => $hist_rec["user_comment"],
177  "hist_entry_id" => $hist_rec["id"],
178  "title" => $hist_rec["title"]);
179  }
180  usort($hist_items, array("ilHistory", "_compareHistArray"));
181  $hist_items2 = array_reverse($hist_items);
182  return $hist_items2;
183  }
184 
185  return $hist_items;
186  }
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()

ilHistory::_getEntryByHistoryID (   $a_hist_entry_id)

returns a single history entry

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

References $ilDB, and $r.

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

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

◆ _removeEntriesForObject()

ilHistory::_removeEntriesForObject (   $a_obj_id)

remove all history entries for an object

Parameters
int$a_obj_idobject id
Returns
boolean

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

References $ilDB, and $r.

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

205  {
206  global $ilDB;
207 
208  $q = "DELETE FROM history WHERE obj_id = ".
209  $ilDB->quote($a_obj_id, "integer");
210  $r = $ilDB->manipulate($q);
211 
212  return true;
213  }
$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 283 of file class.ilHistory.php.

References $ilDB.

Referenced by ilObjFile\deleteVersions().

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

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