ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilHistory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 class ilHistory
11 {
12 
31  function _createEntry($a_obj_id, $a_action, $a_info_params = "", $a_obj_type = "",
32  $a_user_comment = "", $a_update_last = false)
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  }
120 
129  function _getEntriesForObject($a_obj_id, $a_obj_type = "")
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 ".
164  " ORDER BY h.hdate DESC";
165 
166  $hist_set = $ilDB->query($query);
167  while ($hist_rec = $ilDB->fetchAssoc($hist_set))
168  {
169  $hist_items[] = array("date" => $hist_rec["hdate"],
170  "user_id" => $hist_rec["usr_id"],
171  "obj_id" => $hist_rec["obj_id"],
172  "obj_type" => $hist_rec["obj_type"],
173  "action" => $hist_rec["action"],
174  "info_params" => $hist_rec["info_params"],
175  "user_comment" => $hist_rec["user_comment"],
176  "hist_entry_id" => $hist_rec["id"],
177  "title" => $hist_rec["title"]);
178  }
179  usort($hist_items, array("ilHistory", "_compareHistArray"));
180  $hist_items2 = array_reverse($hist_items);
181  return $hist_items2;
182  }
183 
184  return $hist_items;
185  }
186 
187  function _compareHistArray($a, $b)
188  {
189  if ($a["date"] == $b["date"])
190  {
191  return 0;
192  }
193  return ($a["date"] < $b["date"]) ? -1 : 1;
194  }
195 
203  function _removeEntriesForObject($a_obj_id)
204  {
205  global $ilDB;
206 
207  $q = "DELETE FROM history WHERE obj_id = ".
208  $ilDB->quote($a_obj_id, "integer");
209  $r = $ilDB->manipulate($q);
210 
211  return true;
212  }
213 
221  function _copyEntriesForObject($a_src_id,$a_dst_id)
222  {
223  global $ilDB;
224 
225  $q = "SELECT * FROM history WHERE obj_id = ".
226  $ilDB->quote($a_src_id, "integer");
227  $r = $ilDB->query($q);
228 
229  while ($row = $ilDB->fetchObject($r))
230  {
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  }
260 
266  function _getEntryByHistoryID($a_hist_entry_id)
267  {
268  global $ilDB;
269 
270  $q = "SELECT * FROM history WHERE id = ".
271  $ilDB->quote($a_hist_entry_id, "integer");
272  $r = $ilDB->query($q);
273 
274  return $ilDB->fetchAssoc($r);
275  }
276 } // END class.ilHistory
277 ?>