ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilHistory Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilHistory:

Static Public Member Functions

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

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning This class methods for maintain history enties for objects

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Member Function Documentation

◆ _changeUserId()

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

Changes the user id of the specified history entry.

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

References $DIC, and $ilDB.

250  : void
251  {
252  global $DIC;
253 
254  $ilDB = $DIC->database();
255 
256  $ilDB->update(
257  "history",
258  array("usr_id" => array("integer", $new_user_id)),
259  array("id" => array("integer", $a_hist_entry_id))
260  );
261  }
global $DIC
Definition: feed.php:28

◆ _compareHistArray()

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

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

Referenced by HistCompareTest\testCompare(), HistCompareTest\testCompare2(), and HistCompareTest\testCompare3().

167  : int
168  {
169  if ($a["date"] == $b["date"]) {
170  return 0;
171  }
172  return ($a["date"] < $b["date"]) ? -1 : 1;
173  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the caller graph for this function:

◆ _copyEntriesForObject()

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

copy all history entries for an object

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

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

192  : void
193  {
194  global $DIC;
195 
196  $ilDB = $DIC->database();
197 
198  $q = "SELECT * FROM history WHERE obj_id = " .
199  $ilDB->quote($a_src_id, "integer");
200  $r = $ilDB->query($q);
201 
202  while ($row = $ilDB->fetchObject($r)) {
203  $id = $ilDB->nextId("history");
204  $ilDB->insert("history", array(
205  "id" => array("integer", $id),
206  "obj_id" => array("integer", $a_dst_id),
207  "obj_type" => array("text", $row->obj_type),
208  "action" => array("text", $row->action),
209  "hdate" => array("timestamp", ilUtil::now()),
210  "usr_id" => array("integer", $row->usr_id),
211  "info_params" => array("text", $row->info_params),
212  "user_comment" => array("clob", $row->user_comment)
213  ));
214  }
215  }
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: feed.php:28
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ _createEntry()

static ilHistory::_createEntry ( int  $a_obj_id,
string  $a_action,
array  $a_info_params = [],
string  $a_obj_type = "",
string  $a_user_comment = "",
bool  $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_action
array$a_info_paramsinformation parameters
string$a_obj_typeobject type (must only be set, if object is not in object_data table)
string$a_user_comment
bool$a_update_last

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

References $DIC, $id, $ilDB, $ilUser, ILIAS\LTI\ToolProvider\$key, $param, ilObject\_lookupType(), and ilUtil\now().

Referenced by ilPageEditorGUI\addChangeComment(), ilObjContentObjectGUI\confirmedDelete(), ilLMObject\create(), ilWebLinkDatabaseRepository\createItem(), ilWebLinkDatabaseRepository\createList(), ilWebLinkDatabaseRepository\deleteItemByLinkID(), ilWebLinkDatabaseRepository\deleteList(), ilObjContentObject\executeDragDrop(), ilLMPageObjectGUI\updateHistory(), ilWebLinkDatabaseRepository\updateItem(), and ilWebLinkDatabaseRepository\updateList().

49  : void {
50  global $DIC;
51 
52  $ilDB = $DIC->database();
53  $ilUser = $DIC->user();
54 
55  if ($a_obj_type == "") {
56  $a_obj_type = ilObject::_lookupType($a_obj_id);
57  }
58 
59  if (is_array($a_info_params)) {
60  foreach ($a_info_params as $key => $param) {
61  $a_info_params[$key] = str_replace(",", "&#044;", $param);
62  }
63  $a_info_params = implode(",", $a_info_params);
64  }
65 
66  // get last entry of object
67  $last_entry_sql = "SELECT * FROM history WHERE " .
68  " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
69  " obj_type = " . $ilDB->quote($a_obj_type, "text") . " ORDER BY hdate DESC";
70  $last_entry_set = $ilDB->query($last_entry_sql);
71  $last_entry = $ilDB->fetchAssoc($last_entry_set);
72 
73  // note: insert is forced if last entry already has a comment and a
74  // new comment is given too OR
75  // if entry should not be updated OR
76  // if current action or user id are not equal with last entry
77  if (($a_user_comment != "" && $last_entry["user_comment"] != "")
78  || !$a_update_last || $a_action != $last_entry["action"]
79  || $ilUser->getId() != $last_entry["usr_id"]) {
80  $id = $ilDB->nextId("history");
81  $ilDB->insert("history", array(
82  "id" => array("integer", $id),
83  "obj_id" => array("integer", $a_obj_id),
84  "obj_type" => array("text", $a_obj_type),
85  "action" => array("text", $a_action),
86  "hdate" => array("timestamp", ilUtil::now()),
87  "usr_id" => array("integer", $ilUser->getId()),
88  "info_params" => array("text", $a_info_params),
89  "user_comment" => array("clob", $a_user_comment)
90  ));
91  } else {
92  $fields = array(
93  "hdate" => array("timestamp", ilUtil::now())
94  );
95  if ($a_user_comment != "") {
96  $fields["user_comment"] = array("clob", $a_user_comment);
97  }
98 
99  $ilDB->update("history", $fields, array(
100  "id" => array("integer", $last_entry["id"])
101  ));
102  }
103  }
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: feed.php:28
$param
Definition: xapitoken.php:46
string $key
Consumer key/client ID value.
Definition: System.php:193
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getEntriesForObject()

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

get all history entries for an object

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

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

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

Referenced by ilECSFileSettings\buildJson(), ilHistoryTableGUI\getDataFromDb(), and ilFileObjectToStorageDirectory\getHistoryData().

114  : array {
115  global $DIC;
116 
117  $ilDB = $DIC->database();
118 
119  if ($a_obj_type == "") {
120  $a_obj_type = ilObject::_lookupType($a_obj_id);
121  }
122  $query = "SELECT * FROM history WHERE obj_id = " .
123  $ilDB->quote($a_obj_id, "integer") . " AND " .
124  "obj_type = " . $ilDB->quote($a_obj_type, "text") .
125  " ORDER BY hdate DESC";
126 
127  $hist_set = $ilDB->query($query);
128  $hist_items = array();
129  while ($hist_rec = $ilDB->fetchAssoc($hist_set)) {
130  $hist_items[] = array("date" => $hist_rec["hdate"],
131  "user_id" => $hist_rec["usr_id"],
132  "obj_id" => $hist_rec["obj_id"],
133  "obj_type" => $hist_rec["obj_type"],
134  "action" => $hist_rec["action"],
135  "info_params" => $hist_rec["info_params"],
136  "user_comment" => $hist_rec["user_comment"],
137  "hist_entry_id" => $hist_rec["id"]);
138  }
139 
140  if ($a_obj_type == "lm") {
141  $query = "SELECT h.*, l.title as title FROM history h, lm_data l WHERE " .
142  " l.lm_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
143  " l.obj_id = h.obj_id AND " .
144  " (h.obj_type=" . $ilDB->quote($a_obj_type . ":pg", "text") . " OR h.obj_type=" . $ilDB->quote($a_obj_type . ":st", "text") . ") " .
145  " ORDER BY h.hdate DESC";
146 
147  $hist_set = $ilDB->query($query);
148  while ($hist_rec = $ilDB->fetchAssoc($hist_set)) {
149  $hist_items[] = array("date" => $hist_rec["hdate"],
150  "user_id" => $hist_rec["usr_id"],
151  "obj_id" => $hist_rec["obj_id"],
152  "obj_type" => $hist_rec["obj_type"],
153  "action" => $hist_rec["action"],
154  "info_params" => $hist_rec["info_params"],
155  "user_comment" => $hist_rec["user_comment"],
156  "hist_entry_id" => $hist_rec["id"],
157  "title" => $hist_rec["title"]);
158  }
159  usort($hist_items, array("ilHistory", "_compareHistArray"));
160  $hist_items2 = array_reverse($hist_items);
161  return $hist_items2;
162  }
163 
164  return $hist_items;
165  }
global $DIC
Definition: feed.php:28
$query
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getEntryByHistoryID()

static ilHistory::_getEntryByHistoryID ( int  $a_hist_entry_id)
static

returns a single history entry

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

References $DIC, and $ilDB.

220  : array
221  {
222  global $DIC;
223 
224  $ilDB = $DIC->database();
225 
226  $q = "SELECT * FROM history WHERE id = " .
227  $ilDB->quote($a_hist_entry_id, "integer");
228  $r = $ilDB->query($q);
229 
230  return $ilDB->fetchAssoc($r);
231  }
global $DIC
Definition: feed.php:28

◆ _removeEntriesForObject()

static ilHistory::_removeEntriesForObject ( int  $a_obj_id)
static

remove all history entries for an object

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

References $DIC, and $ilDB.

Referenced by ilObjBibliographic\doDelete(), ilObjFile\doDelete(), ilObjCmiXapi\doDelete(), and ilFileXMLParser\setFileContents().

178  : void
179  {
180  global $DIC;
181 
182  $ilDB = $DIC->database();
183 
184  $q = "DELETE FROM history WHERE obj_id = " .
185  $ilDB->quote($a_obj_id, "integer");
186  $ilDB->manipulate($q);
187  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ _removeEntryByHistoryID()

static ilHistory::_removeEntryByHistoryID ( int  $a_hist_entry_id)
static

Removes a single entry from the history.

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

References $DIC, and $ilDB.

236  : void
237  {
238  global $DIC;
239 
240  $ilDB = $DIC->database();
241 
242  $q = "DELETE FROM history WHERE id = " .
243  $ilDB->quote($a_hist_entry_id, "integer");
244  $ilDB->manipulate($q);
245  }
global $DIC
Definition: feed.php:28

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