ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilHistory.php
Go to the documentation of this file.
1<?php
2
25{
42 public static function _createEntry(
43 int $a_obj_id,
44 string $a_action,
45 array $a_info_params = [],
46 string $a_obj_type = "",
47 string $a_user_comment = "",
48 bool $a_update_last = false
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 }
104
111 public static function _getEntriesForObject(
112 int $a_obj_id,
113 string $a_obj_type = ""
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 }
166
167 public static function _compareHistArray(array $a, array $b): int
168 {
169 if ($a["date"] == $b["date"]) {
170 return 0;
171 }
172 return ($a["date"] < $b["date"]) ? -1 : 1;
173 }
174
178 public static function _removeEntriesForObject(int $a_obj_id): 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 }
188
192 public static function _copyEntriesForObject(int $a_src_id, int $a_dst_id): 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 }
216
220 public static function _getEntryByHistoryID(int $a_hist_entry_id): 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 }
232
236 public static function _removeEntryByHistoryID(int $a_hist_entry_id): 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 }
246
250 public static function _changeUserId(int $a_hist_entry_id, int $new_user_id): 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 }
262}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getEntriesForObject(int $a_obj_id, string $a_obj_type="")
get all history entries for an object
static _getEntryByHistoryID(int $a_hist_entry_id)
returns a single history entry
static _compareHistArray(array $a, array $b)
static _removeEntryByHistoryID(int $a_hist_entry_id)
Removes a single entry from the history.
static _changeUserId(int $a_hist_entry_id, int $new_user_id)
Changes the user id of the specified history entry.
static _copyEntriesForObject(int $a_src_id, int $a_dst_id)
copy all history entries for an object
static _removeEntriesForObject(int $a_obj_id)
remove all history entries for an object
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.
static _lookupType(int $id, bool $reference=false)
static now()
Return current timestamp in Y-m-d H:i:s format.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23
$param
Definition: xapitoken.php:46