ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilFileVersionsGUI Class Reference

Class ilFileVersionsGUI. More...

+ Collaboration diagram for ilFileVersionsGUI:

Public Member Functions

 __construct (ilObjFile $file)
 ilFileVersionsGUI constructor. More...
 
 executeCommand ()
 
 getFile ()
 

Data Fields

const CMD_DEFAULT = 'index'
 
const CMD_DELETE_VERSIONS = "deleteVersions"
 
const CMD_ROLLBACK_VERSION = "rollbackVersion"
 
const CMD_DOWNLOAD_VERSION = "sendFile"
 
const HIST_ID = 'hist_id'
 
const CMD_CANCEL_DELETE = "cancelDeleteFile"
 
const CMD_CONFIRMED_DELETE_FILE = "confirmDeleteFile"
 
const CMD_CONFIRMED_DELETE_VERSIONS = 'confirmDeleteVersions'
 
const CMD_ADD_NEW_VERSION = 'addNewVersion'
 
const CMD_CREATE_NEW_VERSION = 'saveVersion'
 
const CMD_ADD_REPLACING_VERSION = 'addReplacingVersion'
 
const CMD_CREATE_REPLACING_VERSION = 'createReplacingVersion'
 

Private Member Functions

 index ()
 
 addVersion ($mode=ilFileVersionFormGUI::MODE_ADD)
 
 saveVersion ($mode=ilFileVersionFormGUI::MODE_ADD)
 
 downloadVersion ()
 
 deleteVersions ()
 
 rollbackVersion ()
 
 confirmDeleteVersions ()
 
 confirmDeleteFile ()
 
 getVersionIdsFromRequest ()
 
 getVersionsToKeep (array $version_ids)
 
 hasPermission ($a_permission)
 bugfix mantis 26007: this function was created to ensure that the access check not only works for repository objects but for workspace objects too More...
 

Private Attributes

 $toolbar
 
 $access
 
 $wsp_access
 
 $ref_id
 
 $lng
 
 $http
 
 $tabs
 
 $ctrl
 
 $tpl
 
 $file
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilFileVersionsGUI::__construct ( ilObjFile  $file)

ilFileVersionsGUI constructor.

Parameters
ilObjFile$file

Definition at line 72 of file class.ilFileVersionsGUI.php.

73 {
74 global $DIC;
75 $this->file = $file;
76 $this->ctrl = $DIC->ctrl();
77 $this->tpl = $DIC->ui()->mainTemplate();
78 $this->tabs = $DIC->tabs();
79 $this->http = $DIC->http();
80 $this->lng = $DIC->language();
81 $this->ref_id = (int) $this->http->request()->getQueryParams()['ref_id'];
82 $this->toolbar = $DIC->toolbar();
83 $this->access = $DIC->access();
84 $this->wsp_access = new ilWorkspaceAccessHandler();
85 }
Access handler for personal workspace.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: saml.php:7

References $DIC, $file, and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

Member Function Documentation

◆ addVersion()

ilFileVersionsGUI::addVersion (   $mode = ilFileVersionFormGUI::MODE_ADD)
private
Parameters
int$mode

Definition at line 153 of file class.ilFileVersionsGUI.php.

154 {
155 $this->tabs->clearTargets();
156 $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, self::CMD_DEFAULT));
157
158 $form = new ilFileVersionFormGUI($this, $mode);
159 $form->fillForm();
160 $this->tpl->setContent($form->getHTML());
161 }
Class ilFileVersionFormGUI.
if(isset($_POST['submit'])) $form

References $form.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ confirmDeleteFile()

ilFileVersionsGUI::confirmDeleteFile ( )
private

Definition at line 288 of file class.ilFileVersionsGUI.php.

289 {
290 global $DIC;
291
292 $parent_id = $DIC->repositoryTree()->getParentId($this->ref_id);
293
294 $ru = new ilRepUtilGUI($this);
295 $ru->deleteObjects($parent_id, array($this->ref_id));
296
297 // redirect to parent object
298 $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $parent_id);
299 $this->ctrl->redirectByClass(ilRepositoryGUI::class);
300 }
Repository GUI Utilities.

References $DIC.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ confirmDeleteVersions()

ilFileVersionsGUI::confirmDeleteVersions ( )
private

Definition at line 275 of file class.ilFileVersionsGUI.php.

276 {
277 // delete versions after confirmation
278 if (is_array($_POST[self::HIST_ID]) && count($_POST[self::HIST_ID]) > 0) {
279 $this->file->deleteVersions($_POST[self::HIST_ID]);
280 ilUtil::sendSuccess($this->lng->txt("file_versions_deleted"), true);
281 }
282
283 $this->ctrl->setParameter($this, self::HIST_ID, "");
284 $this->ctrl->redirect($this, self::CMD_DEFAULT);
285 }
$_POST["username"]

