ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
13{
17 protected $lng;
18
22 protected $settings;
23
27 protected $ctrl;
28
32 protected $tpl;
33
37 protected $obj_definition;
38
42 protected $access;
43
47 protected $tree;
48
49
56 public function __construct($a_parent_gui, $a_parent_cmd = "")
57 {
58 global $DIC;
59
60 $this->lng = $DIC->language();
61 $this->settings = $DIC->settings();
62 $this->ctrl = $DIC->ctrl();
63 $this->tpl = $DIC["tpl"];
64 $this->obj_definition = $DIC["objDefinition"];
65 $this->access = $DIC->access();
66 $this->tree = $DIC->repositoryTree();
67 $this->parent_gui = $a_parent_gui;
68 $this->parent_cmd = $a_parent_cmd;
69 }
70
71
75 public function showDeleteConfirmation($a_ids, $a_supress_message = false)
76 {
81 $objDefinition = $this->obj_definition;
82
83 if (!is_array($a_ids) || count($a_ids) == 0) {
84 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
85 return false;
86 }
87
88 // Remove duplicate entries
89 $a_ids = array_unique((array) $a_ids);
90
91 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
92 $cgui = new ilConfirmationGUI();
93
94 if (!$a_supress_message) {
95 $msg = $lng->txt("info_delete_sure");
96
97 if (!$ilSetting->get('enable_trash')) {
98 $msg .= "<br/>" . $lng->txt("info_delete_warning_no_trash");
99 }
100
101 $cgui->setHeaderText($msg);
102 }
103 $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
104 $cgui->setCancel($lng->txt("cancel"), "cancelDelete");
105 $cgui->setConfirm($lng->txt("confirm"), "confirmedDelete");
106
107 $form_name = "cgui_" . md5(uniqid());
108 $cgui->setFormName($form_name);
109
110 $deps = array();
111 foreach ($a_ids as $ref_id) {
112 $obj_id = ilObject::_lookupObjId($ref_id);
113 $type = ilObject::_lookupType($obj_id);
114 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
115 $alt = ($objDefinition->isPlugin($type))
116 ? $lng->txt("icon") . " " . ilObjectPlugin::lookupTxtById($type, "obj_" . $type)
117 : $lng->txt("icon") . " " . $lng->txt("obj_" . $type);
118
119 $title .= $this->handleMultiReferences($obj_id, $ref_id, $form_name);
120
121 $cgui->addItem(
122 "id[]",
123 $ref_id,
124 $title,
125 ilObject::_getIcon($obj_id, "small", $type),
126 $alt
127 );
128
129 ilObject::collectDeletionDependencies($deps, $ref_id, $obj_id, $type);
130 }
131 $deps_html = "";
132
133 if (is_array($deps) && count($deps) > 0) {
134 include_once("./Services/Repository/classes/class.ilRepDependenciesTableGUI.php");
135 $tab = new ilRepDependenciesTableGUI($deps);
136 $deps_html = "<br/><br/>" . $tab->getHTML();
137 }
138
139 $tpl->setContent($cgui->getHTML() . $deps_html);
140 return true;
141 }
142
151 public function handleMultiReferences($a_obj_id, $a_ref_id, $a_form_name)
152 {
154 $ilAccess = $this->access;
156
157 // process
158
159 $all_refs = ilObject::_getAllReferences($a_obj_id);
160 if (sizeof($all_refs) > 1) {
161 $lng->loadLanguageModule("rep");
162
163 $may_delete_any = 0;
164 $counter = 0;
165 $items = array();
166 foreach ($all_refs as $mref_id) {
167 // not the already selected reference, no refs from trash
168 if ($mref_id != $a_ref_id && !$tree->isDeleted($mref_id)) {
169 if ($ilAccess->checkAccess("read", "", $mref_id)) {
170 $may_delete = false;
171 if ($ilAccess->checkAccess("delete", "", $mref_id)) {
172 $may_delete = true;
173 $may_delete_any++;
174 }
175
176 $items[] = array("id" => $mref_id,
177 "path" => array_shift($this->buildPath(array($mref_id))),
178 "delete" => $may_delete);
179 } else {
180 $counter++;
181 }
182 }
183 }
184
185
186 // render
187
188 $tpl = new ilTemplate("tpl.rep_multi_ref.html", true, true, "Services/Repository");
189
190 $tpl->setVariable("TXT_INTRO", $lng->txt("rep_multiple_reference_deletion_intro"));
191
192 if ($may_delete_any) {
193 $tpl->setVariable("TXT_INSTRUCTION", $lng->txt("rep_multiple_reference_deletion_instruction"));
194 }
195
196 if ($items) {
197 $var_name = "mref_id[]";
198
199 foreach ($items as $item) {
200 if ($item["delete"]) {
201 $tpl->setCurrentBlock("cbox");
202 $tpl->setVariable("ITEM_NAME", $var_name);
203 $tpl->setVariable("ITEM_VALUE", $item["id"]);
204 $tpl->parseCurrentBlock();
205 } else {
206 $tpl->setCurrentBlock("item_info");
207 $tpl->setVariable("TXT_ITEM_INFO", $lng->txt("rep_no_permission_to_delete"));
208 $tpl->parseCurrentBlock();
209 }
210
211 $tpl->setCurrentBlock("item");
212 $tpl->setVariable("ITEM_TITLE", $item["path"]);
213 $tpl->parseCurrentBlock();
214 }
215
216 if ($may_delete_any > 1) {
217 $tpl->setCurrentBlock("cbox");
218 $tpl->setVariable("ITEM_NAME", "sall_" . $a_ref_id);
219 $tpl->setVariable("ITEM_VALUE", "");
220 $tpl->setVariable("ITEM_ADD", " onclick=\"il.Util.setChecked('" .
221 $a_form_name . "', '" . $var_name . "', document." . $a_form_name .
222 ".sall_" . $a_ref_id . ".checked)\"");
223 $tpl->parseCurrentBlock();
224
225 $tpl->setCurrentBlock("item");
226 $tpl->setVariable("ITEM_TITLE", $lng->txt("select_all"));
227 $tpl->parseCurrentBlock();
228 }
229 }
230
231 if ($counter) {
232 $tpl->setCurrentBlock("add_info");
233 $tpl->setVariable(
234 "TXT_ADDITIONAL_INFO",
235 sprintf($lng->txt("rep_object_references_cannot_be_read"), $counter)
236 );
237 $tpl->parseCurrentBlock();
238 }
239
240 return $tpl->get();
241 }
242 }
243
249 public function showTrashTable($a_ref_id)
250 {
254
255 $objects = $tree->getSavedNodeData($a_ref_id);
256
257 if (count($objects) == 0) {
258 ilUtil::sendInfo($lng->txt("msg_trash_empty"));
259 return;
260 }
261 include_once("./Services/Repository/classes/class.ilTrashTableGUI.php");
262 $ttab = new ilTrashTableGUI($this->parent_gui, "trash");
263 $ttab->setData($objects);
264
265 $tpl->setContent($ttab->getHTML());
266 }
267
274 public function restoreObjects($a_cur_ref_id, $a_ref_ids)
275 {
277
278 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
279 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
280 return false;
281 } else {
282 try {
283 include_once("./Services/Repository/classes/class.ilRepUtil.php");
284 ilRepUtil::restoreObjects($a_cur_ref_id, $a_ref_ids);
285 ilUtil::sendSuccess($lng->txt("msg_undeleted"), true);
286 } catch (Exception $e) {
287 ilUtil::sendFailure($e->getMessage(), true);
288 return false;
289 }
290 }
291 return true;
292 }
293
297 public function deleteObjects($a_cur_ref_id, $a_ref_ids)
298 {
301
302 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
303 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
304 return false;
305 } else {
306 include_once("./Services/Repository/classes/class.ilRepUtil.php");
307 try {
308 ilRepUtil::deleteObjects($a_cur_ref_id, $a_ref_ids);
309 if ($ilSetting->get('enable_trash')) {
310 ilUtil::sendSuccess($lng->txt("info_deleted"), true);
311 } else {
312 ilUtil::sendSuccess($lng->txt("msg_removed"), true);
313 }
314 } catch (Exception $e) {
315 ilUtil::sendFailure($e->getMessage(), true);
316 return false;
317 }
318 }
319 }
320
324 public function removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder = false)
325 {
327
328 if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) {
329 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
330 return false;
331 } else {
332 include_once("./Services/Repository/classes/class.ilRepUtil.php");
333 try {
334 ilRepUtil::removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder);
335 ilUtil::sendSuccess($lng->txt("msg_removed"), true);
336 } catch (Exception $e) {
337 ilUtil::sendFailure($e->getMessage(), true);
338 return false;
339 }
340 }
341
342 return true;
343 }
344
351 protected function buildPath($ref_ids)
352 {
354
355 include_once 'Services/Link/classes/class.ilLink.php';
356
357 if (!count($ref_ids)) {
358 return false;
359 }
360
361 $result = array();
362 foreach ($ref_ids as $ref_id) {
363 $path = "";
364 $path_full = $tree->getPathFull($ref_id);
365 foreach ($path_full as $idx => $data) {
366 if ($idx) {
367 $path .= " &raquo; ";
368 }
369 if ($ref_id != $data['ref_id']) {
370 $path .= $data['title'];
371 } else {
372 $path .= ('<a target="_top" href="' .
373 ilLink::_getLink($data['ref_id'], $data['type']) . '">' .
374 $data['title'] . '</a>');
375 }
376 }
377
378 $result[] = $path;
379 }
380 return $result;
381 }
382
388 public function confirmRemoveFromSystemObject($a_ids)
389 {
392 $objDefinition = $this->obj_definition;
394 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
395
396 if (!is_array($a_ids)) {
397 $a_ids = array($a_ids);
398 }
399
400 $cgui = new ilConfirmationGUI();
401 $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
402 $cgui->setCancel($lng->txt("cancel"), "trash");
403 $cgui->setConfirm($lng->txt("confirm"), "removeFromSystem");
404 $cgui->setFormName("trash_confirmation");
405 $cgui->setHeaderText($lng->txt("info_delete_sure"));
406
407 foreach ($a_ids as $id) {
408 $obj_id = ilObject::_lookupObjId($id);
409 $type = ilObject::_lookupType($obj_id);
410 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
411 $alt = ($objDefinition->isPlugin($type))
412 ? $lng->txt("icon") . " " . ilObjectPlugin::lookupTxtById($type, "obj_" . $type)
413 : $lng->txt("icon") . " " . $lng->txt("obj_" . $type);
414
415 $cgui->addItem(
416 "trash_id[]",
417 $id,
418 $title,
419 ilObject::_getIcon($obj_id, "small", $type),
420 $alt
421 );
422 }
423
424 $tpl->setContent($cgui->getHTML());
425 }
426}
sprintf('%.4f', $callTime)
$result
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
Repository GUI Utilities.
showDeleteConfirmation($a_ids, $a_supress_message=false)
Show delete confirmation table.
restoreObjects($a_cur_ref_id, $a_ref_ids)
Restore objects from trash.
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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
$type
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2