ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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'
 
const CMD_MIGRATE = 'migrate'
 

Protected Attributes

 $has_been_migrated = false
 

Private Member Functions

 index ()
 
 addVersion ($mode=ilFileVersionFormGUI::MODE_ADD)
 
 saveVersion ($mode=ilFileVersionFormGUI::MODE_ADD)
 
 downloadVersion ()
 
 deleteVersions ()
 
 rollbackVersion ()
 
 confirmDeleteVersions ()
 
 confirmDeleteFile ()
 
 migrate ()
 
 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 74 of file class.ilFileVersionsGUI.php.

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

75  {
76  global $DIC;
77  $this->file = $file;
78  $this->ctrl = $DIC->ctrl();
79  $this->tpl = $DIC->ui()->mainTemplate();
80  $this->tabs = $DIC->tabs();
81  $this->http = $DIC->http();
82  $this->lng = $DIC->language();
83  $this->ref_id = (int) $this->http->request()->getQueryParams()['ref_id'];
84  $this->toolbar = $DIC->toolbar();
85  $this->access = $DIC->access();
86  $this->wsp_access = new ilWorkspaceAccessHandler();
87  $this->has_been_migrated = !empty($file->getResourceId());
88  }
Access handler for personal workspace.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: goto.php:24
+ 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 164 of file class.ilFileVersionsGUI.php.

Referenced by executeCommand().

165  {
166  if (!$this->has_been_migrated) {
167  return;
168  }
169  $this->tabs->clearTargets();
170  $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, self::CMD_DEFAULT));
171 
172  $form = new ilFileVersionFormGUI($this, $mode);
173  $form->fillForm();
174  $this->tpl->setContent($form->getHTML());
175  }
Class ilFileVersionFormGUI.
+ Here is the caller graph for this function:

◆ confirmDeleteFile()

ilFileVersionsGUI::confirmDeleteFile ( )
private

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

References $DIC.

Referenced by executeCommand().

311  {
312  if (!$this->has_been_migrated) {
313  return;
314  }
315  global $DIC;
316 
317  $parent_id = $DIC->repositoryTree()->getParentId($this->ref_id);
318 
319  $ru = new ilRepUtilGUI($this);
320  $ru->deleteObjects($parent_id, array($this->ref_id));
321 
322  // redirect to parent object
323  $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $parent_id);
324  $this->ctrl->redirectByClass(ilRepositoryGUI::class);
325  }
global $DIC
Definition: goto.php:24
Repository GUI Utilities.
+ Here is the caller graph for this function:

◆ confirmDeleteVersions()

ilFileVersionsGUI::confirmDeleteVersions ( )
private

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

References getVersionIdsFromRequest().

Referenced by executeCommand().

