ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileVersionTableGUI.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 include_once("Services/Table/classes/class.ilTable2GUI.php");
5 
18 {
19  var $confirmDelete = false;
21 
28  function __construct($a_parent_obj, $a_parent_cmd, $confirmDelete = false)
29  {
30  global $ilCtrl, $lng;
31 
32  parent::__construct($a_parent_obj, $a_parent_cmd);
33 
34  $this->current_version = $a_parent_obj->object->getVersion();
35  $this->confirmDelete = $confirmDelete;
36 
37  $lng->loadLanguageModule("file");
38 
39  // general properties
40  $this->setRowTemplate("tpl.file_version_row.html", "Modules/File");
41  $this->setLimit(9999);
42  $this->setPrefix("versions");
43  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
44  $this->setEnableHeader(true);
45  $this->disable("footer");
46 
47  // properties depending on confirmation
48  if (!$this->confirmDelete)
49  {
50  $this->setTitle($lng->txt("versions"));
51  $this->setSelectAllCheckbox("hist_id[]");
52  }
53 
54  // columns
55  if (!$this->confirmDelete)
56  $this->addColumn("", "", "1", true);
57 
58  $this->addColumn($lng->txt("version"), "", "1");
59  $this->addColumn($lng->txt("date"));
60  $this->addColumn($lng->txt("file_uploaded_by"));
61  $this->addColumn($lng->txt("filename"));
62  $this->addColumn($lng->txt("filesize"), "", "", false, "ilRight");
63 
64  if (!$this->confirmDelete)
65  {
66  $this->addColumn($lng->txt("action"));
67  $this->addColumn("", "", "1");
68  }
69 
70  // commands depending on confirmation
71  if (!$this->confirmDelete)
72  {
73  $this->addMultiCommand("deleteVersions", $lng->txt("delete"));
74  $this->addMultiCommand("rollbackVersion", $lng->txt("file_rollback"));
75  }
76  else
77  {
78  $this->addCommandButton("confirmDeleteVersions", $lng->txt("confirm"));
79  $this->addCommandButton("cancelDeleteVersions", $lng->txt("cancel"));
80  }
81  }
82 
87  protected function fillRow($a_set)
88  {
89  global $lng, $ilCtrl, $ilAccess;
90 
91  $hist_id = $a_set["hist_entry_id"];
92 
93  // split params
94  $filename = $a_set["filename"];
95  $version = $a_set["version"];
96  $rollback_version = $a_set["rollback_version"];
97  $rollback_user_id = $a_set["rollback_user_id"];
98 
99  // get user name
100  $name = ilObjUser::_lookupName($a_set["user_id"]);
101  $username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
102 
103  // get file size
104  $filepath = $this->parent_obj->object->getDirectory($version) . "/" . $filename;
105  $filesize = filesize($filepath);
106 
107  // get action text
108  $action = $lng->txt("file_version_" . $a_set["action"]); // create, replace, new_version, rollback
109  if ($a_set["action"] == "rollback")
110  {
111  $name = ilObjUser::_lookupName($rollback_user_id);
112  $rollback_username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
113  $action = sprintf($action, $rollback_version, $rollback_username);
114  }
115 
116  // get download link
117  $ilCtrl->setParameter($this->parent_obj, "hist_id", $hist_id);
118  $link = $ilCtrl->getLinkTarget($this->parent_obj, "sendfile");
119 
120  // build actions
121  include_once("Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
122  $actions = new ilAdvancedSelectionListGUI();
123  $actions->setId($hist_id);
124  $actions->setListTitle($lng->txt("actions"));
125  $actions->addItem($lng->txt("delete"), "", $ilCtrl->getLinkTarget($this->parent_obj, "deleteVersions"));
126  if ($this->current_version != $version)
127  $actions->addItem($lng->txt("file_rollback"), "", $ilCtrl->getLinkTarget($this->parent_obj, "rollbackVersion"));
128 
129  // reset history parameter
130  $ilCtrl->setParameter($this->parent_obj, "hist_id", "");
131 
132  // fill template
133  $this->tpl->setVariable("TXT_VERSION", $version);
134  $this->tpl->setVariable("TXT_DATE", ilDatePresentation::formatDate(new ilDateTime($a_set['date'],IL_CAL_DATETIME)));
135  $this->tpl->setVariable("TXT_UPLOADED_BY", $username);
136  $this->tpl->setVariable("DL_LINK", $link);
137  $this->tpl->setVariable("TXT_FILENAME", $filename);
138  $this->tpl->setVariable("TXT_FILESIZE", ilFormat::formatSize($filesize));
139 
140  // columns depending on confirmation
141  if (!$this->confirmDelete)
142  {
143  $this->tpl->setCurrentBlock("version_selection");
144  $this->tpl->setVariable("OBJ_ID", $hist_id);
145  $this->tpl->parseCurrentBlock();
146 
147  $this->tpl->setCurrentBlock("version_txt_actions");
148  $this->tpl->setVariable("TXT_ACTION", $action);
149  $this->tpl->parseCurrentBlock();
150 
151  $this->tpl->setCurrentBlock("version_actions");
152  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
153  $this->tpl->parseCurrentBlock();
154  }
155  else
156  {
157  $this->tpl->setCurrentBlock("version_id");
158  $this->tpl->setVariable("OBJ_ID", $hist_id);
159  $this->tpl->parseCurrentBlock();
160  }
161  }
162 }
163 ?>