ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileVersionsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
10 {
11 
15  private $dic;
19  private $max_version;
27  private $file;
31  protected $has_been_migrated = false;
32 
38  public function __construct(ilFileVersionsGUI $calling_gui_class, $a_parent_cmd = ilFileVersionsGUI::CMD_DEFAULT)
39  {
40  global $DIC;
41  $this->dic = $DIC;
42 
43  $this->setId(self::class);
44  parent::__construct($calling_gui_class, $a_parent_cmd, "");
45  $this->file = $calling_gui_class->getFile();
46  $this->current_version = (int) $this->file->getVersion();
47  $this->max_version = (int) $this->file->getMaxVersion();
48  $this->has_been_migrated = !is_null($calling_gui_class->getFile()->getResourceId());
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  if ($this->has_been_migrated) {
63  $this->setFormAction($this->dic->ctrl()->getFormAction($calling_gui_class));
64  $this->setSelectAllCheckbox("hist_id[]");
65  $this->addMultiCommand(ilFileVersionsGUI::CMD_DELETE_VERSIONS, $this->dic->language()->txt("delete"));
67  $this->dic->language()->txt("file_rollback"));
68  }
69 
70  // Columns
71  $this->addColumn("", "", "1", true);
72  $this->addColumn($this->dic->language()->txt("version"), "", "auto");
73  $this->addColumn($this->dic->language()->txt("date"));
74  $this->addColumn($this->dic->language()->txt("file_uploaded_by"));
75  $this->addColumn($this->dic->language()->txt("filename"));
76  $this->addColumn($this->dic->language()->txt("versionname"));
77  $this->addColumn($this->dic->language()->txt("filesize"), "", "", false);
78  $this->addColumn($this->dic->language()->txt("type"));
79  $this->addColumn($this->dic->language()->txt("action"));
80  $this->addColumn("", "", "1");
81 
82  $this->initData();
83  }
84 
85  private function initData() : void
86  {
87  $versions = [];
88  foreach ($this->file->getVersions() as $version) {
89  $versions[] = $version->getArrayCopy();
90  }
91  usort($versions, static function (array $i1, array $i2) : bool {
92  return $i1['version'] < $i2['version'];
93  });
94 
95  $this->setData($versions);
96  $this->setMaxCount(is_array($versions) ? count($versions) : 0);
97  }
98 
99  protected function fillRow($a_set)
100  {
101  $hist_id = $a_set["hist_entry_id"];
102 
103  // split params
104  $filename = $a_set["filename"];
105  $version = $a_set["version"];
106  $rollback_version = $a_set["rollback_version"];
107  $rollback_user_id = $a_set["rollback_user_id"];
108 
109  // get user name
110  $name = ilObjUser::_lookupName($a_set["user_id"]);
111  $username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
112 
113  // get file size
114  $filesize = $a_set["size"];
115 
116  // get action text
117  $action = $this->dic->language()->txt("file_version_" . $a_set["action"]); // create, replace, new_version, rollback
118  if ($a_set["action"] == "rollback") {
119  $name = ilObjUser::_lookupName($rollback_user_id);
120  $rollback_username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
121  $action = sprintf($action, $rollback_version, $rollback_username);
122  }
123 
124  // get download link
125  $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, $hist_id);
126  $link = $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DOWNLOAD_VERSION);
127 
128  // build actions
129  $actions = new ilAdvancedSelectionListGUI();
130  $actions->setId($hist_id);
131  $actions->setListTitle($this->dic->language()->txt("actions"));
132  $actions->addItem($this->dic->language()->txt("delete"), "",
133  $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DELETE_VERSIONS));
134  if ($this->current_version !== (int) $version) {
135  $actions->addItem($this->dic->language()->txt("file_rollback"), "",
136  $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_ROLLBACK_VERSION));
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("TXT_DATE",
146  $this->tpl->setVariable("TXT_UPLOADED_BY", $username);
147  $this->tpl->setVariable("DL_LINK", $link);
148  $this->tpl->setVariable("TXT_FILENAME", $filename);
149  $this->tpl->setVariable("TXT_VERSIONNAME", $a_set['title']);
150  $this->tpl->setVariable("TXT_FILESIZE", ilUtil::formatSize($filesize));
151 
152  // columns depending on confirmation
153 
154  if (!$this->has_been_migrated) {
155  $this->tpl->setVariable("DISABLED", 'disabled');
156  }
157 
158  $this->tpl->setCurrentBlock("version_selection");
159  $this->tpl->setVariable("OBJ_ID", $hist_id);
160  $this->tpl->parseCurrentBlock();
161 
162  $this->tpl->setCurrentBlock("version_txt_actions");
163  $this->tpl->setVariable("TXT_ACTION", $action);
164  $this->tpl->parseCurrentBlock();
165 
166  $this->tpl->setCurrentBlock("version_actions");
167  if ($this->has_been_migrated) {
168  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
169  } else {
170  $this->tpl->setVariable("ACTIONS", "&nbsp;");
171  }
172  $this->tpl->parseCurrentBlock();
173  }
174 }
static _lookupName($a_user_id)
lookup user name
const IL_CAL_DATETIME
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.
if($format !==null) $name
Definition: metadata.php:230
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.
global $DIC
Definition: goto.php:24
addMultiCommand($a_cmd, $a_text)
Add Command button.
setPrefix($a_prefix)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$filename
Definition: buildRTE.php:89
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
__construct(Container $dic, ilPlugin $plugin)
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.
setLimit($a_limit=0, $a_default_limit=0)