ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjectCopyGUI.php
Go to the documentation of this file.
1<?php
2
20
33{
37 protected $ctrl;
38
42 protected $tree;
43
47 protected $tabs;
48
52 protected $toolbar;
53
57 protected $tpl;
58
62 protected $obj_definition;
63
67 protected $obj_data_cache;
68
72 protected $access;
73
77 protected $error;
78
82 protected $rbacsystem;
83
87 protected $user;
88
92 protected $rbacreview;
93
96 const SEARCH_SOURCE = 3;
97
100
101 // tabs
105
106 // group selection of source or target
108
109
110 private $mode = 0;
112
113 private $lng;
114
115 private $parent_obj = null;
116
117 private $type = '';
118
119 private $sources = array();
120
121 // begin-patch multi copy
122 private $targets = array();
123 private $targets_copy_id = array();
124 // end-patch multi copy
125
129 private $log = null;
130
131 public function __construct(ImplementsCreationCallback $a_parent_gui)
132 {
133 global $DIC;
134
135 $this->ctrl = $DIC->ctrl();
136 $this->tree = $DIC->repositoryTree();
137 $this->tabs = $DIC->tabs();
138 $this->toolbar = $DIC->toolbar();
139 $this->tpl = $DIC["tpl"];
140 $this->obj_definition = $DIC["objDefinition"];
141 $this->obj_data_cache = $DIC["ilObjDataCache"];
142 $this->access = $DIC->access();
143 $this->error = $DIC["ilErr"];
144 $this->rbacsystem = $DIC->rbac()->system();
145 $this->user = $DIC->user();
146 $this->rbacreview = $DIC->rbac()->review();
147 $this->log = $DIC["ilLog"];
148 $ilCtrl = $DIC->ctrl();
149 $lng = $DIC->language();
150
151 $this->lng = $lng;
152 $this->lng->loadLanguageModule('search');
153 $this->lng->loadLanguageModule('obj');
154 $this->ctrl->saveParameter($this, "crtcb");
155
156 $this->parent_obj = $a_parent_gui;
157
158 $this->log = ilLoggerFactory::getLogger('obj');
159 }
160
165 public function executeCommand()
166 {
167 $ilCtrl = $this->ctrl;
168
169 $this->init();
170 $this->initTabs();
171
172 $next_class = $ilCtrl->getNextClass($this);
173 $cmd = $ilCtrl->getCmd();
174
175 switch ($next_class) {
176 default:
177 $this->$cmd();
178 break;
179 }
180 }
181
186 protected function init()
187 {
188 $ilCtrl = $this->ctrl;
189
190 if ((int) $_REQUEST['smode']) {
191 $this->setSubMode((int) $_REQUEST['smode']);
192 $ilCtrl->setParameter($this, 'smode', $this->getSubMode());
193 ilLoggerFactory::getLogger('obj')->debug('Submode is: ' . $this->getSubMode());
194 }
195
196 // save sources
197 if ($_REQUEST['source_ids']) {
198 $this->setSource(explode('_', $_REQUEST['source_ids']));
199 $ilCtrl->setParameter($this, 'source_ids', implode('_', $this->getSources()));
200 ilLoggerFactory::getLogger('obj')->debug('Multiple sources: ' . implode('_', $this->getSources()));
201 }
202 if ($_REQUEST['source_id']) {
203 $this->setSource(array((int) $_REQUEST['source_id']));
204 $ilCtrl->setParameter($this, 'source_ids', implode('_', $this->getSources()));
205 ilLoggerFactory::getLogger('obj')->debug('source_id is set: ' . implode('_', $this->getSources()));
206 }
207 if ($this->getFirstSource()) {
208 $this->setType(
210 );
211 }
212
213 // creation screen: copy section
214 if ($_REQUEST['new_type']) {
215 $this->setMode(self::SEARCH_SOURCE);
216 $this->setType($_REQUEST['new_type']);
217 $this->setTarget((int) $_GET['ref_id']);
218
219 $ilCtrl->setParameter($this, 'new_type', $this->getType());
220 $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'new_type', $this->getType());
221 $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'cpfl', 1);
222 $ilCtrl->setReturnByClass(get_class($this->getParentObject()), 'create');
223
224 ilLoggerFactory::getLogger('obj')->debug('Copy from object creation for type: ' . $this->getType());
225 return true;
226 }
227 // adopt content, and others?
228 elseif ($_REQUEST['selectMode'] == self::SOURCE_SELECTION) {
229 $this->setMode(self::SOURCE_SELECTION);
230
231 $ilCtrl->setParameterByClass(get_class($this->parent_obj), 'selectMode', self::SOURCE_SELECTION);
232 $this->setTarget((int) $_GET['ref_id']);
233 $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
234
235 ilLoggerFactory::getLogger('obj')->debug('Source selection mode. Target is: ' . $this->getFirstTarget());
236 } elseif ($_REQUEST['selectMode'] == self::TARGET_SELECTION) {
237 $this->setMode(self::TARGET_SELECTION);
238 $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
239 ilLoggerFactory::getLogger('obj')->debug('Target selection mode.');
240 }
241
242
243 // save targets
244 if ($_REQUEST['target_ids']) {
245 $this->setTargets(explode('_', $_REQUEST['target_ids']));
246 ilLoggerFactory::getLogger('obj')->debug('targets are: ' . print_r($this->getTargets(), true));
247 }
248 }
249
254 protected function initTabs()
255 {
257 $ilTabs = $this->tabs;
258 $ilCtrl = $this->ctrl;
259
260 $lng->loadLanguageModule('cntr');
261 $ilTabs->clearTargets();
262 $ilTabs->setBackTarget(
263 $lng->txt('tab_back_to_repository'),
264 $ilCtrl->getParentReturn($this->parent_obj)
265 );
266 }
267
273 protected function setTabs($a_tab_group, $a_active_tab)
274 {
276 $ilTabs = $this->tabs;
277 $ilCtrl = $this->ctrl;
278
279 if ($a_tab_group == self::TAB_GROUP_SC_SELECTION) {
280 if ($this->getSubMode() == self::SUBMODE_CONTENT_ONLY) {
281 if ($this->getMode() == self::SOURCE_SELECTION) {
282 $ilTabs->addTab(
283 self::TAB_SELECTION_SOURCE_TREE,
284 $lng->txt('cntr_copy_repo_tree'),
285 $ilCtrl->getLinkTarget($this, 'initSourceSelection')
286 );
287 $ilTabs->addTab(
288 self::TAB_SELECTION_MEMBERSHIP,
289 $lng->txt('cntr_copy_crs_grp'),
290 $ilCtrl->getLinkTarget($this, 'showSourceSelectionMembership')
291 );
292 }
293 }
294 }
295 $ilTabs->activateTab($a_active_tab);
296 }
297
298
303 protected function adoptContent()
304 {
305 $ilCtrl = $this->ctrl;
306
307 $ilCtrl->setParameter($this, 'smode', self::SUBMODE_CONTENT_ONLY);
308 $ilCtrl->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
309
310
311 $this->setSubMode(self::SUBMODE_CONTENT_ONLY);
312 $this->setMode(self::SOURCE_SELECTION);
313 $this->setTarget((int) $_GET['ref_id']);
314
315
316 return $this->initSourceSelection();
317 }
318
323 protected function initTargetSelection()
324 {
325 $ilCtrl = $this->ctrl;
327 $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
328 // empty session on init
329 $_SESSION['paste_copy_repexpand'] = array();
330
331 // copy opened nodes from repository explorer
332 $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
333
334 // begin-patch mc
335 $this->setTargets(array());
336 // cognos-blu-patch: end
337
338 // open current position
339
340 foreach ($this->getSources() as $source_id) {
341 if ($source_id) {
342 $path = $tree->getPathId($source_id);
343 foreach ((array) $path as $node_id) {
344 if (!in_array($node_id, $_SESSION['paste_copy_repexpand'])) {
345 $_SESSION['paste_copy_repexpand'][] = $node_id;
346 }
347 }
348 }
349 }
350
351 $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
353 }
354
359 protected function initSourceSelection()
360 {
361 $ilCtrl = $this->ctrl;
363
364 // empty session on init
365 $_SESSION['paste_copy_repexpand'] = array();
366
367 // copy opened nodes from repository explorer
368 $_SESSION['paste_copy_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
369
370 $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_SOURCE_TREE);
371
372
373 // open current position
374 // begin-patch mc
375 foreach ($this->getTargets() as $target_ref_id) {
376 $path = $tree->getPathId($target_ref_id);
377 foreach ((array) $path as $node_id) {
378 if (!in_array($node_id, $_SESSION['paste_copy_repexpand'])) {
379 $_SESSION['paste_copy_repexpand'][] = $node_id;
380 }
381 }
382 }
383 // end-patch multi copy
384 $ilCtrl->setReturnByClass(get_class($this->parent_obj), '');
386 }
387
388
392 protected function showSourceSelectionMembership()
393 {
396
397 ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
398 $this->setTabs(self::TAB_GROUP_SC_SELECTION, self::TAB_SELECTION_MEMBERSHIP);
399
400 include_once './Services/Object/classes/class.ilObjectCopyCourseGroupSelectionTableGUI.php';
401 $cgs = new ilObjectCopyCourseGroupSelectionTableGUI($this, 'showSourceSelectionMembership', 'copy_selection_membership');
402 $cgs->init();
403 $cgs->setObjects(
404 array_merge(
405 ilParticipants::_getMembershipByType($user->getId(), 'crs', false),
406 ilParticipants::_getMembershipByType($user->getId(), 'grp', false)
407 )
408 );
409 $cgs->parse();
410
411 $tpl->setContent($cgs->getHTML());
412 }
413
414
418 public function showTargetSelectionTree()
419 {
420 $ilTabs = $this->tabs;
421 $ilToolbar = $this->toolbar;
422 $ilCtrl = $this->ctrl;
425 $objDefinition = $this->obj_definition;
427
428 $this->tpl = $tpl;
429
430 if ($objDefinition->isContainer($this->getType())) {
431 ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_container'));
432 } else {
433 ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard'));
434 }
435
436 //
437 include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
438 $exp = new ilRepositorySelectorExplorerGUI($this, "showTargetSelectionTree");
439 $exp->setTypeWhiteList(array("root", "cat", "grp", "crs", "fold", "lso", "prg"));
440 $exp->setSelectMode("target", true);
441 if ($exp->handleCommand()) {
442 return;
443 }
444 $output = $exp->getHTML();
445
446 // toolbars
447 $t = new ilToolbarGUI();
448 $t->setFormAction($ilCtrl->getFormAction($this, "saveTarget"));
449 if ($objDefinition->isContainer($this->getType())) {
451 $btn->setCaption('btn_next');
452 $btn->setCommand('saveTarget');
453 $btn->setPrimary(true);
454 $t->addButtonInstance($btn);
455 } else {
457 $btn->setCaption('paste');
458 $btn->setCommand('saveTarget');
459 $btn->setPrimary(true);
460 $t->addButtonInstance($btn);
461 }
462 $t->addSeparator();
463 $clipboard_btn = ilSubmitButton::getInstance();
464 $clipboard_btn->setCaption('obj_insert_into_clipboard');
465 $clipboard_btn->setCommand('keepObjectsInClipboard');
466 $t->addButtonInstance($clipboard_btn);
467 $cancel_btn = ilSubmitButton::getInstance();
468 $cancel_btn->setCaption('cancel');
469 $cancel_btn->setCommand('cancel');
470 $t->addButtonInstance($cancel_btn);
471 $t->setCloseFormTag(false);
472 $t->setLeadingImage(ilUtil::getImagePath("arrow_upright.svg"), " ");
473 $output = $t->getHTML() . $output;
474 $t->setLeadingImage(ilUtil::getImagePath("arrow_downright.svg"), " ");
475 $t->setCloseFormTag(true);
476 $t->setOpenFormTag(false);
477 $output .= "<br />" . $t->getHTML();
478
479 $this->tpl->setContent($output);
480
481 return;
482 }
483
487 public function showSourceSelectionTree()
488 {
489 $ilToolbar = $this->toolbar;
490 $ilCtrl = $this->ctrl;
493
494 $this->tpl = $tpl;
495 $this->tpl->addBlockfile(
496 'ADM_CONTENT',
497 'adm_content',
498 'tpl.paste_into_multiple_objects.html',
499 "Services/Object"
500 );
501
502 ilUtil::sendInfo($this->lng->txt('msg_copy_clipboard_source'));
503 include_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
506 'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto',
507 'paste_copy_repexpand'
508 );
509 $exp->setRequiredFormItemPermission('visible,read,copy');
510
511 $ilCtrl->setParameter($this, 'selectMode', self::SOURCE_SELECTION);
512 $exp->setExpandTarget($ilCtrl->getLinkTarget($this, 'showSourceSelectionTree'));
513 $exp->setTargetGet('ref_id');
514 $exp->setPostVar('source');
515 $exp->setCheckedItems($this->getSources());
516
517 // Filter to container
518 foreach (array('cat','root','fold') as $container) {
519 $exp->removeFormItemForType($container);
520 }
521
522
523 if ($_GET['paste_copy_repexpand'] == '') {
524 $expanded = $tree->readRootId();
525 } else {
526 $expanded = $_GET['paste_copy_repexpand'];
527 }
528
529 $this->tpl->setVariable('FORM_TARGET', '_self');
530 $this->tpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this, 'copySelection'));
531
532 $exp->setExpand($expanded);
533 // build html-output
534 $exp->setOutput(0);
535 $output = $exp->getOutput();
536
537 $this->tpl->setVariable('OBJECT_TREE', $output);
538
539 $this->tpl->setVariable('CMD_SUBMIT', 'saveSource');
540 $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('btn_next'));
541
542 $ilToolbar->addButton($this->lng->txt('cancel'), $ilCtrl->getLinkTarget($this, 'cancel'));
543 }
544
549 protected function saveTarget()
550 {
551 $objDefinition = $this->obj_definition;
553 $ilCtrl = $this->ctrl;
554
555
556 // begin-patch mc
557 if (is_array($_REQUEST['target']) and $_REQUEST['target']) {
558 $this->setTargets($_REQUEST['target']);
559 $ilCtrl->setParameter($this, 'target_ids', implode('_', $this->getTargets()));
560 }
561 // paste from clipboard
562 elseif ((int) $_REQUEST['target']) {
563 $this->setTarget($_REQUEST['target']);
564 $ilCtrl->setParameter($this, 'target_ids', implode('_', $this->getTargets()));
565 }
566 // end-patch multi copy
567 else {
568 $ilCtrl->setParameter($this, 'selectMode', self::TARGET_SELECTION);
569 ilUtil::sendFailure($this->lng->txt('select_one'));
571 return false;
572 }
573
574 // validate allowed subtypes
575 foreach ($this->getSources() as $source_ref_id) {
576 foreach ((array) $this->getTargets() as $target_ref_id) {
577 $target_type = ilObject::_lookupType($target_ref_id, true);
578 $target_class_name = ilObjectFactory::getClassByType($target_type);
579 $target_object = new $target_class_name($target_ref_id);
580 $possible_subtypes = $target_object->getPossibleSubObjects();
581
582 $source_type = ilObject::_lookupType($source_ref_id, true);
583
584 if (!array_key_exists($source_type, (array) $possible_subtypes)) {
586 sprintf(
587 $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
588 $this->lng->txt('obj_' . $target_type),
589 $this->lng->txt('obj_' . $source_type)
590 )
591 );
593 return false;
594 }
595 }
596 }
597
598 if (count($this->getSources()) == 1 && $objDefinition->isContainer($this->getType())) {
599 // check, if object should be copied into itself
600 // begin-patch mc
601 $is_child = array();
602 foreach ($this->getTargets() as $target_ref_id) {
603 if ($tree->isGrandChild($this->getFirstSource(), $target_ref_id)) {
605 }
606 if ($this->getFirstSource() == $target_ref_id) {
608 }
609 }
610 // end-patch multi copy
611 if (count($is_child) > 0) {
612 ilUtil::sendFailure($this->lng->txt("msg_not_in_itself") . " " . implode(',', $is_child));
614 return false;
615 }
616
617 $this->showItemSelection();
618 } else {
619 if (count($this->getSources()) == 1) {
620 $this->copySingleObject();
621 } else {
622 $this->copyMultipleNonContainer($this->getSources());
623 }
624 }
625 }
626
632 public function setMode($a_mode)
633 {
634 $this->mode = $a_mode;
635 }
636
641 public function getMode()
642 {
643 return $this->mode;
644 }
645
646 public function setSubMode($a_mode)
647 {
648 $this->sub_mode = $a_mode;
649 }
650
651 public function getSubMode()
652 {
653 return $this->sub_mode;
654 }
655
660 public function getParentObject()
661 {
662 return $this->parent_obj;
663 }
664
670 public function getType()
671 {
672 return $this->type;
673 }
674
681 public function setType($type)
682 {
683 $this->type = $type;
684 }
685
691 public function setSource(array $a_source_ids)
692 {
693 $this->sources = $a_source_ids;
694 }
695
700 public function getSources()
701 {
702 return (array) $this->sources;
703 }
704
705 public function getFirstSource()
706 {
707 if (count($this->sources)) {
708 return $this->sources[0];
709 }
710 return 0;
711 }
712
713 // begin-patch mc
714
719 public function setTarget($a_ref_id)
720 {
721 $this->setTargets(array($a_ref_id));
722 }
723
724
730 public function setTargets(array $a_target)
731 {
732 $this->targets = $a_target;
733 }
734
739 public function getTargets()
740 {
741 return (array) $this->targets;
742 }
743
748 public function getFirstTarget()
749 {
750 if (array_key_exists(0, $this->getTargets())) {
751 $targets = $this->getTargets();
752 return $targets[0];
753 }
754 return 0;
755 }
756 // end-patch multi copy
757
761 protected function cancel()
762 {
763 $ilCtrl = $this->ctrl;
764 $ilCtrl->setReturnByClass(get_class($this->parent_obj), 'cancel');
765 $ilCtrl->returnToParent($this);
766 }
767
771 public function keepObjectsInClipboard()
772 {
773 ilUtil::sendSuccess($this->lng->txt("obj_inserted_clipboard"), true);
774 $ilCtrl = $this->ctrl;
775 $_SESSION['clipboard']['cmd'] = "copy";
776 $_SESSION['clipboard']['ref_ids'] = $this->getSources();
777 $ilCtrl->returnToParent($this);
778 }
779
780
785 protected function searchSource()
786 {
788 $ilObjDataCache = $this->obj_data_cache;
790 $ilCtrl = $this->ctrl;
792
793 if (isset($_POST['tit'])) {
794 ilUtil::sendInfo($this->lng->txt('wizard_search_list'));
795 $_SESSION['source_query'] = $_POST['tit'];
796 } else {
797 $_POST['tit'] = $_SESSION['source_query'];
798 }
799
800 $this->initFormSearch();
801 $this->form->setValuesByPost();
802
803 if (!$this->form->checkInput()) {
804 ilUtil::sendFailure($lng->txt('msg_no_search_string'), true);
805 $ilCtrl->returnToParent($this);
806 return false;
807 }
808
809 include_once './Services/Search/classes/class.ilQueryParser.php';
810 $query_parser = new ilQueryParser($this->form->getInput('tit'));
811 $query_parser->setMinWordLength(1, true);
812 $query_parser->setCombination(QP_COMBINATION_AND);
813 $query_parser->parse();
814 if (!$query_parser->validate()) {
815 ilUtil::sendFailure($query_parser->getMessage(), true);
816 $ilCtrl->returnToParent($this);
817 }
818
819 // only like search since fulltext does not support search with less than 3 characters
820 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
821 $object_search = new ilLikeObjectSearch($query_parser);
822 $object_search->setFilter(array($_REQUEST['new_type']));
823 $res = $object_search->performSearch();
824 $res->setRequiredPermission('copy');
825 $res->filter(ROOT_FOLDER_ID, true);
826
827 if (!count($results = $res->getResultsByObjId())) {
828 ilUtil::sendFailure($this->lng->txt('search_no_match'), true);
829 $ilCtrl->returnToParent($this);
830 }
831
832
833 include_once './Services/Object/classes/class.ilObjectCopySearchResultTableGUI.php';
834 $table = new ilObjectCopySearchResultTableGUI($this, 'searchSource', $this->getType());
835 $table->setFormAction($ilCtrl->getFormAction($this));
836 $table->setSelectedReference($this->getFirstSource());
837 $table->parseSearchResults($results);
838 $tpl->setContent($table->getHTML());
839 }
840
845 protected function saveSource()
846 {
847 $objDefinition = $this->obj_definition;
848 $ilCtrl = $this->ctrl;
849
850 if (isset($_POST['source'])) {
851 $this->setSource(array((int) $_REQUEST['source']));
852 $this->setType(ilObject::_lookupType((int) $_REQUEST['source'], true));
853 $ilCtrl->setParameter($this, 'source_id', (int) $_REQUEST['source']);
854 } else {
855 ilUtil::sendFailure($this->lng->txt('select_one'));
856 $this->searchSource();
857 return false;
858 }
859
860 // validate allowed subtypes
861 foreach ($this->getSources() as $source_ref_id) {
862 foreach ((array) $this->getTargets() as $target_ref_id) {
863 $target_type = ilObject::_lookupType($target_ref_id, true);
864 $target_class_name = ilObjectFactory::getClassByType($target_type);
865 $target_object = new $target_class_name($target_ref_id);
866 $possible_subtypes = $target_object->getPossibleSubObjects();
867
868 $source_type = ilObject::_lookupType($source_ref_id, true);
869
870 if (!array_key_exists($source_type, $possible_subtypes)) {
871 #ilLoggerFactory::getLogger('obj')->debug('Source type: '. $source_type);
872 #ilLoggerFactory::getLogger('obj')->debug('Target type: '. $target_type);
873 #ilLoggerFactory::getLogger('obj')->debug('Submode: '. $this->getSubMode());
874
875 // adopt content mode
876 if (
877 $this->getSubMode() != self::SUBMODE_CONTENT_ONLY and
878 ($source_type != 'crs' or $target_type != 'crs')
879 ) {
881 sprintf(
882 $this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
883 $this->lng->txt('obj_' . $target_type),
884 $this->lng->txt('obj_' . $source_type)
885 )
886 );
887 $this->searchSource();
888 return false;
889 }
890 }
891 }
892 }
893
894
895 if ($objDefinition->isContainer($this->getType())) {
896 $this->showItemSelection();
897 } else {
898 $this->copySingleObject();
899 }
900 }
901
905 protected function saveSourceMembership()
906 {
907 $objDefinition = $this->obj_definition;
908 $ilCtrl = $this->ctrl;
909
910 if (!isset($_REQUEST['source'])) {
911 ilUtil::sendFailure($this->lng->txt('select_one'));
912 $ilCtrl->redirect($this, 'showSourceSelectionMembership');
913 return false;
914 }
915
916 $this->setSource(array((int) $_REQUEST['source']));
917 $this->setType(ilObject::_lookupType((int) $this->getFirstSource(), true));
918 $ilCtrl->setParameter($this, 'source_id', (int) $_REQUEST['source']);
919
920 if ($objDefinition->isContainer($this->getType())) {
921 $this->showItemSelection();
922 } else {
923 $this->copySingleObject();
924 }
925 }
926
931 protected function showItemSelection()
932 {
934
935 if (!count($this->getSources())) {
936 ilUtil::sendFailure($this->lng->txt('select_one'));
937 $this->searchSource();
938 return false;
939 }
940
941 ilLoggerFactory::getLogger('obj')->debug('Source(s): ' . print_r($this->getSources(), true));
942 ilLoggerFactory::getLogger('obj')->debug('Target(s): ' . print_r($this->getTargets(), true));
943
944 ilUtil::sendInfo($this->lng->txt($this->getType() . '_copy_threads_info'));
945 include_once './Services/Object/classes/class.ilObjectCopySelectionTableGUI.php';
946
947 $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
948 $tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
949
950 switch ($this->getMode()) {
952 $back_cmd = 'adoptContent';
953 break;
954
956 $back_cmd = 'showTargetSelectionTree';
957 break;
958
960 $back_cmd = 'searchSource';
961 break;
962 }
963
964 $table = new ilObjectCopySelectionTableGUI($this, 'showItemSelection', $this->getType(), $back_cmd);
965 $table->parseSource($this->getFirstSource());
966
967 $tpl->setContent($table->getHTML());
968 }
969
974 protected function copySingleObject()
975 {
976 include_once('./Services/Link/classes/class.ilLink.php');
977 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
978
979 $ilAccess = $this->access;
983 $ilCtrl = $this->ctrl;
985
986 // Source defined
987 if (!count($this->getSources())) {
988 ilUtil::sendFailure($this->lng->txt('select_one'), true);
989 $ilCtrl->returnToParent($this);
990 }
991
992 $this->copyMultipleNonContainer($this->getSources());
993 return;
994 }
995
1001 public function copyMultipleNonContainer($a_sources)
1002 {
1003 $ilAccess = $this->access;
1004 $objDefinition = $this->obj_definition;
1007 $ilCtrl = $this->ctrl;
1009
1010 // check permissions
1011 foreach ($a_sources as $source_ref_id) {
1012 $source_type = ilObject::_lookupType($source_ref_id, true);
1013
1014 // Create permission
1015 // begin-patch mc
1016 foreach ($this->getTargets() as $target_ref_id) {
1017 if (!$rbacsystem->checkAccess('create', $target_ref_id, $source_type)) {
1018 $this->log->notice('Permission denied for target_id: ' . $target_ref_id . ' source_type: ' . $source_type . ' CREATE');
1019 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1020 $ilCtrl->returnToParent($this);
1021 }
1022 }
1023
1024 // Copy permission
1025 if (!$ilAccess->checkAccess('copy', '', $source_ref_id)) {
1026 $this->log->notice('Permission denied for source_ref_id: ' . $source_ref_id . ' COPY');
1027 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1028 $ilCtrl->returnToParent($this);
1029 }
1030
1031 // check that these objects are really not containers
1032 if ($objDefinition->isContainer($source_type) and $this->getSubMode() != self::SUBMODE_CONTENT_ONLY) {
1033 ilUtil::sendFailure($this->lng->txt('cntr_container_only_on_their_own'), true);
1034 $ilCtrl->returnToParent($this);
1035 }
1036 }
1037
1038 reset($a_sources);
1039
1040 ilLoggerFactory::getLogger('obj')->debug('Copy multiple non containers. Sources: ' . print_r($a_sources, true));
1041
1042 // clone
1043 foreach ($a_sources as $source_ref_id) {
1044 ilLoggerFactory::getLogger('obj')->debug('Copying source ref_id : ' . $source_ref_id);
1045
1046 // begin-patch mc
1047 foreach ($this->getTargets() as $target_ref_id) {
1048 // Save wizard options
1050 $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1051 $wizard_options->saveOwner($ilUser->getId());
1052 $wizard_options->saveRoot((int) $source_ref_id);
1053 $wizard_options->read();
1054
1055 $orig = ilObjectFactory::getInstanceByRefId((int) $source_ref_id);
1056 $new_obj = $orig->cloneObject($target_ref_id, $copy_id);
1057
1058 // Delete wizard options
1059 $wizard_options->deleteAll();
1060 $this->parent_obj->callCreationCallback(
1061 $new_obj,
1062 $this->obj_definition,
1063 $_GET['crtcb'] ?? 0
1064 );
1065
1066 // rbac log
1067 if (ilRbacLog::isActive()) {
1068 $rbac_log_roles = $rbacreview->getParentRoleIds($new_obj->getRefId(), false);
1069 $rbac_log = ilRbacLog::gatherFaPa($new_obj->getRefId(), array_keys($rbac_log_roles), true);
1070 ilRbacLog::add(ilRbacLog::COPY_OBJECT, $new_obj->getRefId(), $rbac_log, (int) $source_ref_id);
1071 }
1072 }
1073 }
1074
1075 unset($_SESSION["clipboard"]["ref_ids"]);
1076 unset($_SESSION["clipboard"]["cmd"]);
1077
1078 if (count($a_sources) == 1) {
1079 ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1080 ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true);
1081 $ref_id = $new_obj->getRefId();
1082 } else {
1083 ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1084 ilUtil::sendSuccess($this->lng->txt("objects_duplicated"), true);
1085 $ref_id = $this->getFirstTarget();
1086 }
1087
1088 ilUtil::sendSuccess($this->lng->txt("objects_duplicated"), true);
1090
1091 // see bug discussion 24472
1092 /*
1093 $gui_fac = new ilObjectGUIFactory();
1094 $obj_gui = $gui_fac->getInstanceByRefId($ref_id);
1095 $obj_gui->redirectAfterCreation();
1096 */
1097 }
1098
1102 protected function copyContainerToTargets()
1103 {
1104 $ilCtrl = $this->ctrl;
1105
1106 ilLoggerFactory::getLogger('obj')->debug('Copy container to targets: ' . print_r($_REQUEST, true));
1107 ilLoggerFactory::getLogger('obj')->debug('Source(s): ' . print_r($this->getSources(), true));
1108 ilLoggerFactory::getLogger('obj')->debug('Target(s): ' . print_r($this->getTargets(), true));
1109
1110
1111 $last_target = 0;
1112 $result = 1;
1113 foreach ($this->getTargets() as $target_ref_id) {
1114 $result = $this->copyContainer($target_ref_id);
1115 $last_target = $target_ref_id;
1116 }
1117
1118 unset($_SESSION["clipboard"]["ref_ids"]);
1119 unset($_SESSION["clipboard"]["cmd"]);
1120
1121 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1122 if (ilCopyWizardOptions::_isFinished($result['copy_id'])) {
1123 ilLoggerFactory::getLogger('obj')->info('Object copy completed.');
1124 ilUtil::sendSuccess($this->lng->txt("object_duplicated"), true);
1125 if ($this->getSubMode() == self::SUBMODE_CONTENT_ONLY) {
1126 // return to parent container
1127 return $this->ctrl->returnToParent($this);
1128 }
1129 // return to last target
1130 $link = ilLink::_getLink($result['ref_id']);
1131 $ilCtrl->redirectToUrl($link);
1132 } else {
1133 // show progress
1134 ilLoggerFactory::getLogger('obj')->debug('Object copy in progress.');
1135 return $this->showCopyProgress();
1136 }
1137 }
1138
1142 protected function showCopyProgress()
1143 {
1144 $ilCtrl = $this->ctrl;
1145 $tpl = $this->tpl;
1146
1147 include_once './Services/Object/classes/class.ilObjectCopyProgressTableGUI.php';
1148 $progress = new ilObjectCopyProgressTableGUI(
1149 $this,
1150 'showCopyProgress',
1151 (int) $_GET['ref_id']
1152 );
1153 $progress->setObjectInfo($this->targets_copy_id);
1154 $progress->parse();
1155 $progress->init();
1156 $progress->setRedirectionUrl($ilCtrl->getParentReturn($this->parent_obj));
1157
1158 $tpl->setContent($progress->getHTML());
1159 }
1160
1164 protected function updateProgress()
1165 {
1166 $json = new stdClass();
1167 $json->percentage = null;
1168 $json->performed_steps = null;
1169
1170 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1171 $options = ilCopyWizardOptions::_getInstance((int) $_REQUEST['copy_id']);
1172 $json->required_steps = $options->getRequiredSteps();
1173 $json->id = (int) $_REQUEST['copy_id'];
1174
1175 ilLoggerFactory::getLogger('obj')->debug('Update copy progress: ' . json_encode($json));
1176
1177 echo json_encode($json);
1178 exit;
1179 }
1180
1181
1186 protected function copyContainer($a_target)
1187 {
1188 $ilLog = $this->log;
1189 $ilCtrl = $this->ctrl;
1190
1191 include_once('./Services/Link/classes/class.ilLink.php');
1192 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1193
1194 $ilAccess = $this->access;
1199 $ilCtrl = $this->ctrl;
1200
1201 // Workaround for course in course copy
1202
1205
1206 if ($this->getSubMode() != self::SUBMODE_CONTENT_ONLY) {
1207 if (!$rbacsystem->checkAccess('create', $a_target, $this->getType())) {
1208 $this->log->notice('Permission denied for target: ' . $a_target . ' type: ' . $this->getType() . ' CREATE');
1209 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
1210 $ilCtrl->returnToParent($this);
1211 }
1212 }
1213 if (!$this->getFirstSource()) {
1214 ilUtil::sendFailure($this->lng->txt('select_one'), true);
1215 $ilCtrl->returnToParent($this);
1216 return false;
1217 }
1218
1219 $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
1220
1221
1222 ilLoggerFactory::getLogger('obj')->debug('Copy container (sources): ' . print_r($this->getSources(), true));
1223
1225 $result = $orig->cloneAllObject(
1226 $_COOKIE[session_name()],
1227 $_COOKIE['ilClientId'],
1228 $this->getType(),
1229 $a_target,
1230 $this->getFirstSource(),
1231 $options,
1232 false,
1233 $this->getSubMode()
1234 );
1235 $this->targets_copy_id[$a_target] = $result['copy_id'];
1236 $new_ref_id = (int) $result['ref_id'];
1237 if ($new_ref_id > 0) {
1238 $new_obj = ilObjectFactory::getInstanceByRefId((int) $result['ref_id'], false);
1239 if ($new_obj instanceof ilObject) {
1240 $this->parent_obj->callCreationCallback(
1241 $new_obj,
1242 $this->obj_definition,
1243 $_GET['crtcb'] ?? 0
1244 );
1245 }
1246 }
1247 return $result;
1248 }
1249
1250
1251
1259 public function showSourceSearch($a_tplvar)
1260 {
1261 $tpl = $this->tpl;
1262
1263 // Disabled for performance
1264 #if(!$this->sourceExists())
1265 #{
1266 # return false;
1267 #}
1268
1269 $this->unsetSession();
1270 $this->initFormSearch();
1271
1272 if ($a_tplvar) {
1273 $tpl->setVariable($a_tplvar, $this->form->getHTML());
1274 } else {
1275 return $this->form;
1276 }
1277 }
1278
1279
1284 protected function sourceExists()
1285 {
1287
1288 return (bool) ilUtil::_getObjectsByOperations($this->getType(), 'copy', $ilUser->getId(), 1);
1289 }
1290
1295 protected function initFormSearch()
1296 {
1297 $lng = $this->lng;
1298 $ilCtrl = $this->ctrl;
1299
1300 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
1301 $this->form = new ilPropertyFormGUI();
1302 $this->form->setTableWidth('600px');
1303
1304 $ilCtrl->setParameter($this, 'new_type', $this->getType());
1305
1306 #$ilCtrl->setParameter($this, 'cp_mode', self::SOURCE_SELECTION);
1307 $this->form->setFormAction($ilCtrl->getFormAction($this));
1308 $this->form->setTitle($lng->txt($this->getType() . '_copy'));
1309
1310 $this->form->addCommandButton('searchSource', $lng->txt('btn_next'));
1311 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
1312
1313 $tit = new ilTextInputGUI($lng->txt('title'), 'tit');
1314 $tit->setSize(40);
1315 $tit->setMaxLength(70);
1316 $tit->setRequired(true);
1317 $tit->setInfo($lng->txt('wizard_title_info'));
1318 $this->form->addItem($tit);
1319 }
1320
1325 protected function unsetSession()
1326 {
1327 unset($_SESSION['source_query']);
1328 $this->setSource(array());
1329 }
1330}
$result
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
const QP_COMBINATION_AND
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _allocateCopyId()
Allocate a copy for further entries.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _isFinished($a_copy_id)
check if copy is finished
static getLogger($a_component_id)
Get component logger.
GUI class for the workflow of copying objects.
sourceExists()
Check if there is any source object.
setTabs($a_tab_group, $a_active_tab)
Set tabs.
unsetSession()
Unset session variables.
copyMultipleNonContainer($a_sources)
Copy multiple non container.
cancel()
Cancel workflow.
setMode($a_mode)
set copy mode
initTabs()
Init tabs General.
searchSource()
Search source.
getFirstTarget()
Get first target.
initTargetSelection()
Init copy from repository/search list commands.
initFormSearch()
Init search form.
showCopyProgress()
Show progress for copying.
updateProgress()
Update progress.
setType($type)
Sets $type.
getParentObject()
Get parent gui object.
copySingleObject()
Start cloning a single (not container) object.
init()
Init return, mode.
showSourceSelectionTree()
Show target selection.
saveSourceMembership()
Save selected source from membership screen.
getTargets()
Get copy target.
saveTarget()
Save target selection.
setSource(array $a_source_ids)
Set source id.
keepObjectsInClipboard()
Keep objects in clipboard.
saveSource()
select source object
getType()
Returns $type.
executeCommand()
Control class handling.
setTargets(array $a_target)
Set target id.
initSourceSelection()
Init source selection.
setTarget($a_ref_id)
Set single object target.
showSourceSearch($a_tplvar)
Show init screen Normally shown below the create and import form when creating a new object.
copyContainerToTargets()
Copy to multiple targets.
adoptContent()
Adopt content (crs in crs, grp in grp, crs in grp or grp in crs)
showSourceSelectionMembership()
show target selection membership
__construct(ImplementsCreationCallback $a_parent_gui)
copyContainer($a_target)
Copy a container.
showTargetSelectionTree()
Show target selection.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static getClassByType($a_obj_type)
Get class by type.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
This class represents a property form user interface.
const COPY_OBJECT
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
static gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action=false)
static isActive()
Explorer for selecting repository items.
static getInstance()
Factory.
This class represents a text property in a property form.
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
$target_type
Definition: goto.php:50
$ilUser
Definition: imgupload.php:18
exit
Definition: login.php:29
$ilErr
Definition: raiseError.php:18
$results
foreach($_POST as $key=> $value) $res
$container
Definition: wac.php:13
$_COOKIE[session_name()]
Definition: xapitoken.php:37