ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFileVersionsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
23 
29 {
30  private Container $dic;
31  private int $current_version;
32  private \ilObjFile $file;
33  private \ILIAS\ResourceStorage\Services $irss;
35  private int $amount_of_versions;
36  protected \ILIAS\DI\UIServices $ui;
37  protected bool $has_been_migrated = false;
38 
42  protected array $modals = [];
43 
47  public function __construct(
48  ilFileVersionsGUI $calling_gui_class,
49  string $a_parent_cmd = ilFileVersionsGUI::CMD_DEFAULT
50  ) {
51  global $DIC;
52  $this->dic = $DIC;
53  $this->ui = $DIC->ui();
54  $this->irss = $DIC->resourceStorage();
55  $this->setId(self::class);
56  parent::__construct($calling_gui_class, $a_parent_cmd, "");
57  $this->file = $calling_gui_class->getFile();
58  $this->current_version = $this->file->getVersion(true);
59  $rid = $this->irss->manage()->find(
60  $this->file->getResourceId()
61  );
62  $revision = $this->irss->manage()->getCurrentRevisionIncludingDraft(
63  $rid
64  );
65  $this->amount_of_versions = count(
66  $this->irss->manage()->getResource($rid)->getAllRevisionsIncludingDraft()
67  );
68  $this->current_version_is_draft = $revision->getStatus() === RevisionStatus::DRAFT;
69 
70  // General
71  $this->setPrefix("versions");
72  $this->dic->language()->loadLanguageModule('file');
73 
74  // Appearance
75  $this->setRowTemplate("tpl.file_version_row.html", "Modules/File");
76  $this->setLimit(9999);
77  $this->setEnableHeader(true);
78  $this->disable("footer");
79  $this->setTitle($this->dic->language()->txt("versions"));
80 
81  // Form
82 
83  $this->setFormAction($this->dic->ctrl()->getFormAction($calling_gui_class));
84  $this->setSelectAllCheckbox("hist_id[]");
85  //TODO: Use ilFileVersionsGUI::CMD_RENDER_DELETE_SELECTED_VERSIONS_MODAL instead of ilFileVersionsGUI::CMD_DELETE_VERSIONS as soon as new table gui is introduced.
86  // ilFileVersionsGUI::CMD_DELETE_VERSIONS and its deprecated ilConfirmationGUI are only needed because the old ilTable2GUI doesn't support calling modals from its MultiCommands
87  $this->addMultiCommand(ilFileVersionsGUI::CMD_DELETE_VERSIONS, $this->dic->language()->txt("delete"));
88  $this->addMultiCommand(
90  $this->dic->language()->txt("file_rollback")
91  );
92 
93  // Columns
94  $this->addColumn("", "", "1", true);
95  $this->addColumn($this->dic->language()->txt("version"), "", "auto");
96  $this->addColumn($this->dic->language()->txt("filename"));
97  $this->addColumn($this->dic->language()->txt("date"));
98  $this->addColumn($this->dic->language()->txt("file_uploaded_by"));
99  $this->addColumn($this->dic->language()->txt("versionname"));
100  $this->addColumn($this->dic->language()->txt("filesize"), "", "", false);
101  $this->addColumn($this->dic->language()->txt("status"));
102  $this->addColumn($this->dic->language()->txt("action"));
103  $this->addColumn("", "", "1");
104 
105  $this->initData();
106  }
107 
108  private function initData(): void
109  {
110  $versions = [];
111  foreach ($this->file->getVersions() as $version) {
112  $versions[] = $version->getArrayCopy();
113  }
114  usort($versions, static fn(array $i1, array $i2): int => $i2['version'] - $i1['version']);
115 
116  $this->setData($versions);
117  $this->setMaxCount(is_array($versions) ? count($versions) : 0);
118  }
119 
120  protected function fillRow(array $a_set): void
121  {
122  $action_entries = [];
123  $hist_id = $a_set["hist_entry_id"];
124 
125  // split params
126  $filename = $a_set["filename"];
127  $version = $a_set["version"];
128  $rollback_version = $a_set["rollback_version"];
129  $rollback_user_id = $a_set["rollback_user_id"];
130 
131  // get user name
132  $name = ilObjUser::_lookupName($a_set["user_id"]);
133  $username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
134 
135  // get file size
136  $data_size = new DataSize(
137  (int) ($a_set["size"] ?? 0),
138  DataSize::KB
139  );
140  $filesize = (string) $data_size;
141 
142  // get action text
143  $action = $this->dic->language()->txt(
144  "file_version_" . $a_set["action"]
145  ); // create, replace, new_version, rollback
146  if ($a_set["action"] == "rollback") {
147  $name = ilObjUser::_lookupName($rollback_user_id);
148  $rollback_username = trim($name["title"] . " " . $name["firstname"] . " " . $name["lastname"]);
149  $action = sprintf($action, $rollback_version, $rollback_username);
150  }
151 
152  // get download link
153  $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, $hist_id);
154  $link = $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_DOWNLOAD_VERSION);
155 
156  // build actions
157  $pseudo_modal = $this->ui->factory()->modal()->interruptive('', '', '')->withAsyncRenderUrl(
158  $this->ctrl->getLinkTargetByClass(
159  ilFileVersionsGUI::class,
161  null,
162  true
163  )
164  );
165 
166  $this->modals[] = $pseudo_modal;
167  $buttons = $this->dic->ui()->factory()->button();
168 
169 
170  if (!$this->current_version_is_draft) {
171  $action_entries['delete'] = $buttons
172  ->shy(
173  $this->dic->language()->txt("delete"),
174  ''
175  )
176  ->withOnClick(
177  $pseudo_modal->getShowSignal()
178  );
179 
180 
181  if ($this->current_version !== (int) $version) {
182  $action_entries['file_rollback'] = $buttons
183  ->shy(
184  $this->dic->language()->txt("file_rollback"),
185  $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_ROLLBACK_VERSION)
186  );
187  } elseif ($this->amount_of_versions > 1) {
188  $action_entries['unpublish'] = $buttons
189  ->shy(
190  $this->dic->language()->txt("file_unpublish"),
191  $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_UNPUBLISH)
192  );
193  }
194  } elseif ($this->current_version === (int) $version) {
195  $action_entries['publish'] = $buttons
196  ->shy(
197  $this->dic->language()->txt("file_publish"),
198  $this->dic->ctrl()->getLinkTarget($this->parent_obj, ilFileVersionsGUI::CMD_PUBLISH)
199  );
200  }
201 
202 
203  $actions = $this->dic->ui()->renderer()->render(
204  $this->dic->ui()->factory()->dropdown()
205  ->standard($action_entries)
206  ->withLabel($this->lng->txt('actions'))
207  );
208 
209  // reset history parameter
210  $this->dic->ctrl()->setParameter($this->parent_obj, ilFileVersionsGUI::HIST_ID, "");
211 
212  // fill template
213  $this->tpl->setVariable("TXT_VERSION", $version);
214  $this->tpl->setVariable(
215  "TXT_DATE",
217  );
218  $this->tpl->setVariable("TXT_UPLOADED_BY", $username);
219  $this->tpl->setVariable("DL_LINK", $link);
220  $this->tpl->setVariable("TXT_FILENAME", $filename);
221  $this->tpl->setVariable("TXT_VERSIONNAME", $a_set['title']);
222  $this->tpl->setVariable("TXT_FILESIZE", $data_size);
223 
224  // columns depending on confirmation
225  $this->tpl->setCurrentBlock("version_selection");
226  $this->tpl->setVariable("OBJ_ID", $hist_id);
227  $this->tpl->parseCurrentBlock();
228 
229  $this->tpl->setCurrentBlock("version_txt_actions");
230  $this->tpl->setVariable("TXT_ACTION", $action);
231  $this->tpl->parseCurrentBlock();
232 
233  $this->tpl->setCurrentBlock("version_actions");
234 
235  $this->tpl->setVariable("ACTIONS", $actions);
236 
237  $this->tpl->parseCurrentBlock();
238  }
239 
246  public function getHTML(): string
247  {
248  return parent::getHTML() . $this->ui->renderer()->render($this->modals);
249  }
250 }
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_DATETIME
getHTML()
Enables rendering modals OUTSIDE of the table.
setFormAction(string $a_form_action, bool $a_multipart=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:30
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _lookupName(int $a_user_id)
lookup user name
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
setId(string $a_val)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
Class ilFileVersionsTableGUI.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
$filename
Definition: buildRTE.php:78
ILIAS ResourceStorage Services $irss
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
disable(string $a_module_name)
addMultiCommand(string $a_cmd, string $a_text)
__construct(ilFileVersionsGUI $calling_gui_class, string $a_parent_cmd=ilFileVersionsGUI::CMD_DEFAULT)
ilFileVersionsTableGUI constructor.
setEnableHeader(bool $a_enableheader)
$version
Definition: plugin.php:24
setMaxCount(int $a_max_count)
set max.
setPrefix(string $a_prefix)