ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilHistoryGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/History/classes/class.ilHistory.php");
5 
13 {
14  var $obj_id;
15  var $lng;
16  var $tpl;
17 
18  function ilHistoryGUI($a_obj_id, $a_obj_type = "")
19  {
20  global $lng, $ilCtrl;
21 
22  $this->obj_id = $a_obj_id;
23 
24  if ($a_obj_type == "")
25  {
26  $this->obj_type = ilObject::_lookupType($a_obj_id);
27  }
28  else
29  {
30  $this->obj_type = $a_obj_type;
31  }
32 
33  $this->lng =& $lng;
34  $this->ctrl =& $ilCtrl;
35  }
36 
37 
41  function getHistoryTable($a_header_params, $a_user_comment = false)
42  {
43  $ref_id = $a_header_params["ref_id"];
44 
45  require_once("./Services/Table/classes/class.ilTableGUI.php");
46  $tbl = new ilTableGUI(0, false);
47 
48  // table header
49  $tbl->setTitle($this->lng->txt("history"));
50 
51  $tbl->setHeaderNames(array($this->lng->txt("date")."/".
52  $this->lng->txt("user"), $this->lng->txt("action")));
53  $tbl->setColumnWidth(array("40%", "60%"));
54  $cols = array("date_user", "action");
55 
56  if ($a_header_params == "")
57  {
58  $a_header_params = array();
59  }
60  $header_params = $a_header_params;
61  $tbl->setHeaderVars($cols, $header_params);
62 
63  // table variables
64  $tbl->setOrderColumn($_GET["sort_by"]);
65  $tbl->setOrderDirection($_GET["sort_order"]);
66  $tbl->setLimit($_GET["limit"]);
67  $tbl->setOffset($_GET["offset"]);
68  $tbl->setMaxCount($this->maxcount); // ???
69  $tbl->disable("header");
70 
71  // footer
72  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
73 
74  // get history entries
75  $entries = ilHistory::_getEntriesForObject($this->obj_id, $this->obj_type);
76 
77  $tbl->setMaxCount(count($entries));
78  $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
79 
80  $this->tpl =& $tbl->getTemplateObject();
81  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.history_row.html",
82  "Services/History");
83 
84  if(count($entries) > 0)
85  {
86  $i=0;
87  foreach($entries as $entry)
88  {
89  $this->tpl->setCurrentBlock("tbl_content");
90  $css_row = ($css_row != "tblrow1") ? "tblrow1" : "tblrow2";
91  $this->tpl->setVariable("CSS_ROW", $css_row);
92  $this->tpl->setVariable('TXT_DATE',ilDatePresentation::formatDate(new ilDateTime($entry["date"],IL_CAL_DATETIME)));
93  $name = ilObjUser::_lookupName($entry["user_id"]);
94  $login = ilObjUser::_lookupLogin($entry["user_id"]);
95  $this->tpl->setVariable("TXT_USER",
96  $name["title"]." ".$name["firstname"]." ".$name["lastname"]." [".$login."]");
97  $info_params = explode(",", $entry["info_params"]);
98 
99  // not so nice
100  if ($this->obj_type != "lm" && $this->obj_type != "dbk")
101  {
102  $info_text = $this->lng->txt("hist_".str_replace(":", "_", $this->obj_type).
103  "_".$entry["action"]);
104  }
105  else
106  {
107  $info_text = $this->lng->txt("hist_".str_replace(":", "_", $entry["obj_type"]).
108  "_".$entry["action"]);
109  }
110  $i=1;
111  foreach($info_params as $info_param)
112  {
113  $info_text = str_replace("%".$i, $info_param, $info_text);
114  $i++;
115  }
116  $this->tpl->setVariable("TXT_ACTION", $info_text);
117  if ($this->obj_type == "lm" || $this->obj_type == "dbk")
118  {
119  $obj_arr = explode(":", $entry["obj_type"]);
120  switch ($obj_arr[1])
121  {
122  case "st":
123  $img_type = "st";
124  $class = "ilstructureobjectgui";
125  $cmd = "view";
126  break;
127 
128  case "pg":
129  $img_type = "pg";
130  $class = "illmpageobjectgui";
131  $cmd = "edit";
132  break;
133 
134  default:
135  $img_type = $obj_arr[0];
136  $class = "";
137  $cmd = "view";
138  break;
139  }
140 
141  $this->tpl->setCurrentBlock("item_icon");
142  $this->tpl->setVariable("SRC_ICON", ilUtil::getImagePath("icon_".$img_type.".png"));
143  $this->tpl->parseCurrentBlock();
144 
145  if ($class != "")
146  {
147  $this->tpl->setCurrentBlock("item_link");
148  $this->ctrl->setParameterByClass($class, "obj_id", $entry["obj_id"]);
149  $this->tpl->setVariable("HREF_LINK",
150  $this->ctrl->getLinkTargetByClass($class, $cmd));
151  $this->tpl->setVariable("TXT_LINK", $entry["title"]);
152  $this->tpl->parseCurrentBlock();
153  }
154  else
155  {
156  $this->tpl->setCurrentBlock("item_title");
157  $this->tpl->setVariable("TXT_TITLE",
158  ilObject::_lookupTitle($entry["obj_id"]));
159  $this->tpl->parseCurrentBlock();
160  }
161  }
162  if ($a_user_comment && $entry["user_comment"] != "")
163  {
164  $this->tpl->setCurrentBlock("user_comment");
165  $this->tpl->setVariable("TXT_COMMENT", $this->lng->txt("comment"));
166  $this->tpl->setVariable("TXT_USER_COMMENT", $entry["user_comment"]);
167  $this->tpl->parseCurrentBlock();
168  }
169  $this->tpl->setCurrentBlock("tbl_content");
170 
171  $this->tpl->setCurrentBlock("tbl_content");
172  $this->tpl->parseCurrentBlock();
173  }
174  } //if is_array
175  else
176  {
177  $this->tpl->setCurrentBlock("tbl_content_cell");
178  $this->tpl->setVariable("TBL_CONTENT_CELL", $this->lng->txt("hist_no_entries"));
179  $this->tpl->setVariable("TBL_COL_SPAN", 4);
180  $this->tpl->parseCurrentBlock();
181  $this->tpl->setCurrentBlock("tbl_content_row");
182  $this->tpl->setVariable("ROWCOLOR", "tblrow1");
183  $this->tpl->parseCurrentBlock();
184  }
185  $tbl->render();
186  //$this->tpl->parseCurrentBlock();
187 
188  return $this->tpl->get();
189  }
190 
194  function getVersionsTable($a_header_params, $a_user_comment = false)
195  {
196  global $ilCtrl;
197 
198  $ref_id = $a_header_params["ref_id"];
199 
200  require_once("./Services/Table/classes/class.ilTableGUI.php");
201  $tbl = new ilTableGUI(0, false);
202 
203  // table header
204  $tbl->setTitle($this->lng->txt("versions"));
205 
206  $tbl->setHeaderNames(array($this->lng->txt("date")."/".
207  $this->lng->txt("user"), $this->lng->txt("action")));
208  $tbl->setColumnWidth(array("40%", "60%"));
209  $cols = array("date_user", "action");
210 
211  if ($a_header_params == "")
212  {
213  $a_header_params = array();
214  }
215  $header_params = $a_header_params;
216  $tbl->setHeaderVars($cols, $header_params);
217 
218  // table variables
219  $tbl->setOrderColumn($_GET["sort_by"]);
220  $tbl->setOrderDirection($_GET["sort_order"]);
221  $tbl->setLimit($_GET["limit"]);
222  $tbl->setOffset($_GET["offset"]);
223  $tbl->setMaxCount($this->maxcount); // ???
224  $tbl->disable("header");
225 
226  // footer
227  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
228 
229  // get history entries
230  $entries = ilHistory::_getEntriesForObject($this->obj_id, $this->obj_type);
231 
232  $tbl->setMaxCount(count($entries));
233  $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
234 
235  $this->tpl =& $tbl->getTemplateObject();
236  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.history_row.html",
237  "Services/History");
238 
239  if(count($entries) > 0)
240  {
241  $i=0;
242  foreach($entries as $entry)
243  {
244  $this->tpl->setCurrentBlock("tbl_content");
245  $css_row = ($css_row != "tblrow1") ? "tblrow1" : "tblrow2";
246  $this->tpl->setVariable("CSS_ROW", $css_row);
247  $this->tpl->setVariable('TXT_DATE',ilDatePresentation::formatDate(new ilDateTime($entry['date'],IL_CAL_DATETIME)));
248 
249  $name = ilObjUser::_lookupName($entry["user_id"]);
250  $this->tpl->setVariable("TXT_USER",
251  $name["title"]." ".$name["firstname"]." ".$name["lastname"]." [".$entry["user_id"]."]");
252  $info_params = explode(",", $entry["info_params"]);
253  $info_text = $this->lng->txt("hist_".$this->obj_type.
254  "_".$entry["action"]);
255  $i=1;
256  foreach($info_params as $info_param)
257  {
258  $info_text = str_replace("%".$i, $info_param, $info_text);
259  $i++;
260  }
261  $this->tpl->setVariable("TXT_ACTION", $info_text);
262  if ($a_user_comment)
263  {
264  $this->tpl->setCurrentBlock("user_comment");
265  $this->tpl->setVariable("TXT_USER_COMMENT", $entry["user_comment"]);
266  $this->tpl->parseCurrentBlock();
267  $this->tpl->setCurrentBlock("tbl_content");
268  }
269 
270  $this->tpl->setCurrentBlock("dl_link");
271  $this->tpl->setVariable("TXT_DL", $this->lng->txt("download"));
272  $ilCtrl->setParameterByClass("ilobjfilegui", "hist_id", $entry["hist_entry_id"]);
273  $this->tpl->setVariable("DL_LINK",
274  $ilCtrl->getLinkTargetByClass("ilobjfilegui", "sendfile"));
275  $this->tpl->setCurrentBlock("tbl_content");
276  $this->tpl->parseCurrentBlock();
277 
278  }
279  } //if is_array
280  else
281  {
282  $this->tpl->setCurrentBlock("tbl_content_cell");
283  $this->tpl->setVariable("TBL_CONTENT_CELL", $this->lng->txt("hist_no_entries"));
284  $this->tpl->setVariable("TBL_COL_SPAN", 4);
285  $this->tpl->parseCurrentBlock();
286  $this->tpl->setCurrentBlock("tbl_content_row");
287  $this->tpl->setVariable("ROWCOLOR", "tblrow1");
288  $this->tpl->parseCurrentBlock();
289  }
290 
291  $tbl->render();
292  //$this->tpl->parseCurrentBlock();
293 
294  return $this->tpl->get();
295  }
296 
297 } // END class.ilHistoryGUI
298 ?>