References $_POST.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ deleteVersions()

ilFileVersionsGUI::deleteVersions ( )
private

array ( 'date' => '2019-07-25 11:19:51', 'user_id' => '6', 'obj_id' => '287', 'obj_type' => 'file', 'action' => 'create', 'info_params' => 'chicken_outlined.pdf,1,1', 'user_comment' => '', 'hist_entry_id' => '3', 'filename' => 'lorem ipsum', )

Definition at line 192 of file class.ilFileVersionsGUI.php.

193 {
194 $version_ids = $this->getVersionIdsFromRequest();
195
196 if (count($version_ids) < 1) {
197 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
198 $this->ctrl->redirect($this, self::CMD_DEFAULT);
199 } else {
200 // check if all versions are selected
201 $versions_to_keep = $this->getVersionsToKeep($version_ids);
202
203 $conf_gui = new ilConfirmationGUI();
204 $conf_gui->setFormAction($this->ctrl->getFormAction($this, self::CMD_DEFAULT));
205 $conf_gui->setCancel($this->lng->txt("cancel"), self::CMD_CANCEL_DELETE);
206
207 $icon = ilObject::_getIcon($this->file->getId(), "small", $this->file->getType());
208 $alt = $this->lng->txt("icon") . " " . $this->lng->txt("obj_" . $this->file->getType());
209
210 if (count($versions_to_keep) < 1) {
211 // Ask
212 ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_all_versions"));
213
214 $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_FILE);
215 $conf_gui->addItem(
216 "id[]",
217 $this->ref_id,
218 $this->file->getTitle(),
219 $icon,
220 $alt
221 );
222 } else {
223 // Ask
224 ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_versions"));
225
226 $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_VERSIONS);
227
241 foreach ($this->file->getVersions($version_ids) as $version) {
242 $conf_gui->addItem(
243 "hist_id[]",
244 $version['hist_entry_id'],
245 $version['filename'] ?? $this->file->getTitle(),
246 $icon,
247 $alt
248 );
249 }
250 }
251
252 $this->tpl->setContent($conf_gui->getHTML());
253 }
254 }
$version
Definition: build.php:27
Confirmation screen class.
getVersionsToKeep(array $version_ids)
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.

References $version, getVersionIdsFromRequest(), getVersionsToKeep(), ilUtil\sendFailure(), and ilUtil\sendQuestion().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ downloadVersion()

ilFileVersionsGUI::downloadVersion ( )
private

Definition at line 182 of file class.ilFileVersionsGUI.php.

183 {
184 $version = (int) $_GET[self::HIST_ID];
185 $this->file->sendFile($version);
186 try {
187 } catch (FileNotFoundException $e) {
188 }
189 }
$_GET["client_id"]

References $_GET, and $version.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ executeCommand()

ilFileVersionsGUI::executeCommand ( )

Definition at line 88 of file class.ilFileVersionsGUI.php.

89 {
90 // bugfix mantis 26007: use new function hasPermission to ensure that the check also works for workspace files
91 if (!$this->hasPermission('write')) {
92 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
93 $this->ctrl->returnToParent($this);
94 }
95 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
96
97 switch ($cmd) {
99 $this->index();
100 break;
102 $this->downloadVersion();
103 break;
105 $this->deleteVersions();
106 break;
108 $this->rollbackVersion();
109 break;
112 break;
115 break;
118 // no break
121 break;
123 $this->confirmDeleteVersions();
124 break;
126 $this->confirmDeleteFile();
127 break;
128 }
129 }
hasPermission($a_permission)
bugfix mantis 26007: this function was created to ensure that the access check not only works for rep...
saveVersion($mode=ilFileVersionFormGUI::MODE_ADD)
addVersion($mode=ilFileVersionFormGUI::MODE_ADD)

References addVersion(), CMD_ADD_NEW_VERSION, CMD_ADD_REPLACING_VERSION, CMD_CONFIRMED_DELETE_FILE, CMD_CONFIRMED_DELETE_VERSIONS, CMD_CREATE_NEW_VERSION, CMD_CREATE_REPLACING_VERSION, CMD_DEFAULT, CMD_DELETE_VERSIONS, CMD_DOWNLOAD_VERSION, CMD_ROLLBACK_VERSION, confirmDeleteFile(), confirmDeleteVersions(), deleteVersions(), downloadVersion(), hasPermission(), index(), ilFileVersionFormGUI\MODE_ADD, ilFileVersionFormGUI\MODE_REPLACE, rollbackVersion(), saveVersion(), and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ getFile()

ilFileVersionsGUI::getFile ( )
Returns
ilObjFile

Definition at line 306 of file class.ilFileVersionsGUI.php.

306 : ilObjFile
307 {
308 return $this->file;
309 }
Class ilObjFile.

References $file.

Referenced by ilFileVersionsTableGUI\__construct(), and ilFileVersionFormGUI\__construct().

+ Here is the caller graph for this function:

◆ getVersionIdsFromRequest()

ilFileVersionsGUI::getVersionIdsFromRequest ( )
private
Returns
array

Definition at line 315 of file class.ilFileVersionsGUI.php.

315 : array
316 {
317 // get ids either from GET (if single item was clicked) or
318 // from POST (if multiple items were selected)
319 $request = $this->http->request();
320
321 $version_ids = [];
322 if (isset($request->getQueryParams()[self::HIST_ID])) {
323 $version_ids = [$request->getQueryParams()[self::HIST_ID]];
324 } elseif (isset($request->getParsedBody()[self::HIST_ID])) {
325 $version_ids = (array) $request->getParsedBody()[self::HIST_ID];
326 }
327
328 return $version_ids;
329 }
foreach($paths as $path) $request
Definition: asyncclient.php:32

References $request, HIST_ID, and ILIAS\FileDelivery\http().

Referenced by deleteVersions(), and rollbackVersion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVersionsToKeep()

ilFileVersionsGUI::getVersionsToKeep ( array  $version_ids)
private
Parameters
array$version_ids
Returns
array

Definition at line 337 of file class.ilFileVersionsGUI.php.

337 : array
338 {
339 $versions_to_keep = array_udiff($this->file->getVersions(), $version_ids, function ($v1, $v2) {
340 if (is_array($v1)) {
341 $v1 = (int) $v1["hist_entry_id"];
342 } else {
343 if (!is_int($v1)) {
344 $v1 = (int) $v1;
345 }
346 }
347
348 if (is_array($v2)) {
349 $v2 = (int) $v2["hist_entry_id"];
350 } else {
351 if (!is_int($v2)) {
352 $v2 = (int) $v2;
353 }
354 }
355
356 return $v1 - $v2;
357 });
358
359 return $versions_to_keep;
360 }

Referenced by deleteVersions().

+ Here is the caller graph for this function:

◆ hasPermission()

ilFileVersionsGUI::hasPermission (   $a_permission)
private

bugfix mantis 26007: this function was created to ensure that the access check not only works for repository objects but for workspace objects too

Parameters
string$a_permission
Returns
bool

Definition at line 372 of file class.ilFileVersionsGUI.php.

373 {
374 // determine if the permission check concerns a workspace- or repository-object
375 if (isset($_GET['wsp_id'])) {
376 // permission-check concerning a workspace object
377 if ($this->wsp_access->checkAccess($a_permission, "", $this->ref_id)) {
378 return true;
379 }
380 } else {
381 // permission-check concerning a repository object
382 if ($this->access->checkAccess($a_permission, '', $this->ref_id)) {
383 return true;
384 }
385 }
386
387 return false;
388 }

References $_GET.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ index()

ilFileVersionsGUI::index ( )
private

Definition at line 132 of file class.ilFileVersionsGUI.php.

133 {
134 // Buttons
135 $add_version = ilLinkButton::getInstance();
136 $add_version->setCaption('file_new_version');
137 $add_version->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD_NEW_VERSION));
138 $this->toolbar->addButtonInstance($add_version);
139
140 $replace_version = ilLinkButton::getInstance();
141 $replace_version->setCaption('replace_file');
142 $replace_version->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD_REPLACING_VERSION));
143 $this->toolbar->addButtonInstance($replace_version);
144
145 $table = new ilFileVersionsTableGUI($this, self::CMD_DEFAULT);
146 $this->tpl->setContent($table->getHTML());
147 }
Class ilFileVersionsTableGUI.
static getInstance()
Factory.
if(empty($password)) $table
Definition: pwgen.php:24

References $table, and ilLinkButton\getInstance().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rollbackVersion()

ilFileVersionsGUI::rollbackVersion ( )
private

Definition at line 257 of file class.ilFileVersionsGUI.php.

258 {
259 $version_ids = $this->getVersionIdsFromRequest();
260
261 // more than one entry selected?
262 if (count($version_ids) != 1) {
263 ilUtil::sendInfo($this->lng->txt("file_rollback_select_exact_one"), true);
264 $this->ctrl->redirect($this, self::CMD_DEFAULT);
265 }
266
267 // rollback the version
268 $new_version = $this->file->rollback($version_ids[0]);
269
270 ilUtil::sendSuccess(sprintf($this->lng->txt("file_rollback_done"), $new_version["rollback_version"]), true);
271 $this->ctrl->redirect($this, self::CMD_DEFAULT);
272 }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References getVersionIdsFromRequest(), and ilUtil\sendInfo().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveVersion()

