ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilRepUtilGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
4
16{
20 protected $lng;
21
25 protected $settings;
26
30 protected $ctrl;
31
35 protected $tpl;
36
40 protected $obj_definition;
41
45 protected $access;
46
50 protected $tree;
51
52
56 private $logger = null;
57
58
65 public function __construct($a_parent_gui, $a_parent_cmd = "")
66 {
67 global $DIC;
68
69 $this->lng = $DIC->language();
70 $this->settings = $DIC->settings();
71 $this->ctrl = $DIC->ctrl();
72 $this->tpl = $DIC["tpl"];
73 $this->obj_definition = $DIC["objDefinition"];
74 $this->access = $DIC->access();
75 $this->tree = $DIC->repositoryTree();
76 $this->parent_gui = $a_parent_gui;
77 $this->parent_cmd = $a_parent_cmd;
78
79 $this->logger = $DIC->logger()->rep();
80 }
81
85 public function executeCommand()
86 {
87 global $DIC;
88
89 $logger = $DIC->logger()->rep();
90 $next_class = $this->ctrl->getNextClass($this);
91 switch ($next_class) {
92 case "ilpropertyformgui":
93 $form = $this->initFormTrashTargetLocation();
94 $this->ctrl->forwardCommand($form);
95 break;
96
97 default:
98 $cmd = $this->ctrl->getCmd('cancel');
99 $this->$cmd();
100 break;
101
102 }
103 }
104
108 protected function cancel()
109 {
110 $this->ctrl->returnToParent($this);
111 }
112
117 public function restoreToNewLocation(\ilPropertyFormGUI $form = null)
118 {
119 $this->lng->loadLanguageModule('rep');
120
121 if (isset($_POST['trash_id'])) {
122 $trash_ids = (array) $_POST['trash_id'];
123 } elseif (isset($_REQUEST['trash_ids'])) {
124 $trash_ids = explode(',', $_POST['trash_ids']);
125 }
126
127 $this->ctrl->setParameter($this, 'trash_ids', implode(',', $trash_ids));
128
129 if (!count($trash_ids)) {
130 \ilUtil::sendFailure($this->lng->txt('select_one'), true);
131 $this->ctrl->returnToParent($this);
132 }
133
134 if (!$form instanceof \ilPropertyFormGUI) {
135 $form = $this->initFormTrashTargetLocation();
136 }
137 \ilUtil::sendInfo($this->lng->txt('rep_target_location_info'));
138 $this->tpl->setContent($form->getHTML());
139 }
140
144 public function doRestoreToNewLocation()
145 {
146 $trash_ids = [];
147 if (isset($_REQUEST['trash_ids'])) {
148 $trash_ids = explode(',', $_REQUEST['trash_ids']);
149 }
150
151 $form = $this->initFormTrashTargetLocation();
152 if (!$form->checkInput() && count($trash_ids)) {
153 $this->lng->loadLanguageModule('search');
154 \ilUtil::sendFailure($this->lng->txt('search_no_selection'), true);
155 $this->ctrl->returnToParent($this);
156 }
157
158 try {
159 \ilRepUtil::restoreObjects($form->getInput('target_id'), $trash_ids);
160 \ilUtil::sendSuccess($this->lng->txt('msg_undeleted'), true);
161 $this->ctrl->returnToParent($this);
162 } catch (\ilRepositoryException $e) {
163 \ilUtil::sendFailure($e->getMessage(), true);
164 $this->ctrl->returnToParent($this);
165 }
166 }
167
171 protected function initFormTrashTargetLocation()
172 {
173 $form = new \ilPropertyFormGUI();
174 $form->setFormAction($this->ctrl->getFormAction($this));
175
176 $target = new \ilRepositorySelector2InputGUI(
177 $this->lng->txt('rep_target_location'),
178 'target_id',
179 false
180 );
181 $target->setRequired(true);
182
183 $explorer = new \ilRepositorySelectorExplorerGUI(
184 [
185 \ilAdministrationGUI::class,
186 get_class($this->parent_gui),
187 \ilRepUtilGUI::class,
188 \ilPropertyFormGUI::class,
189 \ilFormPropertyDispatchGUI::class,
190 \ilRepositorySelector2InputGUI::class
191 ],
192 'handleExplorerCommand',
193 $target,
194 'root_id',
195 'rep_exp_sel_' . $target->getPostVar()
196 );
197 $explorer->setSelectMode($target->getPostVar() . "_sel", false);
198 $explorer->setRootId(ROOT_FOLDER_ID);
199 $explorer->setTypeWhiteList(['root','cat','crs','grp','fold']);
200 $target->setExplorerGUI($explorer);
201
202 $form->addItem($target);
203 $form->addCommandButton('doRestoreToNewLocation', $this->lng->txt('btn_undelete'));
204 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
205
206 return $form;
207 }
208
209
213 public function showDeleteConfirmation($a_ids, $a_supress_message = false)
214 {
217 $ilCtrl = $this->ctrl;
219 $objDefinition = $this->obj_definition;
220
221 if (!is_array($a_ids) || count($a_ids) == 0) {
222 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
223 return false;
224 }
225
226 // Remove duplicate entries
227 $a_ids = array_unique((array) $a_ids);
228
229 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
230 $cgui = new ilConfirmationGUI();
231
232 if (!$a_supress_message) {
233 $msg = $lng->txt("info_delete_sure");
234
235 if (!$ilSetting->get('enable_trash')) {
236 $msg .= "<br/>" . $lng->txt("info_delete_warning_no_trash");
237 }
238
239 $cgui->setHeaderText($msg);
240 }
241 $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
242 $cgui->setCancel($lng->txt("cancel"), "cancelDelete");
243 $cgui->setConfirm($lng->txt("confirm"), "confirmedDelete");
244
245 $form_name = "cgui_" . md5(uniqid());
246 $cgui->setFormName($form_name);
247
248 $deps = array();
249 foreach ($a_ids as $ref_id) {
250 $obj_id = ilObject::_lookupObjId($ref_id);
251 $type = ilObject::_lookupType($obj_id);
252 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
253 $alt = ($objDefinition->isPlugin($type))
254 ? $lng->txt("icon") . " " . ilObjectPlugin::lookupTxtById($type, "obj_" . $type)
255 : $lng->txt("icon") . " " . $lng->txt("obj_" . $type);
256
257 $title .= $this->handleMultiReferences($obj_id, $ref_id, $form_name);
258
259 $cgui->addItem(
260 "id[]",
261 $ref_id,
262 $title,
263 ilObject::_getIcon($obj_id, "small", $type),
264 $alt
265 );
266
267 ilObject::collectDeletionDependencies($deps, $ref_id, $obj_id, $type);
268 }
269 $deps_html = "";
270
271 if (is_array($deps) && count($deps) > 0) {
272 include_once("./Services/Repository/classes/class.ilRepDependenciesTableGUI.php");
273 $tab = new ilRepDependenciesTableGUI($deps);
274 $deps_html = "<br/><br/>" . $tab->getHTML();
275 }
276
277 $tpl->setContent($cgui->getHTML() . $deps_html);
278 return true;
279 }
280
289 public function handleMultiReferences($a_obj_id, $a_ref_id, $a_form_name)
290 {
292 $ilAccess = $this->access;
294
295 // process
296
297 $all_refs = ilObject::_getAllReferences($a_obj_id);
298 if (sizeof($all_refs) > 1) {
299 $lng->loadLanguageModule("rep");
300
301 $may_delete_any = 0;
302 $counter = 0;
303 $items = array();
304 foreach ($all_refs as $mref_id) {
305 // not the already selected reference, no refs from trash
306 if ($mref_id != $a_ref_id && !$tree->isDeleted($mref_id)) {
307 if ($ilAccess->checkAccess("read", "", $mref_id)) {
308 $may_delete = false;
309 if ($ilAccess->checkAccess("delete", "", $mref_id)) {
310 $may_delete = true;
311 $may_delete_any++;
312 }
313
314 $items[] = array("id" => $mref_id,
315 "path" => array_shift($this->buildPath(array($mref_id))),
316 "delete" => $may_delete);
317 } else {
318 $counter++;
319 }
320 }
321 }
322
323
324 // render
325
326 $tpl = new ilTemplate("tpl.rep_multi_ref.html", true, true, "Services/Repository");
327
328 $tpl->setVariable("TXT_INTRO", $lng->txt("rep_multiple_reference_deletion_intro"));
329
330 if ($may_delete_any) {
331 $tpl->setVariable("TXT_INSTRUCTION", $lng->txt("rep_multiple_reference_deletion_instruction"));
332 }
333
334 if ($items) {
335 $var_name = "mref_id[]";
336
337 foreach ($items as $item) {
338 if ($item["delete"]) {
339 $tpl->setCurrentBlock("cbox");
340 $tpl->setVariable("ITEM_NAME", $var_name);
341 $tpl->setVariable("ITEM_VALUE", $item["id"]);
342 $tpl->parseCurrentBlock();
343 } else {
344 $tpl->setCurrentBlock("item_info");
345 $tpl->setVariable("TXT_ITEM_INFO", $lng->txt("rep_no_permission_to_delete"));
346 $tpl->parseCurrentBlock();
347 }
348
349 $tpl->setCurrentBlock("item");
350 $tpl->setVariable("ITEM_TITLE", $item["path"]);
351 $tpl->parseCurrentBlock();
352 }
353
354 if ($may_delete_any > 1) {
355 $tpl->setCurrentBlock("cbox");
356 $tpl->setVariable("ITEM_NAME", "sall_" . $a_ref_id);
357 $tpl->setVariable("ITEM_VALUE", "");
358 $tpl->setVariable("ITEM_ADD", " onclick=\"il.Util.setChecked('" .
359 $a_form_name . "', '" . $var_name . "', document." . $a_form_name .
360 ".sall_" . $a_ref_id . ".checked)\"");
361 $tpl->parseCurrentBlock();
362
363 $tpl->setCurrentBlock("item");
364 $tpl->setVariable("ITEM_TITLE", $lng->txt("select_all"));
365 $tpl->parseCurrentBlock();
366 }
367 }
368
369 if ($counter) {
370 $tpl->setCurrentBlock("add_info");
371 $tpl->setVariable(
372 "TXT_ADDITIONAL_INFO",
373 sprintf($lng->txt("rep_object_references_cannot_be_read"), $counter)
374 );
375 $tpl->parseCurrentBlock();
376 }
377
378 return $tpl->get();
379 }
380 }
381
387 public function showTrashTable($a_ref_id)
388 {
392
393 $objects = $tree->getSavedNodeData($a_ref_id);
394
395 if (count($objects) == 0) {
396 ilUtil::sendInfo($lng->txt("msg_trash_empty"));
397 return;
398 }
399 include_once("./Services/Repository/classes/class.ilTrashTableGUI.php");
400 $ttab = new ilTrashTableGUI($this->parent_gui, "trash");
401 $ttab->setData($objects);
402
403 $tpl->setContent($ttab->getHTML());
404 }
405
412 public function restoreObjects($a_cur_ref_id, $a_ref_ids)
413 {
415 $lng->loadLanguageModule('rep');
416
417 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
418 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
419 return false;
420 }
421
422 $tree_trash_queries = new \ilTreeTrashQueries();
423 if ($tree_trash_queries->isTrashedTrash($a_ref_ids)) {
424 \ilUtil::sendFailure($this->lng->txt('rep_failure_trashed_trash'), true);
425 return false;
426 }
427 try {
428
429 // find parent foreach node
430 $by_location = [];
431 foreach ($a_ref_ids as $deleted_node_id) {
432 $target_id = $tree_trash_queries->findRepositoryLocationForDeletedNode($deleted_node_id);
433 if ($target_id) {
434 $by_location[$target_id][] = $deleted_node_id;
435 }
436 }
437 foreach ($by_location as $target_id => $deleted_node_ids) {
438 \ilRepUtil::restoreObjects($target_id, $deleted_node_ids);
439 }
440 ilUtil::sendSuccess($lng->txt("msg_undeleted"), true);
441 } catch (Exception $e) {
442 ilUtil::sendFailure($e->getMessage(), true);
443 return false;
444 }
445 return true;
446 }
447
451 public function deleteObjects($a_cur_ref_id, $a_ref_ids)
452 {
455
456 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
457 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
458 return false;
459 } else {
460 include_once("./Services/Repository/classes/class.ilRepUtil.php");
461 try {
462 ilRepUtil::deleteObjects($a_cur_ref_id, $a_ref_ids);
463 if ($ilSetting->get('enable_trash')) {
464 ilUtil::sendSuccess($lng->txt("info_deleted"), true);
465 } else {
466 ilUtil::sendSuccess($lng->txt("msg_removed"), true);
467 }
468 } catch (Exception $e) {
469 ilUtil::sendFailure($e->getMessage(), true);
470 return false;
471 }
472 }
473 }
474
478 public function removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder = false)
479 {
481
482 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
483 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
484 return false;
485 } else {
486 include_once("./Services/Repository/classes/class.ilRepUtil.php");
487 try {
488 ilRepUtil::removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder);
489 ilUtil::sendSuccess($lng->txt("msg_removed"), true);
490 } catch (Exception $e) {
491 ilUtil::sendFailure($e->getMessage(), true);
492 return false;
493 }
494 }
495
496 return true;
497 }
498
505 protected function buildPath($ref_ids)
506 {
508
509 include_once 'Services/Link/classes/class.ilLink.php';
510
511 if (!count($ref_ids)) {
512 return false;
513 }
514
515 $result = array();
516 foreach ($ref_ids as $ref_id) {
517 $path = "";
518 $path_full = $tree->getPathFull($ref_id);
519 foreach ($path_full as $idx => $data) {
520 if ($idx) {
521 $path .= " &raquo; ";
522 }
523 if ($ref_id != $data['ref_id']) {
524 $path .= $data['title'];
525 } else {
526 $path .= ('<a target="_top" href="' .
527 ilLink::_getLink($data['ref_id'], $data['type']) . '">' .
528 $data['title'] . '</a>');
529 }
530 }
531
532 $result[] = $path;
533 }
534 return $result;
535 }
536
542 public function confirmRemoveFromSystemObject($a_ids)
543 {
544 $ilCtrl = $this->ctrl;
546 $objDefinition = $this->obj_definition;
548 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
549
550 if (!is_array($a_ids)) {
551 $a_ids = array($a_ids);
552 }
553
554 $cgui = new ilConfirmationGUI();
555 $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
556 $cgui->setCancel($lng->txt("cancel"), "trash");
557 $cgui->setConfirm($lng->txt("confirm"), "removeFromSystem");
558 $cgui->setFormName("trash_confirmation");
559 $cgui->setHeaderText($lng->txt("info_delete_sure"));
560
561 foreach ($a_ids as $id) {
562 $obj_id = ilObject::_lookupObjId($id);
563 $type = ilObject::_lookupType($obj_id);
564 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
565 $alt = ($objDefinition->isPlugin($type))
566 ? $lng->txt("icon") . " " . ilObjectPlugin::lookupTxtById($type, "obj_" . $type)
567 : $lng->txt("icon") . " " . $lng->txt("obj_" . $type);
568
569 $cgui->addItem(
570 "trash_id[]",
571 $id,
572 $title,
573 ilObject::_getIcon($obj_id, "small", $type),
574 $alt
575 );
576 }
577
578 $tpl->setContent($cgui->getHTML());
579 }
580}
$result
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
static getClassByType($a_obj_type)
Get class by type.
static lookupTxtById($plugin_id, $lang_var)
static _lookupObjId($a_id)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _getAllReferences($a_id)
get all reference ids of object
static collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
Collect deletion dependencies.
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
Repository GUI Utilities.
showDeleteConfirmation($a_ids, $a_supress_message=false)
Show delete confirmation table.
restoreToNewLocation(\ilPropertyFormGUI $form=null)
restoreObjects($a_cur_ref_id, $a_ref_ids)
Restore objects from trash.
cancel()
Cancel action.
deleteObjects($a_cur_ref_id, $a_ref_ids)
Delete objects.
__construct($a_parent_gui, $a_parent_cmd="")
Constructor.
buildPath($ref_ids)
Build path with deep-link.
doRestoreToNewLocation()
Perform restore to new location.
showTrashTable($a_ref_id)
Get trashed objects for a container.
removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder=false)
Remove objects from system.
handleMultiReferences($a_obj_id, $a_ref_id, $a_form_name)
Build subitem list for multiple references.
confirmRemoveFromSystemObject($a_ids)
Confirmation for trash.
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.
static restoreObjects($a_cur_ref_id, $a_ref_ids)
Move objects from trash back to repository.
static removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder=false)
remove objects from trash bin and all entries therefore every object needs a specific deleteObject() ...
special template class to simplify handling of ITX/PEAR
TableGUI class for.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
global $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23