ILIAS  release_8 Revision v8.24
class.ilFileVersionsTableGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 private Container $dic;
28 private int $current_version;
29 private \ilObjFile $file;
30 protected bool $has_been_migrated = false;
31
35 public function __construct(ilFileVersionsGUI $calling_gui_class, string $a_parent_cmd = ilFileVersionsGUI::CMD_DEFAULT)
36 {
37 global $DIC;
38 $this->dic = $DIC;
39
40 $this->setId(self::class);
41 parent::__construct($calling_gui_class, $a_parent_cmd, "");
42 $this->file = $calling_gui_class->getFile();
43 $this->current_version = $this->file->getVersion();
44
45 // General
46 $this->setPrefix("versions");
47 $this->dic->language()->loadLanguageModule('file');
48
49 // Appearance
50 $this->setRowTemplate("tpl.file_version_row.html", "Modules/File");
51 $this->setLimit(9999);
52 $this->setEnableHeader(true);
53 $this->disable("footer");
54 $this->setTitle($this->dic->language()->txt("versions"));
55
56 // Form
57
58 $this->setFormAction($this->dic->ctrl()->getFormAction($calling_gui_class));
59 $this->setSelectAllCheckbox("hist_id[]");
60 $this->addMultiCommand(ilFileVersionsGUI::CMD_DELETE_VERSIONS, $this->dic->language()->txt("delete"));
61 $this->addMultiCommand(
63 $this->dic->language()->txt("file_rollback")
64 );
65
66 // Columns
67 $this->addColumn("", "", "1", true);
68 $this->addColumn($this->dic->language()->txt("version"), "", "auto");
69 $this->addColumn($this->dic->language()->txt("date"));
70 $this->addColumn($this->dic->language()->txt("file_uploaded_by"));
71 $this->addColumn($this->dic->language()->txt("filename"));
72 $this->addColumn($this->dic->language()->txt("versionname"));
73 $this->addColumn($this->dic->language()->txt("filesize"), "", "", false);
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 private function initData(): void
82 {
83 $versions = [];
84 foreach ($this->file->getVersions() as $version) {
85 $versions[] = $version->getArrayCopy();
86 }
87 usort($versions, static fn (array $i1, array $i2): int => $i2['version'] - $i1['version']);
88
89 $this->setData($versions);
90 $this->setMaxCount(is_array($versions) ? count($versions) : 0);
91 }
92
93 protected function fillRow(array $a_set): void
94 {
95 $hist_id = $a_set["hist_entry_id"];
96
97 // split params
98 $filename = $a_set["filename"];
99 $version = $a_set["version"];
100 $rollback_version = $a_set["rollback_version"];
101 $rollback_user_id = $a_set["rollback_user_id"];
102
103 // get user name
104 $name = ilObjUser::_lookupName($a_set["user_id"]);
105 $username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
106
107 // get file size
108 $filesize = $a_set["size"];
109
110 // get action text
111 $action = $this->dic->language()->txt("file_version_" . $a_set["action"]); // create, replace, new_version, rollback
112 if ($a_set["action"] == "rollback") {
113 $name = ilObjUser::_lookupName($rollback_user_id);
114 $rollback_username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
115 $action = sprintf($action, $rollback_version, $rollback_username);
116 }
117
118 // get download link
119 $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, $hist_id);
120 $link = $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DOWNLOAD_VERSION);
121
122 // build actions
123 $actions = new ilAdvancedSelectionListGUI();
124 $actions->setId($hist_id);
125 $actions->setListTitle($this->dic->language()->txt("actions"));
126 $actions->addItem(
127 $this->dic->language()->txt("delete"),
128 "",
129 $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DELETE_VERSIONS)
130 );
131 if ($this->current_version !== (int) $version) {
132 $actions->addItem(
133 $this->dic->language()->txt("file_rollback"),
134 "",
135 $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_ROLLBACK_VERSION)
136 );
137 }
138
139 // reset history parameter
140 $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, "");
141
142 // fill template
143 $this->tpl->setVariable("TXT_VERSION", $version);
144 $this->tpl->setVariable(
145 "TXT_DATE",
147 );
148 $this->tpl->setVariable("TXT_UPLOADED_BY", $username);
149 $this->tpl->setVariable("DL_LINK", $link);
150 $this->tpl->setVariable("TXT_FILENAME", $filename);
151 $this->tpl->setVariable("TXT_VERSIONNAME", $a_set['title']);
152 $this->tpl->setVariable("TXT_FILESIZE", ilUtil::formatSize($filesize));
153
154 // columns depending on confirmation
155 $this->tpl->setCurrentBlock("version_selection");
156 $this->tpl->setVariable("OBJ_ID", $hist_id);
157 $this->tpl->parseCurrentBlock();
158
159 $this->tpl->setCurrentBlock("version_txt_actions");
160 $this->tpl->setVariable("TXT_ACTION", $action);
161 $this->tpl->parseCurrentBlock();
162
163 $this->tpl->setCurrentBlock("version_actions");
164
165 $this->tpl->setVariable("ACTIONS", $actions->getHTML());
166
167 $this->tpl->parseCurrentBlock();
168 }
169}
$version
Definition: plugin.php:24
$filename
Definition: buildRTE.php:78
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class ilFileVersionsGUI.
Class ilFileVersionsTableGUI.
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(ilFileVersionsGUI $calling_gui_class, string $a_parent_cmd=ilFileVersionsGUI::CMD_DEFAULT)
ilFileVersionsTableGUI constructor.
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addMultiCommand(string $a_cmd, string $a_text)
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
disable(string $a_module_name)
setMaxCount(int $a_max_count)
set max.
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc