ILIAS  eassessment Revision 61809
 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("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", false);
82 
83  if(count($entries) > 0)
84  {
85  $i=0;
86  foreach($entries as $entry)
87  {
88  $this->tpl->setCurrentBlock("tbl_content");
89  $css_row = ($css_row != "tblrow1") ? "tblrow1" : "tblrow2";
90  $this->tpl->setVariable("CSS_ROW", $css_row);
91  $this->tpl->setVariable('TXT_DATE',ilDatePresentation::formatDate(new ilDateTime($entry["date"],IL_CAL_DATETIME)));
92  $name = ilObjUser::_lookupName($entry["user_id"]);
93  $login = ilObjUser::_lookupLogin($entry["user_id"]);
94  $this->tpl->setVariable("TXT_USER",
95  $name["title"]." ".$name["firstname"]." ".$name["lastname"]." [".$login."]");
96  $info_params = explode(",", $entry["info_params"]);
97 
98  // not so nice
99  if ($this->obj_type != "lm" && $this->obj_type != "dbk")
100  {
101  $info_text = $this->lng->txt("hist_".str_replace(":", "_", $this->obj_type).
102  "_".$entry["action"]);
103  }
104  else
105  {
106  $info_text = $this->lng->txt("hist_".str_replace(":", "_", $entry["obj_type"]).
107  "_".$entry["action"]);
108  }
109  $i=1;
110  foreach($info_params as $info_param)
111  {
112  $info_text = str_replace("%".$i, $info_param, $info_text);
113  $i++;
114  }
115  $this->tpl->setVariable("TXT_ACTION", $info_text);
116  if ($this->obj_type == "lm" || $this->obj_type == "dbk")
117  {
118  $obj_arr = explode(":", $entry["obj_type"]);
119  switch ($obj_arr[1])
120  {
121  case "st":
122  $img_type = "st";
123  $class = "ilstructureobjectgui";
124  $cmd = "view";
125  break;
126 
127  case "pg":
128  $img_type = "pg";
129  $class = "illmpageobjectgui";
130  $cmd = "edit";
131  break;
132 
133  default:
134  $img_type = $obj_arr[0];
135  $class = "";
136  $cmd = "view";
137  break;
138  }
139 
140  $this->tpl->setCurrentBlock("item_icon");
141  $this->tpl->setVariable("SRC_ICON", ilUtil::getImagePath("icon_".$img_type.".gif"));
142  $this->tpl->parseCurrentBlock();
143 
144  if ($class != "")
145  {
146  $this->tpl->setCurrentBlock("item_link");
147  $this->ctrl->setParameterByClass($class, "obj_id", $entry["obj_id"]);
148  $this->tpl->setVariable("HREF_LINK",
149  $this->ctrl->getLinkTargetByClass($class, $cmd));
150  $this->tpl->setVariable("TXT_LINK", $entry["title"]);
151  $this->tpl->parseCurrentBlock();
152  }
153  else
154  {
155  $this->tpl->setCurrentBlock("item_title");
156  $this->tpl->setVariable("TXT_TITLE",
157  ilObject::_lookupTitle($entry["obj_id"]));
158  $this->tpl->parseCurrentBlock();
159  }
160  }
161  if ($a_user_comment && $entry["user_comment"] != "")
162  {
163  $this->tpl->setCurrentBlock("user_comment");
164  $this->tpl->setVariable("TXT_COMMENT", $this->lng->txt("comment"));
165  $this->tpl->setVariable("TXT_USER_COMMENT", $entry["user_comment"]);
166  $this->tpl->parseCurrentBlock();
167  }
168  $this->tpl->setCurrentBlock("tbl_content");
169 
170  $this->tpl->setCurrentBlock("tbl_content");
171  $this->tpl->parseCurrentBlock();
172  }
173  } //if is_array
174  else
175  {
176  $this->tpl->setCurrentBlock("tbl_content_cell");
177  $this->tpl->setVariable("TBL_CONTENT_CELL", $this->lng->txt("hist_no_entries"));
178  $this->tpl->setVariable("TBL_COL_SPAN", 4);
179  $this->tpl->parseCurrentBlock();
180  $this->tpl->setCurrentBlock("tbl_content_row");
181  $this->tpl->setVariable("ROWCOLOR", "tblrow1");
182  $this->tpl->parseCurrentBlock();
183  }
184  $tbl->render();
185  //$this->tpl->parseCurrentBlock();
186 
187  return $this->tpl->get();
188  }
189 
193  function getVersionsTable($a_header_params, $a_user_comment = false)
194  {
195  $ref_id = $a_header_params["ref_id"];
196 
197  require_once("./Services/Table/classes/class.ilTableGUI.php");
198  $tbl = new ilTableGUI(0, false);
199 
200  // table header
201  $tbl->setTitle($this->lng->txt("versions"));
202 
203  $tbl->setHeaderNames(array($this->lng->txt("date")."/".
204  $this->lng->txt("user"), $this->lng->txt("action")));
205  $tbl->setColumnWidth(array("40%", "60%"));
206  $cols = array("date_user", "action");
207 
208  if ($a_header_params == "")
209  {
210  $a_header_params = array();
211  }
212  $header_params = $a_header_params;
213  $tbl->setHeaderVars($cols, $header_params);
214 
215  // table variables
216  $tbl->setOrderColumn($_GET["sort_by"]);
217  $tbl->setOrderDirection($_GET["sort_order"]);
218  $tbl->setLimit($_GET["limit"]);
219  $tbl->setOffset($_GET["offset"]);
220  $tbl->setMaxCount($this->maxcount); // ???
221  $tbl->disable("header");
222 
223  // footer
224  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
225 
226  // get history entries
227  $entries = ilHistory::_getEntriesForObject($this->obj_id, $this->obj_type);
228 
229  $tbl->setMaxCount(count($entries));
230  $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
231 
232  $this->tpl =& $tbl->getTemplateObject();
233  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.history_row.html", false);
234 
235  if(count($entries) > 0)
236  {
237  $i=0;
238  foreach($entries as $entry)
239  {
240  $this->tpl->setCurrentBlock("tbl_content");
241  $css_row = ($css_row != "tblrow1") ? "tblrow1" : "tblrow2";
242  $this->tpl->setVariable("CSS_ROW", $css_row);
243  $this->tpl->setVariable('TXT_DATE',ilDatePresentation::formatDate(new ilDateTime($entry['date'],IL_CAL_DATETIME)));
244 
245  $name = ilObjUser::_lookupName($entry["user_id"]);
246  $this->tpl->setVariable("TXT_USER",
247  $name["title"]." ".$name["firstname"]." ".$name["lastname"]." [".$entry["user_id"]."]");
248  $info_params = explode(",", $entry["info_params"]);
249  $info_text = $this->lng->txt("hist_".$this->obj_type.
250  "_".$entry["action"]);
251  $i=1;
252  foreach($info_params as $info_param)
253  {
254  $info_text = str_replace("%".$i, $info_param, $info_text);
255  $i++;
256  }
257  $this->tpl->setVariable("TXT_ACTION", $info_text);
258  if ($a_user_comment)
259  {
260  $this->tpl->setCurrentBlock("user_comment");
261  $this->tpl->setVariable("TXT_USER_COMMENT", $entry["user_comment"]);
262  $this->tpl->parseCurrentBlock();
263  $this->tpl->setCurrentBlock("tbl_content");
264  }
265 
266  $this->tpl->setCurrentBlock("dl_link");
267  $this->tpl->setVariable("TXT_DL", $this->lng->txt("download"));
268  $this->tpl->setVariable("DL_LINK", "repository.php?cmd=sendfile&hist_id=".$entry["hist_entry_id"]."&ref_id=".$ref_id);
269  $this->tpl->setCurrentBlock("tbl_content");
270  $this->tpl->parseCurrentBlock();
271 
272  }
273  } //if is_array
274  else
275  {
276  $this->tpl->setCurrentBlock("tbl_content_cell");
277  $this->tpl->setVariable("TBL_CONTENT_CELL", $this->lng->txt("hist_no_entries"));
278  $this->tpl->setVariable("TBL_COL_SPAN", 4);
279  $this->tpl->parseCurrentBlock();
280  $this->tpl->setCurrentBlock("tbl_content_row");
281  $this->tpl->setVariable("ROWCOLOR", "tblrow1");
282  $this->tpl->parseCurrentBlock();
283  }
284 
285  $tbl->render();
286  //$this->tpl->parseCurrentBlock();
287 
288  return $this->tpl->get();
289  }
290 
291 } // END class.ilHistoryGUI
292 ?>