295  {
296  if (!$this->has_been_migrated) {
297  return;
298  }
299  // delete versions after confirmation
300  $versions_to_delete = $this->getVersionIdsFromRequest();
301  if (is_array($versions_to_delete) && count($versions_to_delete) > 0) {
302  $this->file->deleteVersions($versions_to_delete);
303  ilUtil::sendSuccess($this->lng->txt("file_versions_deleted"), true);
304  }
305 
306  $this->ctrl->setParameter($this, self::HIST_ID, "");
307  $this->ctrl->redirect($this, self::CMD_DEFAULT);
308  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteVersions()

ilFileVersionsGUI::deleteVersions ( )
private

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

References Vendor\Package\$a, Vendor\Package\$b, ilObject\_getIcon(), getVersionIdsFromRequest(), ilUtil\sendFailure(), and ilUtil\sendQuestion().

Referenced by executeCommand().

206  {
207  if (!$this->has_been_migrated) {
208  return;
209  }
210 
211  $version_ids = $this->getVersionIdsFromRequest();
212  $existing_versions = $this->file->getVersions();
213  $remaining_versions = array_udiff(
214  $existing_versions,
215  $version_ids,
216  static function ($a, $b) {
217  if ($a instanceof ilObjFileVersion) {
218  $a = $a->getHistEntryId();
219  }
220  if ($b instanceof ilObjFileVersion) {
221  $b = $b->getHistEntryId();
222  }
223  return $a - $b;
224  }
225  );
226 
227  if (count($version_ids) < 1) {
228  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
229  $this->ctrl->redirect($this, self::CMD_DEFAULT);
230  } else {
231  $conf_gui = new ilConfirmationGUI();
232  $conf_gui->setFormAction($this->ctrl->getFormAction($this, self::CMD_DEFAULT));
233  $conf_gui->setCancel($this->lng->txt("cancel"), self::CMD_DEFAULT);
234 
235  $icon = ilObject::_getIcon($this->file->getId(), "small", $this->file->getType());
236  $alt = $this->lng->txt("icon") . " " . $this->lng->txt("obj_" . $this->file->getType());
237 
238  if (count($remaining_versions) < 1) {
239  // Ask
240  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_all_versions"));
241 
242  $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_FILE);
243  $conf_gui->addItem(
244  "id[]",
245  $this->ref_id,
246  $this->file->getTitle(),
247  $icon,
248  $alt
249  );
250  } else {
251  // Ask
252  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_versions"));
253 
254  $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_VERSIONS);
255 
256  foreach ($this->file->getVersions($version_ids) as $version) {
257  $a_text = $version['filename'] ?? $version->getFilename() ?? $this->file->getTitle();
258  $version_string = $version['hist_id'] ?? $version->getVersion();
259  $a_text .= " (v" . $version_string . ")";
260  $conf_gui->addItem(
261  "hist_id[]",
262  $version['hist_entry_id'],
263  $a_text,
264  $icon,
265  $alt
266  );
267  }
268  }
269 
270  $this->tpl->setContent($conf_gui->getHTML());
271  }
272  }
Class ilObjFileVersion.
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
Confirmation screen class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ downloadVersion()

ilFileVersionsGUI::downloadVersion ( )
private

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

References $_GET, and Vendor\Package\$e.

Referenced by executeCommand().

197  {
198  $version = (int) $_GET[self::HIST_ID];
199  $this->file->sendFile($version);
200  try {
201  } catch (FileNotFoundException $e) {
202  }
203  }
$_GET["client_id"]
Class FileNotFoundException Indicates that a file is missing or not found.
+ Here is the caller graph for this function:

◆ executeCommand()

ilFileVersionsGUI::executeCommand ( )

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

References addVersion(), confirmDeleteFile(), confirmDeleteVersions(), deleteVersions(), downloadVersion(), hasPermission(), index(), migrate(), ilFileVersionFormGUI\MODE_ADD, ilFileVersionFormGUI\MODE_REPLACE, rollbackVersion(), saveVersion(), and ilUtil\sendFailure().

91  {
92  // bugfix mantis 26007: use new function hasPermission to ensure that the check also works for workspace files
93  if (!$this->hasPermission('write')) {
94  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
95  $this->ctrl->returnToParent($this);
96  }
97  $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
98 
99  switch ($cmd) {
100  case self::CMD_DEFAULT:
101  $this->index();
102  break;
103  case self::CMD_DOWNLOAD_VERSION:
104  $this->downloadVersion();
105  break;
106  case self::CMD_DELETE_VERSIONS:
107  $this->deleteVersions();
108  break;
109  case self::CMD_ROLLBACK_VERSION:
110  $this->rollbackVersion();
111  break;
112  case self::CMD_ADD_NEW_VERSION:
114  break;
115  case self::CMD_ADD_REPLACING_VERSION:
117  break;
118  case self::CMD_CREATE_NEW_VERSION:
120  // no break
121  case self::CMD_CREATE_REPLACING_VERSION:
123  break;
124  case self::CMD_CONFIRMED_DELETE_VERSIONS:
125  $this->confirmDeleteVersions();
126  break;
127  case self::CMD_CONFIRMED_DELETE_FILE:
128  $this->confirmDeleteFile();
129  break;
130  case self::CMD_MIGRATE:
131  $this->migrate();
132  break;
133  }
134  }
saveVersion($mode=ilFileVersionFormGUI::MODE_ADD)
addVersion($mode=ilFileVersionFormGUI::MODE_ADD)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
hasPermission($a_permission)
bugfix mantis 26007: this function was created to ensure that the access check not only works for rep...
+ Here is the call graph for this function:

◆ getFile()

ilFileVersionsGUI::getFile ( )
Returns
ilObjFile

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

References $file.

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

342  : ilObjFile
343  {
344  return $this->file;
345  }
+ Here is the caller graph for this function:

◆ getVersionIdsFromRequest()

ilFileVersionsGUI::getVersionIdsFromRequest ( )
private
Returns
array

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

References $i, and ILIAS\FileDelivery\http().

Referenced by confirmDeleteVersions(), deleteVersions(), and rollbackVersion().

350  : array
351  {
352  // get ids either from GET (if single item was clicked) or
353  // from POST (if multiple items were selected)
354  $request = $this->http->request();
355 
356  $version_ids = [];
357  if (isset($request->getQueryParams()[self::HIST_ID])) {
358  $version_ids = [$request->getQueryParams()[self::HIST_ID]];
359  } elseif (isset($request->getParsedBody()[self::HIST_ID])) {
360  $version_ids = (array) $request->getParsedBody()[self::HIST_ID];
361  }
362 
363  array_walk($version_ids, static function (&$i) {
364  $i = (int) $i;
365  });
366 
367  return $version_ids;
368  }
static http()
Fetches the global http state from ILIAS.
$i
Definition: metadata.php:24
+ 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 374 of file class.ilFileVersionsGUI.php.

374  : array
375  {
376  $versions_to_keep = $this->file->getVersions();
377  array_udiff($versions_to_keep, $version_ids, static function ($v1, $v2) {
378  if (is_array($v1) || $v1 instanceof ilObjFileVersion) {
379  $v1 = (int) $v1["hist_entry_id"];
380  } else {
381  if (!is_numeric($v1)) {
382  $v1 = (int) $v1;
383  }
384  }
385 
386  if (is_array($v2) || $v2 instanceof ilObjFileVersion) {
387  $v2 = (int) $v2["hist_entry_id"];
388  } else {
389  if (!is_numeric($v2)) {
390  $v2 = (int) $v2;
391  }
392  }
393 
394  return $v1 === $v2;
395  });
396 
397  return $versions_to_keep;
398  }
Class ilObjFileVersion.

◆ 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 407 of file class.ilFileVersionsGUI.php.

References $_GET.

Referenced by executeCommand().

408  {
409  // determine if the permission check concerns a workspace- or repository-object
410  if (isset($_GET['wsp_id'])) {
411  // permission-check concerning a workspace object
412  if ($this->wsp_access->checkAccess($a_permission, "", $this->ref_id)) {
413  return true;
414  }
415  } else {
416  // permission-check concerning a repository object
417  if ($this->access->checkAccess($a_permission, '', $this->ref_id)) {
418  return true;
419  }
420  }
421 
422  return false;
423  }
$_GET["client_id"]
+ Here is the caller graph for this function:

◆ index()

ilFileVersionsGUI::index ( )
private

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

References ilLinkButton\getInstance(), and ilUtil\sendInfo().

Referenced by executeCommand().

137  {
138  // Buttons
139  if ($this->has_been_migrated) {
140  $add_version = ilLinkButton::getInstance();
141  $add_version->setCaption('file_new_version');
142  $add_version->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD_NEW_VERSION));
143  $this->toolbar->addButtonInstance($add_version);
144 
145  $replace_version = ilLinkButton::getInstance();
146  $replace_version->setCaption('replace_file');
147  $replace_version->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD_REPLACING_VERSION));
148  $this->toolbar->addButtonInstance($replace_version);
149  } else {
150  $migrate = ilLinkButton::getInstance();
151  $migrate->setCaption('migrate');
152  $migrate->setUrl($this->ctrl->getLinkTarget($this, self::CMD_MIGRATE));
153 // $this->toolbar->addButtonInstance($migrate);
154  ilUtil::sendInfo($this->lng->txt('not_yet_migrated'));
155  }
156 
157  $table = new ilFileVersionsTableGUI($this, self::CMD_DEFAULT);
158  $this->tpl->setContent($table->getHTML());
159  }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilFileVersionsTableGUI.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrate()

