ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.EditSubObjectsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ilLMObject;
30
32{
33 protected string $lang;
34 protected array $page_layouts;
36 protected int $lm_id;
37 protected \ilLMTree $lm_tree;
38 protected int $sub_obj_id;
39
40 public function __construct(
41 protected InternalDomainService $domain,
42 protected InternalGUIService $gui,
43 protected string $sub_type,
44 protected \ilObjLearningModule $lm,
45 protected string $table_title
46 ) {
47 $this->sub_obj_id = $this->gui->editing()->request()->getObjId();
48 $this->gui->ctrl()->saveParameterByClass(self::class, "sub_type");
49 $this->lm_id = $lm->getId();
50 $this->lm_tree = $this->domain->lmTree($this->lm_id);
51 $this->request = $this->gui->editing()->request();
52 $this->page_layouts = \ilPageLayout::activeLayouts(
54 );
55 $this->lang = $this->request->getTranslation();
56 $this->gui->initFetch();
57 }
58
59 public function executeCommand(): void
60 {
61 $ctrl = $this->gui->ctrl();
62 $next_class = $ctrl->getNextClass($this);
63 $cmd = $ctrl->getCmd("list");
64
65 switch ($next_class) {
66 default:
67 if (in_array($cmd, [
68 "list", "tableCommand", "editPages",
69 "insertChapterAfter", "insertChapterBefore", "insertFirstChapter",
70 "insertPageAfter", "insertPageBefore", "insertFirstPage",
71 "editTitle", "saveTitle", "saveOrder",
72 "confirmedDelete", "delete", "cancelDelete",
73 "insertPageClip", "insertPageClipBefore", "insertPageClipAfter",
74 "insertChapterClip", "insertChapterClipBefore", "insertChapterClipAfter",
75 "activatePages",
76 "insertLayoutBefore", "insertLayoutAfter", "insertPageFromLayout",
77 "switchToLanguage", "editMasterLanguage",
78 "savePageAfter", "savePageBefore",
79 "saveChapterAfter", "saveChapterBefore",
80 ])) {
81 $this->$cmd();
82 }
83 }
84 }
85
86 protected function editPages(): void
87 {
88 $this->gui->ctrl()->setParameterByClass(self::class, "sub_type", "pg");
89 $this->gui->ctrl()->redirectByClass(static::class, "list");
90 }
91
92 protected function getTable(): TableAdapterGUI
93 {
94 return $this->gui->editing()->subObjectTableBuilder(
95 $this->table_title,
96 $this->lm_id,
97 $this->sub_type,
98 $this,
99 "list"
100 )->getTable();
101 }
102
103 public function switchToLanguage(): void
104 {
105 $ctrl = $this->gui->ctrl();
106 $ctrl->setParameter($this, "transl", $this->request->getToTranslation());
107 $ctrl->redirect($this, "list");
108 }
109
110 public function editMasterLanguage(): void
111 {
112 $ctrl = $this->gui->ctrl();
113 $ctrl->setParameter($this, "transl", "-");
114 $ctrl->redirect($this, "list");
115 }
116
117
118 protected function list(): void
119 {
120 $lng = $this->domain->lng();
121 $ctrl = $this->gui->ctrl();
122 $main_tpl = $this->gui->mainTemplate();
123 $user = $this->domain->user();
124
125 if ($this->getTable()->handleCommand()) {
126 return;
127 }
128
129 $retrieval = $this->domain->subObjectRetrieval(
130 $this->lm_id,
131 $this->sub_type,
132 $this->sub_obj_id,
133 $this->lang
134 );
135
136 $ml_head = \ilObjLearningModuleGUI::getMultiLangHeader($this->lm_id, $this);
137
138 if ($this->sub_type === "st") {
139 $modal = $this->gui->modal(
140 $lng->txt("lm_insert_chapter")
141 )->form($this->getAddPageForm("saveChapterAfter"))->getAsyncTriggerButtonComponents(
142 $lng->txt("lm_insert_chapter"),
143 $this->gui->ctrl()->getLinkTargetByClass(self::class, "insertChapterAfter"),
144 false
145 );
146 $this->gui->toolbar()->addComponent($modal["button"]);
147 $this->gui->toolbar()->addComponent($modal["modal"]);
148 /*
149 $this->gui->button(
150 $lng->txt("lm_insert_chapter"),
151 $ctrl->getLinkTargetByClass(self::class, "insertFirstChapter")
152 )->toToolbar();*/
153 if ($user->clipboardHasObjectsOfType("st")) {
154 $this->gui->button(
155 $lng->txt("lm_insert_chapter_clip"),
156 $ctrl->getLinkTargetByClass(self::class, "insertChapterClip")
157 )->toToolbar();
158 }
159 } else {
160 $modal = $this->gui->modal(
161 $lng->txt("lm_insert_page")
162 )->form($this->getAddPageForm("savePageAfter"))->getAsyncTriggerButtonComponents(
163 $lng->txt("lm_insert_page"),
164 $this->gui->ctrl()->getLinkTargetByClass(self::class, "insertPageAfter"),
165 false
166 );
167 $this->gui->toolbar()->addComponent($modal["button"]);
168 $this->gui->toolbar()->addComponent($modal["modal"]);
169 /*$this->gui->button(
170 $lng->txt("lm_insert_page"),
171 $ctrl->getLinkTargetByClass(self::class, "insertFirstPage")
172 )->toToolbar();*/
173 if ($user->clipboardHasObjectsOfType("pg")) {
174 $this->gui->button(
175 $lng->txt("lm_insert_page_clip"),
176 $ctrl->getLinkTargetByClass(self::class, "insertPageClip")
177 )->toToolbar();
178 }
179 }
180 $table = $this->getTable();
181
182 $main_tpl->setContent($ml_head . $table->render());
183 $main_tpl->addOnloadCode("window.setTimeout(() => { il.repository.core.trigger('il-lm-editor-tree'); }, 500);");
184 }
185
186 protected function getCurrentParentId(): int
187 {
188 $parent = $this->sub_obj_id;
189 if ($parent === 0) {
190 $parent = $this->lm_tree->readRootId();
191 }
192 return $parent;
193 }
194
195 public function insertChapterClipBefore(): void
196 {
197 $parent = $this->getCurrentParentId();
198 $target_id = $this->request->getTargetId();
199 $before_target = \ilTree::POS_FIRST_NODE;
200 foreach ($this->lm_tree->getChilds($parent) as $node) {
201 if ((int) $node["obj_id"] !== $target_id) {
202 $before_target = (int) $node["obj_id"];
203 } else {
204 break;
205 }
206 }
207 $this->insertChapterClip(
208 $before_target
209 );
210 }
211
212 public function insertChapterClipAfter(): void
213 {
214 $this->insertChapterClip(
215 $this->request->getTargetId()
216 );
217 }
218
219 public function insertChapterClip(
220 $target = \ilTree::POS_LAST_NODE
221 ): void {
222 $user = $this->domain->user();
223 $ctrl = $this->gui->ctrl();
224 $parent_id = $this->request->getObjId();
225
226 // copy and paste
227 $chapters = $user->getClipboardObjects("st", true);
228 $copied_nodes = array();
229
230 foreach ($chapters as $chap) {
231 $cid = ilLMObject::pasteTree(
232 $this->lm,
233 $chap["id"],
234 $parent_id,
235 (int) $target,
236 (string) ($chap["insert_time"] ?? ""),
237 $copied_nodes,
238 (\ilEditClipboard::getAction() == "copy")
239 );
240 $target = $cid;
241 }
242 ilLMObject::updateInternalLinks($copied_nodes);
243
244 if (\ilEditClipboard::getAction() == "cut") {
245 $user->clipboardDeleteObjectsOfType("pg");
246 $user->clipboardDeleteObjectsOfType("st");
248 }
249
250 $this->lm->checkTree();
251 $ctrl->redirect($this, "list");
252 }
253
254 public function insertPageClipBefore(): void
255 {
256 $parent = $this->sub_obj_id;
257 $target_id = $this->request->getTargetId();
258 $before_target = \ilTree::POS_FIRST_NODE;
259 foreach ($this->lm_tree->getChildsByType($parent, "pg") as $node) {
260 if ((int) $node["obj_id"] !== $target_id) {
261 $before_target = (int) $node["obj_id"];
262 } else {
263 break;
264 }
265 }
266 $this->insertPageClip(
267 $before_target
268 );
269 }
270
271 public function insertPageClipAfter(): void
272 {
273 $this->insertPageClip(
274 $this->request->getTargetId()
275 );
276 }
277
278 public function insertPageClip(
279 int $target = 0
280 ): void {
281 $user = $this->domain->user();
282 $ctrl = $this->gui->ctrl();
283
284 $parent_id = $this->request->getObjId();
285
286 // cut and paste
287 $pages = $user->getClipboardObjects("pg");
288 $copied_nodes = array();
289 foreach ($pages as $pg) {
290 $cid = ilLMObject::pasteTree(
291 $this->lm,
292 $pg["id"],
293 $parent_id,
294 $target,
295 (string) ($pg["insert_time"] ?? ""),
296 $copied_nodes,
297 (\ilEditClipboard::getAction() == "copy")
298 );
299 $target = $cid;
300 }
302
303 if (\ilEditClipboard::getAction() == "cut") {
304 $user->clipboardDeleteObjectsOfType("pg");
305 $user->clipboardDeleteObjectsOfType("st");
307 }
308
309 $ctrl->redirect($this, "list");
310 }
311
312 public function insertFirstPage(): void
313 {
314 $this->insertPage(
315 $this->sub_obj_id
316 );
317 }
318 public function insertPageAfter(int $id = 0): void
319 {
320 $lng = $this->domain->lng();
321 $this->gui->ctrl()->setParameterByClass(
322 self::class,
323 "target_id",
324 $id
325 );
326 $this->gui->clearAsnyOnloadCode();
327 $modal = $this->gui->modal($lng->txt("lm_insert_page"))->form($this->getAddPageForm("savePageAfter"));
328 $modal->send();
329 }
330
331 public function savePageAfter(): void
332 {
333 $mt = $this->gui->ui()->mainTemplate();
334 $lng = $this->domain->lng();
335 $target_id = $this->request->getTargetId();
336 $this->insertPage(
337 $this->sub_obj_id,
338 $target_id,
339 $this->getTitlesFromForm(),
340 $this->getLayoutIdFromForm()
341 );
342 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
343 $this->gui->ctrl()->redirect($this, "list");
344 }
345
346 public function insertPageBefore(int $id): void
347 {
348 $lng = $this->domain->lng();
349 $this->gui->ctrl()->setParameterByClass(
350 self::class,
351 "target_id",
352 $id
353 );
354 $this->gui->clearAsnyOnloadCode();
355 $modal = $this->gui->modal($lng->txt("lm_insert_page"))->form($this->getAddPageForm("savePageBefore"));
356 $modal->send();
357 }
358
359 public function savePageBefore(): void
360 {
361 $mt = $this->gui->ui()->mainTemplate();
362 $lng = $this->domain->lng();
363 $parent = $this->sub_obj_id;
364 $target_id = $this->request->getTargetId();
365 $before_target = \ilTree::POS_FIRST_NODE;
366 foreach ($this->lm_tree->getChildsByType($parent, "pg") as $node) {
367 if ((int) $node["obj_id"] !== $target_id) {
368 $before_target = (int) $node["obj_id"];
369 } else {
370 break;
371 }
372 }
373 $this->insertPage(
374 $parent,
375 $before_target,
376 $this->getTitlesFromForm(),
377 $this->getLayoutIdFromForm()
378 );
379 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
380 $this->gui->ctrl()->redirect($this, "list");
381 }
382
383 protected function insertPage(
384 int $parent_id = 0,
385 int $target = 0,
386 array $titles = [],
387 int $layout_id = 0
388 ): void {
389 $lng = $this->domain->lng();
390 $ctrl = $this->gui->ctrl();
391
392 $page = new \ilLMPageObject($this->lm);
393 $page->setType("pg");
394 $page->setTitle($lng->txt("cont_new_page"));
395 $page->setLMId($this->lm_id);
396 $page->create(false, false, $layout_id);
397 \ilLMObject::putInTree($page, $parent_id, $target);
398
399 if (count($titles) > 0) {
400 \ilLMObject::saveTitle($page->getId(), $titles["-"]);
401
402 $ot = $this->domain->translation($this->lm->getId());
403 if ($ot->getContentTranslationActivated()) {
404 foreach ($ot->getLanguages() as $lang) {
405 $code = $lang->getLanguageCode();
406 if ($code === $ot->getBaseLanguage()) {
407 continue;
408 }
409 \ilLMObject::saveTitle($page->getId(), $titles[$code], $code);
410 }
411 }
412 }
413
414 $ctrl->redirect($this, "list");
415 }
416
417 public function insertFirstChapter(): void
418 {
419 $this->insertChapter(
420 $this->sub_obj_id
421 );
422 }
423
424 public function insertChapterAfter(int $id = 0): void
425 {
426 $lng = $this->domain->lng();
427 $this->gui->ctrl()->setParameterByClass(
428 self::class,
429 "target_id",
430 $id
431 );
432 $this->gui->clearAsnyOnloadCode();
433 $modal = $this->gui->modal($lng->txt("lm_insert_chapter"))->form($this->getEditTitleForm(0, "saveChapterAfter"));
434 $modal->send();
435 }
436
437 public function saveChapterAfter(): void
438 {
439 $target_id = $this->request->getTargetId();
440 $this->insertChapter(
441 $this->sub_obj_id,
442 $target_id,
443 $this->getTitlesFromForm()
444 );
445 }
446
447 public function insertChapterBefore(int $id): void
448 {
449 $lng = $this->domain->lng();
450 $this->gui->ctrl()->setParameterByClass(
451 self::class,
452 "target_id",
453 $id
454 );
455 $this->gui->clearAsnyOnloadCode();
456 $modal = $this->gui->modal($lng->txt("lm_insert_chapter"))->form($this->getEditTitleForm(0, "saveChapterBefore"));
457 $modal->send();
458 }
459
460 public function saveChapterBefore(): void
461 {
462 $parent = $this->getCurrentParentId();
463 $target_id = $this->request->getTargetId();
464 $before_target = \ilTree::POS_FIRST_NODE;
465 foreach ($this->lm_tree->getChilds($parent) as $node) {
466 if ((int) $node["obj_id"] !== $target_id) {
467 $before_target = (int) $node["obj_id"];
468 } else {
469 break;
470 }
471 }
472 $this->insertChapter(
473 $parent,
474 $before_target,
475 $this->getTitlesFromForm()
476 );
477 }
478
479 protected function insertChapter(
480 int $parent_id = 0,
481 int $target = \ilTree::POS_LAST_NODE,
482 array $titles = []
483 ): void {
484 $lng = $this->domain->lng();
485 $ctrl = $this->gui->ctrl();
486 $chap = new \ilStructureObject($this->lm);
487 $chap->setType("st");
488 $chap->setTitle($lng->txt("cont_new_chap"));
489 $chap->setLMId($this->lm_id);
490 $chap->create();
491 \ilLMObject::putInTree($chap, $parent_id, $target);
492
493 if (count($titles) > 0) {
494 \ilLMObject::saveTitle($chap->getId(), $titles["-"]);
495
496 $ot = $this->domain->translation($this->lm->getId());
497 if ($ot->getContentTranslationActivated()) {
498 foreach ($ot->getLanguages() as $lang) {
499 $code = $lang->getLanguageCode();
500 if ($code === $ot->getBaseLanguage()) {
501 continue;
502 }
503 \ilLMObject::saveTitle($chap->getId(), $titles[$code], $code);
504 }
505 }
506 }
507
508 $ctrl->redirect($this, "list");
509 }
510
511 protected function getAddPageForm($cmd): FormAdapterGUI
512 {
513 $this->domain->lng()->loadLanguageModule("copg");
514 $form = $this->getEditTitleForm(0, $cmd);
516 if (count($arr_templates) > 0) {
517 $form = $form->optional("use_template", $this->domain->lng()->txt("copg_use_template"));
518 $form = \ilPageLayoutGUI::addTemplateSelection((string) \ilPageLayout::MODULE_LM, $form);
519 $form = $form->end();
520 }
521 return $form;
522 }
523
524 protected function getEditTitleForm(int $id, $cmd = "saveTitle"): FormAdapterGUI
525 {
526 $lng = $this->domain->lng();
527 $this->gui->ctrl()->setParameterByClass(self::class, "edit_id", $id);
528 $ot = $this->domain->translation($this->lm->getId());
529 $ml = "";
530 if ($ot->getContentTranslationActivated()) {
531 $ml = " (" . $lng->txt("meta_l_" . $ot->getBaseLanguage()) . ")";
532 }
533
534 $form = $this
535 ->gui
536 ->form([self::class], $cmd)
537 ->text("title", $lng->txt('title') . $ml, "", ilLMObject::_lookupTitle($id), 200);
538 if ($ot->getContentTranslationActivated()) {
539 foreach ($ot->getLanguages() as $lang) {
540 $code = $lang->getLanguageCode();
541 if ($code === $ot->getBaseLanguage()) {
542 continue;
543 }
544 $lmobjtrans = new \ilLMObjTranslation($id, $code);
545 $title = $lmobjtrans->getTitle();
546 $form = $form->text(
547 "title_" . $code,
548 $lng->txt('title') . " (" . $lng->txt("meta_l_" . $code) . ")",
549 "",
550 $title,
551 200
552 );
553 }
554 }
555 return $form;
556 }
557
558 public function editTitle(int $id): void
559 {
560 $lng = $this->domain->lng();
561 $this->gui->clearAsnyOnloadCode();
562 $modal = $this->gui->modal($lng->txt("cont_edit_title"))->form($this->getEditTitleForm($id));
563 $modal->send();
564 }
565
566 public function getTitlesFromForm(): array
567 {
568 $titles = [];
569 $form = $this->getEditTitleForm($this->request->getEditId());
570 if ($form->isValid()) {
571 $titles["-"] = $form->getData("title");
572
573 $ot = $this->domain->translation($this->lm->getId());
574 if ($ot->getContentTranslationActivated()) {
575 foreach ($ot->getLanguages() as $lang) {
576 $code = $lang->getLanguageCode();
577 if ($code === $ot->getBaseLanguage()) {
578 continue;
579 }
580 $titles[$code] = $form->getData("title_" . $code);
581 }
582 }
583 }
584 return $titles;
585 }
586
587 public function getLayoutIdFromForm(): int
588 {
589 $form = $this->getAddPageForm("");
590 if ($form->isValid()) {
591 if ($form->getData("use_template")) {
592 return (int) $form->getData("template_id");
593 }
594 }
595 return 0;
596 }
597
598 public function saveTitle(): void
599 {
600 $mt = $this->gui->mainTemplate();
601 $lng = $this->domain->lng();
602 $form = $this->getEditTitleForm($this->request->getEditId());
603 if ($form->isValid()) {
604 \ilLMObject::saveTitle($this->request->getEditId(), $form->getData("title"));
605
606 $ot = $this->lm->getObjectProperties()->getPropertyTranslations();
607 if ($ot->getContentTranslationActivated()) {
608 foreach ($ot->getLanguages() as $lang) {
609 $code = $lang->getLanguageCode();
610 if ($code === $ot->getBaseLanguage()) {
611 continue;
612 }
613 \ilLMObject::saveTitle($this->request->getEditId(), $form->getData("title_" . $code), $code);
614 }
615 }
616 }
617 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
618 $this->gui->ctrl()->redirect($this, "list");
619 }
620
621 public function saveOrder(): void
622 {
623 $mt = $this->gui->mainTemplate();
624 $lng = $this->domain->lng();
625 $tree = $this->domain->lmTree($this->lm_id);
626 $table = $this->getTable();
627 $data = $table->getData();
628 $parent = ($this->sub_obj_id > 0)
629 ? $this->sub_obj_id
630 : $tree->readRootId();
631 if (!is_array($data)) {
632 return;
633 }
634
635 // note: moveTree has a bug and does not use the last parameter
636 // target will always be "last node"
637 // since all chapters must follow all pages
638 // we can simple call moveTree in the correct order for the chapters
639 // but if we order the pages, we must append all chapters to the data first
640 if ($this->sub_type === "pg") {
641 foreach ($tree->getChilds($parent) as $child) {
642 if ($child["type"] == "st") {
643 $data[] = $child["child"];
644 }
645 }
646 }
647 foreach ($data as $id) {
648 $tree->moveTree((int) $id, $parent);
649 }
650 $mt->setContent("success", $lng->txt("msg_obj_modified"), true);
651 $this->gui->ctrl()->redirect($this, "list");
652 }
653
660 public function delete(array $ids): void
661 {
662 $a_parent_subobj_id = $this->sub_obj_id;
663 $mt = $this->gui->mainTemplate();
664 $lng = $this->domain->lng();
665 $ctrl = $this->gui->ctrl();
666
667 if (count($ids) == 0) {
668 $mt->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
669 $this->cancelDelete();
670 }
671
672 if (count($ids) == 1 && $ids[0] == \ilTree::POS_FIRST_NODE) {
673 $mt->setOnScreenMessage('failure', $lng->txt("cont_select_item"), true);
674 $this->cancelDelete();
675 }
676
677 $form_action = $ctrl->getFormActionByClass(self::class);
678
679 // display confirmation message
680 $cgui = new \ilConfirmationGUI();
681 $cgui->setFormAction($form_action);
682 $cgui->setHeaderText($lng->txt("info_delete_sure"));
683 $cgui->setCancel($lng->txt("cancel"), "cancelDelete");
684 $cgui->setConfirm($lng->txt("confirm"), "confirmedDelete");
685
686 foreach ($ids as $id) {
687 if ($id != \ilTree::POS_FIRST_NODE) {
688 $obj = new \ilLMObject($this->lm, $id);
689 $caption = $obj->getTitle();
690
691 $cgui->addItem("id[]", (string) $id, $caption);
692 }
693 }
694
695 $mt->setContent($cgui->getHTML());
696 }
697
698 public function cancelDelete(): void
699 {
700 $this->gui->ctrl()->redirect($this, "list");
701 }
702
710 public function confirmedDelete(int $a_parent_subobj_id = 0): void
711 {
712 $tree = $this->domain->lmTree($this->lm_id);
713 $ids = $this->request->getIds();
714 $mt = $this->gui->mainTemplate();
715 $ctrl = $this->gui->ctrl();
716 $lng = $this->domain->lng();
717
718 // check number of objects
719 if (count($ids) == 0) {
720 $mt->setOnScreenMessage('failure', $lng->txt("no_checkbox"));
721 $ctrl->redirect($this, "list");
722 }
723
724 // delete all selected objects
725 foreach ($ids as $id) {
726 if ($id != \ilTree::POS_FIRST_NODE) {
727 $obj = \ilLMObjectFactory::getInstance($this->lm, $id, false);
728 $node_data = $tree->getNodeData($id);
729 if (is_object($obj)) {
730 $obj->setLMId($this->lm->getId());
731 $obj->delete();
732 }
733 if ($tree->isInTree($id)) {
734 $tree->deleteTree($node_data);
735 }
736 }
737 }
738
739 // check the tree
740 $this->lm->checkTree();
741
742 // feedback
743 $mt->setOnScreenMessage('success', $lng->txt("info_deleted"), true);
744 $ctrl->redirect($this, "list");
745 }
746
750 public function cutItems(array $ids): void
751 {
752 $ctrl = $this->gui->ctrl();
753 $mt = $this->gui->mainTemplate();
754 $lng = $this->domain->lng();
755
756 $items = $ids;
757 if (count($items) == 0) {
758 $mt->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
759 $ctrl->redirect($this, "list");
760 }
761
762 $todel = array(); // delete IDs < 0 (needed for non-js editing)
763 foreach ($items as $k => $item) {
764 if ($item < 0) {
765 $todel[] = $k;
766 }
767 }
768 foreach ($todel as $k) {
769 unset($items[$k]);
770 }
771
772 \ilLMObject::clipboardCut($this->lm_id, $items);
774 $mt->setOnScreenMessage('info', $lng->txt("cont_selected_items_have_been_cut"), true);
775
776 $ctrl->redirect($this, "list");
777 }
778
782 public function copyItems($ids): void
783 {
784
785 $ctrl = $this->gui->ctrl();
786 $lng = $this->domain->lng();
787 $mt = $this->gui->mainTemplate();
788
789 $items = $ids;
790 if (count($items) == 0) {
791 $mt->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
792 $ctrl->redirect($this, "list");
793 }
794
795 $todel = array(); // delete IDs < 0 (needed for non-js editing)
796 foreach ($items as $k => $item) {
797 if ($item < 0) {
798 $todel[] = $k;
799 }
800 }
801 foreach ($todel as $k) {
802 unset($items[$k]);
803 }
804
805 \ilLMObject::clipboardCopy($this->lm_id, $items);
807
808 $mt->setOnScreenMessage('info', $lng->txt("cont_selected_items_have_been_copied"), true);
809 $ctrl->redirect($this, "list");
810 }
811
812 public function activatePages(array $ids): void
813 {
814 $ctrl = $this->gui->ctrl();
815 $mt = $this->gui->mainTemplate();
816 $lng = $this->domain->lng();
817 $lm_tree = $this->domain->lmTree($this->lm_id);
818
819 $ids = $ids;
820 if (count($ids) > 0) {
821 $act_items = array();
822 // get all "top" ids, i.e. remove ids, that have a selected parent
823 foreach ($ids as $id) {
824 $path = $lm_tree->getPathId($id);
825 $take = true;
826 foreach ($path as $path_id) {
827 if ($path_id != $id && in_array($path_id, $ids)) {
828 $take = false;
829 }
830 }
831 if ($take) {
832 $act_items[] = $id;
833 }
834 }
835
836
837 foreach ($act_items as $id) {
838 $childs = $lm_tree->getChilds($id);
839 foreach ($childs as $child) {
840 if (ilLMObject::_lookupType($child["child"]) == "pg") {
842 $child["child"],
843 $this->lm->getType()
844 );
846 $child["child"],
847 $this->lm->getType(),
848 !$act
849 );
850 }
851 }
852 if (ilLMObject::_lookupType($id) == "pg") {
854 $id,
855 $this->lm->getType()
856 );
858 $id,
859 $this->lm->getType(),
860 !$act
861 );
862 }
863 }
864 } else {
865 $mt->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
866 }
867
868 $ctrl->redirect($this, "list");
869 }
870
871 /*
872
873 public function insertLayoutBefore(): void
874 {
875 $this->insertLayout(true);
876 }
877
878 public function insertLayoutAfter(): void
879 {
880 $this->insertLayout();
881 }
882
883 public function insertLayout(bool $before = false): void
884 {
885 $ctrl = $this->gui->ctrl();
886 $ui = $this->gui->ui();
887 $mt = $this->gui->mainTemplate();
888 if ($before) {
889 $ctrl->setParameterByClass(self::class, "before", "1");
890 }
891 $ctrl->saveParameterByClass(self::class, ["obj_id", "target_id"]);
892 $form = $this->initInsertTemplateForm();
893 $mt->setContent($ui->renderer()->render($form) . \ilLMPageObjectGUI::getLayoutCssFix());
894 }
895
896 public function initInsertTemplateForm(): Standard
897 {
898 $ui = $this->gui->ui();
899 $f = $ui->factory();
900 $ctrl = $this->gui->ctrl();
901 $lng = $this->domain->lng();
902
903 $fields["title"] = $f->input()->field()->text($lng->txt("title"), "");
904 $ts = \ilPageLayoutGUI::getTemplateSelection((string) \ilPageLayout::MODULE_LM);
905 if (!is_null($ts)) {
906 $fields["layout_id"] = $ts;
907 }
908
909 // section
910 $section1 = $f->input()->field()->section($fields, $lng->txt("cont_insert_pagelayout"));
911
912 $form_action = $ctrl->getLinkTarget($this, "insertPageFromLayout");
913 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
914 }
915
916 public function insertPageFromLayout(): void
917 {
918 global $DIC;
919
920 $ctrl = $this->gui->ctrl();
921 $mt = $this->gui->mainTemplate();
922 $lng = $this->domain->lng();
923
924
925 $parent = $this->sub_obj_id;
926 $target_id = $this->request->getTargetId();
927
928 $first_child = false;
929 if ($this->request->getBefore()) {
930 $before_target = \ilTree::POS_FIRST_NODE;
931 $first_child = true;
932 foreach ($this->lm_tree->getChildsByType($parent, "pg") as $node) {
933 if ((int) $node["obj_id"] !== $target_id) {
934 $before_target = (int) $node["obj_id"];
935 $first_child = false;
936 } else {
937 break;
938 }
939 }
940 $target_id = $before_target;
941 }
942
943 $form = $this->initInsertTemplateForm();
944 $form = $form->withRequest($DIC->http()->request());
945 $data = $form->getData();
946 $layout_id = $data["sec"]["layout_id"];
947 $page_ids = \ilLMPageObject::insertPagesFromTemplate(
948 $this->lm->getId(),
949 1,
950 $target_id,
951 $first_child,
952 (int) $layout_id,
953 $data["sec"]["title"]
954 );
955
956 $mt->setOnScreenMessage("success", $lng->txt("lm_page_added"), true);
957
958 $ctrl->redirect($this, "list");
959 }
960
961 */
962}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
insertPage(int $parent_id=0, int $target=0, array $titles=[], int $layout_id=0)
insertChapter(int $parent_id=0, int $target=\ilTree::POS_LAST_NODE, array $titles=[])
__construct(protected InternalDomainService $domain, protected InternalGUIService $gui, protected string $sub_type, protected \ilObjLearningModule $lm, protected string $table_title)
cutItems(array $ids)
Copy items to clipboard, then cut them from the current tree.
confirmedDelete(int $a_parent_subobj_id=0)
delete page object or structure objects
static setAction(string $a_action)
static getInstance(ilObjLearningModule $a_content_obj, int $a_id=0, bool $a_halt=true)
Class ilLMObject.
static saveTitle(int $id, string $title, string $lang="-")
static clipboardCut(int $a_cont_obj_id, array $a_ids)
Copy a set of chapters/pages into the clipboard.
static _lookupTitle(int $a_obj_id)
static clipboardCopy(int $a_cont_obj_id, array $a_ids)
Copy a set of chapters/pages into the clipboard.
static updateInternalLinks(array $a_copied_nodes, string $a_parent_type="lm")
Update internal links, after multiple pages have been copied.
static putInTree(ilLMObject $a_obj, int $a_parent_id=0, int $a_target_node_id=0)
put this object into content object tree
static _lookupType(int $a_obj_id, int $a_lm_id=0)
static getMultiLangHeader(int $a_lm_id, object $a_gui_class, string $a_mode="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static activeLayouts(int $a_module=0)
Get active layouts.
static _writeActive(int $a_id, string $a_parent_type, bool $a_active)
write activation status
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
const POS_LAST_NODE
const POS_FIRST_NODE
This describes a standard form.
Definition: Standard.php:30
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31