ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFileVersionsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
6 
13 {
14 
18  private $dic;
22  private $max_version;
30  private $file;
31 
32 
39  public function __construct(ilFileVersionsGUI $calling_gui_class, $a_parent_cmd = ilFileVersionsGUI::CMD_DEFAULT)
40  {
41  global $DIC;
42  $this->dic = $DIC;
43 
44  $this->setId(self::class);
45  parent::__construct($calling_gui_class, $a_parent_cmd, "");
46  $this->file = $calling_gui_class->getFile();
47  $this->current_version = (int) $this->file->getVersion();
48  $this->max_version = (int) $this->file->getMaxVersion();
49 
50  // General
51  $this->setPrefix("versions");
52  $this->dic->language()->loadLanguageModule('file');
53 
54  // Appearance
55  $this->setRowTemplate("tpl.file_version_row.html", "Modules/File");
56  $this->setLimit(9999);
57  $this->setEnableHeader(true);
58  $this->disable("footer");
59  $this->setTitle($this->dic->language()->txt("versions"));
60 
61  // Form
62  $this->setFormAction($this->dic->ctrl()->getFormAction($calling_gui_class));
63  $this->setSelectAllCheckbox("hist_id[]");
64  $this->addColumn("", "", "1", true);
65  $this->addMultiCommand(ilFileVersionsGUI::CMD_DELETE_VERSIONS, $this->dic->language()->txt("delete"));
66  $this->addMultiCommand(ilFileVersionsGUI::CMD_ROLLBACK_VERSION, $this->dic->language()->txt("file_rollback"));
67 
68  // Columns
69  $this->addColumn($this->dic->language()->txt("version"), "", "1");
70  $this->addColumn($this->dic->language()->txt("date"));
71  $this->addColumn($this->dic->language()->txt("file_uploaded_by"));
72  $this->addColumn($this->dic->language()->txt("filename"));
73  $this->addColumn($this->dic->language()->txt("filesize"), "", "", false, "ilRight");
74  $this->addColumn($this->dic->language()->txt("type"));
75  $this->addColumn($this->dic->language()->txt("action"));
76  $this->addColumn("", "", "1");
77 
78  $this->initData();
79  }
80 
81 
82  private function initData()
83  {
84  $versions = $this->file->getVersions();
85  $this->setData($versions);
86  $this->setMaxCount(is_array($versions) ? count($versions) : 0);
87  }
88 
89 
90  protected function fillRow($a_set)
91  {
92  $hist_id = $a_set["hist_entry_id"];
93 
94  // split params
95  $filename = $a_set["filename"];
96  $version = $a_set["version"];
97  $rollback_version = $a_set["rollback_version"];
98  $rollback_user_id = $a_set["rollback_user_id"];
99 
100  // get user name
101  $name = ilObjUser::_lookupName($a_set["user_id"]);
102  $username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
103 
104  // get file size
105  $directory = LegacyPathHelper::createRelativePath($this->file->getDirectory($version));
106  $filepath = ilFileUtils::getValidFilename(rtrim($directory, "/") . "/" . $filename); // TODO remove after migration to filesystem
107  $filesize = 0;
108  if ($this->dic->filesystem()->storage()->has($filepath)) {
109  $size = $filesize = $this->dic->filesystem()->storage()->getSize($filepath, DataSize::Byte);
110  $filesize = $size->getSize();
111  }
112 
113  // get action text
114  $action = $this->dic->language()->txt("file_version_" . $a_set["action"]); // create, replace, new_version, rollback
115  if ($a_set["action"] == "rollback") {
116  $name = ilObjUser::_lookupName($rollback_user_id);
117  $rollback_username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
118  $action = sprintf($action, $rollback_version, $rollback_username);
119  }
120 
121  // get download link
122  $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, $hist_id);
123  $link = $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DOWNLOAD_VERSION);
124 
125  // build actions
126  $actions = new ilAdvancedSelectionListGUI();
127  $actions->setId($hist_id);
128  $actions->setListTitle($this->dic->language()->txt("actions"));
129  $actions->addItem($this->dic->language()->txt("delete"), "", $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DELETE_VERSIONS));
130  if ($this->current_version !== (int) $version) {
131  $actions->addItem($this->dic->language()->txt("file_rollback"), "", $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_ROLLBACK_VERSION));
132  }
133 
134  // reset history parameter
135  $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, "");
136 
137  // fill template
138  $this->tpl->setVariable("TXT_VERSION", $version);
139  $this->tpl->setVariable("TXT_DATE", ilDatePresentation::formatDate(new ilDateTime($a_set['date'], IL_CAL_DATETIME)));
140  $this->tpl->setVariable("TXT_UPLOADED_BY", $username);
141  $this->tpl->setVariable("DL_LINK", $link);
142  $this->tpl->setVariable("TXT_FILENAME", $filename);
143  $this->tpl->setVariable("TXT_FILESIZE", ilUtil::formatSize($filesize));
144 
145  // columns depending on confirmation
146 
147  $this->tpl->setCurrentBlock("version_selection");
148  $this->tpl->setVariable("OBJ_ID", $hist_id);
149  $this->tpl->parseCurrentBlock();
150 
151  $this->tpl->setCurrentBlock("version_txt_actions");
152  $this->tpl->setVariable("TXT_ACTION", $action);
153  $this->tpl->parseCurrentBlock();
154 
155  $this->tpl->setCurrentBlock("version_actions");
156  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
157  $this->tpl->parseCurrentBlock();
158  }
159 }
static _lookupName($a_user_id)
lookup user name
$size
Definition: RandomTest.php:84
const IL_CAL_DATETIME
$action
global $DIC
Definition: saml.php:7
Exercise XML Parser which completes/updates a given file by an xml string.
Class ilFileVersionsGUI.
__construct(ilFileVersionsGUI $calling_gui_class, $a_parent_cmd=ilFileVersionsGUI::CMD_DEFAULT)
ilFileVersionsTableGUI constructor.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
setId($a_val)
Set id.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
$version
Definition: build.php:27
Class ilTable2GUI.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
Class ilFileVersionsTableGUI.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setPrefix($a_prefix)
Date and time handling
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$filename
Definition: buildRTE.php:89
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setEnableHeader($a_enableheader)
Set Enable Header.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
setMaxCount($a_max_count)
set max.
static getValidFilename($a_filename)
Get valid filename.
setLimit($a_limit=0, $a_default_limit=0)