ilFileVersionsGUI::migrate ( )
private

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

References $DIC, CLIENT_DATA_DIR, and ilFileObjectToStorageMigrationRunner\migrate().

Referenced by executeCommand().

327  : void
328  {
329  global $DIC;
330  $migration = new ilFileObjectToStorageMigrationRunner(
331  $DIC->fileSystem()->storage(),
332  $DIC->database(),
333  rtrim(CLIENT_DATA_DIR, "/") . '/ilFile/migration_log.csv'
334  );
335  $migration->migrate(new ilFileObjectToStorageDirectory($this->file->getId(), $this->file->getDirectory()));
336  $this->ctrl->redirect($this, self::CMD_DEFAULT);
337  }
Class ilFileObjectToStorageDirectory.
const CLIENT_DATA_DIR
Definition: constants.php:44
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rollbackVersion()

ilFileVersionsGUI::rollbackVersion ( )
private

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

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

Referenced by executeCommand().

275  {
276  if (!$this->has_been_migrated) {
277  return;
278  }
279  $version_ids = $this->getVersionIdsFromRequest();
280 
281  // more than one entry selected?
282  if (count($version_ids) != 1) {
283  ilUtil::sendInfo($this->lng->txt("file_rollback_select_exact_one"), true);
284  $this->ctrl->redirect($this, self::CMD_DEFAULT);
285  }
286 
287  // rollback the version
288  $new_version = $this->file->rollback($version_ids[0]);
289 
290  ilUtil::sendSuccess(sprintf($this->lng->txt("file_rollback_done"), $new_version["rollback_version"]), true);
291  $this->ctrl->redirect($this, self::CMD_DEFAULT);
292  }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
+ 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

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

Referenced by executeCommand().

183  {
184  if (!$this->has_been_migrated) {
185  return;
186  }
187  $form = new ilFileVersionFormGUI($this, $mode);
188  if ($form->saveObject()) {
189  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
190  $this->ctrl->redirect($this, self::CMD_DEFAULT);
191  }
192  $form->setValuesByPost();
193  $this->tpl->setContent($form->getHTML());
194  }
Class ilFileVersionFormGUI.
+ 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().

◆ $has_been_migrated

ilFileVersionsGUI::$has_been_migrated = false
protected

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

◆ $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 20 of file class.ilFileVersionsGUI.php.

◆ CMD_ADD_REPLACING_VERSION

const ilFileVersionsGUI::CMD_ADD_REPLACING_VERSION = 'addReplacingVersion'

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

◆ CMD_CANCEL_DELETE

const ilFileVersionsGUI::CMD_CANCEL_DELETE = "cancelDeleteFile"

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

◆ CMD_CONFIRMED_DELETE_FILE

const ilFileVersionsGUI::CMD_CONFIRMED_DELETE_FILE = "confirmDeleteFile"

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

◆ CMD_CONFIRMED_DELETE_VERSIONS

const ilFileVersionsGUI::CMD_CONFIRMED_DELETE_VERSIONS = 'confirmDeleteVersions'

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

◆ CMD_CREATE_NEW_VERSION

const ilFileVersionsGUI::CMD_CREATE_NEW_VERSION = 'saveVersion'

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

Referenced by ilFileVersionFormGUI\initForm().

◆ CMD_CREATE_REPLACING_VERSION

const ilFileVersionsGUI::CMD_CREATE_REPLACING_VERSION = 'createReplacingVersion'

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

Referenced by 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 15 of file class.ilFileVersionsGUI.php.

Referenced by ilFileVersionsTableGUI\fillRow().

◆ CMD_MIGRATE

const ilFileVersionsGUI::CMD_MIGRATE = 'migrate'

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

◆ CMD_ROLLBACK_VERSION

const ilFileVersionsGUI::CMD_ROLLBACK_VERSION = "rollbackVersion"

◆ HIST_ID

const ilFileVersionsGUI::HIST_ID = 'hist_id'

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

Referenced by ilFileVersionsTableGUI\fillRow().


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