ilFileVersionsGUI::saveVersion (   $mode = ilFileVersionFormGUI::MODE_ADD)
private
Parameters
int$mode
Exceptions

ILIAS\FileUpload\Collection\Exception\NoSuchElementException

Exceptions

ILIAS\FileUpload\Exception\IllegalStateException

Definition at line 170 of file class.ilFileVersionsGUI.php.

171 {
172 $form = new ilFileVersionFormGUI($this, $mode);
173 if ($form->saveObject()) {
174 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
175 $this->ctrl->redirect($this, self::CMD_DEFAULT);
176 }
177 $form->setValuesByPost();
178 $this->tpl->setContent($form->getHTML());
179 }

References $form.

Referenced by executeCommand().

+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilFileVersionsGUI::$access
private

Definition at line 32 of file class.ilFileVersionsGUI.php.

◆ $ctrl

ilFileVersionsGUI::$ctrl
private

Definition at line 56 of file class.ilFileVersionsGUI.php.

◆ $file

ilFileVersionsGUI::$file
private

Definition at line 64 of file class.ilFileVersionsGUI.php.

Referenced by __construct(), and getFile().

◆ $http

ilFileVersionsGUI::$http
private

Definition at line 48 of file class.ilFileVersionsGUI.php.

◆ $lng

ilFileVersionsGUI::$lng
private

Definition at line 44 of file class.ilFileVersionsGUI.php.

◆ $ref_id

ilFileVersionsGUI::$ref_id
private

Definition at line 40 of file class.ilFileVersionsGUI.php.

◆ $tabs

ilFileVersionsGUI::$tabs
private

Definition at line 52 of file class.ilFileVersionsGUI.php.

◆ $toolbar

ilFileVersionsGUI::$toolbar
private

Definition at line 28 of file class.ilFileVersionsGUI.php.

◆ $tpl

ilFileVersionsGUI::$tpl
private

Definition at line 60 of file class.ilFileVersionsGUI.php.

◆ $wsp_access

ilFileVersionsGUI::$wsp_access
private

Definition at line 36 of file class.ilFileVersionsGUI.php.

◆ CMD_ADD_NEW_VERSION

const ilFileVersionsGUI::CMD_ADD_NEW_VERSION = 'addNewVersion'

Definition at line 21 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand().

◆ CMD_ADD_REPLACING_VERSION

const ilFileVersionsGUI::CMD_ADD_REPLACING_VERSION = 'addReplacingVersion'

Definition at line 23 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand().

◆ CMD_CANCEL_DELETE

const ilFileVersionsGUI::CMD_CANCEL_DELETE = "cancelDeleteFile"

Definition at line 18 of file class.ilFileVersionsGUI.php.

◆ CMD_CONFIRMED_DELETE_FILE

const ilFileVersionsGUI::CMD_CONFIRMED_DELETE_FILE = "confirmDeleteFile"

Definition at line 19 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand().

◆ CMD_CONFIRMED_DELETE_VERSIONS

const ilFileVersionsGUI::CMD_CONFIRMED_DELETE_VERSIONS = 'confirmDeleteVersions'

Definition at line 20 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand().

◆ CMD_CREATE_NEW_VERSION

const ilFileVersionsGUI::CMD_CREATE_NEW_VERSION = 'saveVersion'

Definition at line 22 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand(), and ilFileVersionFormGUI\initForm().

◆ CMD_CREATE_REPLACING_VERSION

const ilFileVersionsGUI::CMD_CREATE_REPLACING_VERSION = 'createReplacingVersion'

Definition at line 24 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand(), and ilFileVersionFormGUI\initForm().

◆ CMD_DEFAULT

const ilFileVersionsGUI::CMD_DEFAULT = 'index'

◆ CMD_DELETE_VERSIONS

const ilFileVersionsGUI::CMD_DELETE_VERSIONS = "deleteVersions"

◆ CMD_DOWNLOAD_VERSION

const ilFileVersionsGUI::CMD_DOWNLOAD_VERSION = "sendFile"

Definition at line 16 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand(), and ilFileVersionsTableGUI\fillRow().

◆ CMD_ROLLBACK_VERSION

const ilFileVersionsGUI::CMD_ROLLBACK_VERSION = "rollbackVersion"

◆ HIST_ID

const ilFileVersionsGUI::HIST_ID = 'hist_id'

The documentation for this class was generated from the following file: