00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031 class ilHistory
00032 {
00033
00052 function _createEntry($a_obj_id, $a_action, $a_info_params = "", $a_obj_type = "",
00053 $a_user_comment = "", $a_update_last = false)
00054 {
00055 global $ilDB, $ilUser;
00056
00057 if ($a_obj_type == "")
00058 {
00059 $a_obj_type = ilObject::_lookupType($a_obj_id);
00060 }
00061
00062 if (is_array($a_info_params))
00063 {
00064 foreach($a_info_params as $key => $param)
00065 {
00066 $a_info_params[$key] = str_replace(",", ",", $param);
00067 }
00068 $a_info_params = implode(",", $a_info_params);
00069 }
00070
00071
00072 $last_entry_sql = "SELECT * FROM history WHERE ".
00073 " obj_id = ".$ilDB->quote($a_obj_id)." AND ".
00074 " obj_type = ".$ilDB->quote($a_obj_type)." ORDER BY hdate DESC limit 1";
00075 $last_entry_set = $ilDB->query($last_entry_sql);
00076 $last_entry = $last_entry_set->fetchRow(DB_FETCHMODE_ASSOC);
00077
00078
00079
00080
00081
00082 if (($a_user_comment != "" && $last_entry["user_comment"] != "")
00083 || !$a_update_last || $a_action != $last_entry["action"]
00084 || $ilUser->getId() != $last_entry["usr_id"])
00085 {
00086 $query = "INSERT INTO history (obj_id, obj_type, action, hdate, usr_id, info_params, user_comment) VALUES ".
00087 "(".
00088 $ilDB->quote($a_obj_id).", ".
00089 $ilDB->quote($a_obj_type).", ".
00090 $ilDB->quote($a_action).", ".
00091 "now(), ".
00092 $ilDB->quote($ilUser->getId()).", ".
00093 $ilDB->quote($a_info_params).", ".
00094 $ilDB->quote($a_user_comment).
00095 ")";
00096 $ilDB->query($query);
00097 }
00098 else
00099 {
00100
00101
00102
00103
00104 $uc_str = ($a_user_comment != "")
00105 ? ", user_comment = ".$ilDB->quote($a_user_comment)
00106 : "";
00107 $query = "UPDATE history SET ".
00108 " hdate = now() ".
00109 $uc_str.
00110 " WHERE id = ".$ilDB->quote($last_entry["id"]);
00111 $ilDB->query($query);
00112 }
00113
00114 }
00115
00124 function _getEntriesForObject($a_obj_id, $a_obj_type = "")
00125 {
00126 global $ilDB;
00127
00128 if ($a_obj_type == "")
00129 {
00130 $a_obj_type = ilObject::_lookupType($a_obj_id);
00131 }
00132
00133 $query = "SELECT * FROM history WHERE obj_id = ".
00134 $ilDB->quote($a_obj_id)." AND ".
00135 "obj_type = ".$ilDB->quote($a_obj_type).
00136 " ORDER BY hdate DESC";
00137
00138 $hist_set = $ilDB->query($query);
00139
00140 $hist_items = array();
00141 while ($hist_rec = $hist_set->fetchRow(DB_FETCHMODE_ASSOC))
00142 {
00143 $hist_items[] = array("date" => $hist_rec["hdate"],
00144 "user_id" => $hist_rec["usr_id"],
00145 "obj_id" => $hist_rec["obj_id"],
00146 "obj_type" => $hist_rec["obj_type"],
00147 "action" => $hist_rec["action"],
00148 "info_params" => $hist_rec["info_params"],
00149 "user_comment" => $hist_rec["user_comment"],
00150 "hist_entry_id" => $hist_rec["id"],
00151 "title" => $hist_rec["title"]);
00152 }
00153
00154 if ($a_obj_type == "lm" || $a_obj_type == "dbk")
00155 {
00156 $query = "SELECT h.*, l.title as title FROM history as h, lm_data as l WHERE ".
00157 " l.lm_id = ".$ilDB->quote($a_obj_id)." AND ".
00158 " l.obj_id = h.obj_id ".
00159 " ORDER BY h.hdate DESC";
00160
00161 $hist_set = $ilDB->query($query);
00162 while ($hist_rec = $hist_set->fetchRow(DB_FETCHMODE_ASSOC))
00163 {
00164 $hist_items[] = array("date" => $hist_rec["hdate"],
00165 "user_id" => $hist_rec["usr_id"],
00166 "obj_id" => $hist_rec["obj_id"],
00167 "obj_type" => $hist_rec["obj_type"],
00168 "action" => $hist_rec["action"],
00169 "info_params" => $hist_rec["info_params"],
00170 "user_comment" => $hist_rec["user_comment"],
00171 "hist_entry_id" => $hist_rec["id"],
00172 "title" => $hist_rec["title"]);
00173 }
00174 usort($hist_items, array("ilHistory", "_compareHistArray"));
00175 $hist_items2 = array_reverse($hist_items);
00176 return $hist_items2;
00177 }
00178
00179 return $hist_items;
00180 }
00181
00182 function _compareHistArray($a, $b)
00183 {
00184 if ($a["date"] == $b["date"])
00185 {
00186 return 0;
00187 }
00188 return ($a["date"] < $b["date"]) ? -1 : 1;
00189 }
00190
00198 function _removeEntriesForObject($a_obj_id)
00199 {
00200 global $ilDB;
00201
00202 $q = "DELETE FROM history WHERE obj_id = ".$ilDB->quote($a_obj_id);
00203 $r = $ilDB->query($q);
00204
00205 return true;
00206 }
00207
00215 function _copyEntriesForObject($a_src_id,$a_dst_id)
00216 {
00217 global $ilDB;
00218
00219 $q = "SELECT * FROM history WHERE obj_id = ".$ilDB->quote($a_src_id);
00220 $r = $ilDB->query($q);
00221
00222 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00223 {
00224 $q = "INSERT INTO history (obj_id, obj_type, action, hdate, usr_id, info_params, user_comment) VALUES ".
00225 "(".
00226 $ilDB->quote($a_dst_id).", ".
00227 $ilDB->quote($row->obj_type).", ".
00228 $ilDB->quote($row->action).", ".
00229 $ilDB->quote($row->hdate).", ".
00230 $ilDB->quote($row->usr_id).", ".
00231 $ilDB->quote($row->info_params).", ".
00232 $ilDB->quote($row->user_comment).
00233 ")";
00234
00235 $ilDB->query($q);
00236 }
00237
00238 return true;
00239 }
00240
00246 function _getEntryByHistoryID($a_hist_entry_id)
00247 {
00248 global $ilDB;
00249
00250 $q = "SELECT * FROM history WHERE id = ".$ilDB->quote($a_hist_entry_id);
00251 $r = $ilDB->query($q);
00252
00253 return $r->fetchRow(DB_FETCHMODE_ASSOC);
00254 }
00255 }
00256 ?>