ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTermDefinitionBulkCreationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
28{
32 protected \ILIAS\Glossary\Term\TermManager $term_manager;
33
34 public function __construct(
38 ) {
39 $this->glossary = $glossary;
40 $this->domain = $domain;
41 $this->gui = $gui;
42 $lng = $domain->lng();
43 $lng->loadLanguageModule("glo");
44 $this->term_manager = $domain
45 ->term($glossary);
46 }
47
48 public function executeCommand(): void
49 {
50 $ctrl = $this->gui->ctrl();
51
52 $next_class = $ctrl->getNextClass($this);
53 $cmd = $ctrl->getCmd("showCreationForm");
54
55 switch ($next_class) {
56 default:
57 if (in_array($cmd, [
58 "showCreationForm",
59 "showConfirmationScreen",
60 "createTermDefinitionPairs"
61 ])) {
62 $this->$cmd();
63 }
64 }
65 }
66
67 public function modifyToolbar(ilToolbarGUI $toolbar): void
68 {
69 $lng = $this->domain->lng();
70 $ctrl = $this->gui->ctrl();
71 $components = $this
72 ->gui
73 ->modal($lng->txt("glo_bulk_creation"))
74 ->getAsyncTriggerButtonComponents(
75 $lng->txt("glo_bulk_creation"),
76 $ctrl->getLinkTarget($this, "showCreationForm", "", true),
77 false
78 );
79 foreach ($components as $type => $c) {
80 if ($type === "signal") {
81 continue;
82 }
83 $toolbar->addComponent($c);
84 }
85 }
86
87 protected function showCreationForm(): void
88 {
89 $lng = $this->domain->lng();
90 $this->gui
91 ->modal($lng->txt("glo_bulk_creation"))
92 ->form($this->getCreationForm())
93 ->send();
94 }
95
96 protected function getCreationForm(): \ILIAS\Repository\Form\FormAdapterGUI
97 {
98 $lng = $this->domain->lng();
99 $user = $this->domain->user();
100 $form = $this
101 ->gui
102 ->form(self::class, "showConfirmationScreen", $lng->txt("glo_save_and_continue"))
103 ->asyncModal()
104 //->section("creation", $lng->txt("glo_bulk_data"))
105 ->textarea(
106 "bulk_data",
107 $lng->txt("glo_term_definition_pairs"),
108 $lng->txt("glo_term_definition_pairs_info"),
109 )
110 ->required();
111
112 $session_lang = $this->term_manager->getSessionLang();
113 if ($session_lang != "") {
114 $s_lang = $session_lang;
115 } else {
116 $s_lang = $user->getLanguage();
117 }
118 $form->select(
119 "term_language",
120 $lng->txt("language"),
121 $this->domain->metadata()->getLOMLanguagesForSelectInputs(),
122 "",
123 $s_lang
124 )
125 ->required();
126
127 return $form;
128 }
129
130 protected function showConfirmationScreen(): void
131 {
132 $form = $this->getCreationForm();
133 $lng = $this->domain->lng();
134 if (!$form->isValid()) {
135 $this->gui->modal($lng->txt("glo_bulk_creation"))
136 ->form($form)
137 ->send();
138 }
139
140 $language = $form->getData("term_language");
141 $this->gui->modal($lng->txt("glo_bulk_creation"))
142 ->legacy($this->renderConfirmation(
143 $form->getData("bulk_data"),
144 $language
145 ))
146 ->send();
147 }
148
149 protected function renderConfirmation(string $data, string $language): string
150 {
151 $lng = $this->domain->lng();
152 $ctrl = $this->gui->ctrl();
153 $f = $this->gui->ui()->factory();
154 $r = $this->gui->ui()->renderer();
155 $html_util = $this->gui->html();
156
157 $conf_tpl = new ilTemplate("tpl.bulk_creation_confirmation.html", true, true, "components/ILIAS/Glossary");
158
159 $button = $f->button()->standard(
160 $lng->txt("glo_create_term_definition_pairs"),
161 "#"
162 )->withAdditionalOnLoadCode(static function (string $id) {
163 return <<<EOT
164 const glo_bulk_button = document.getElementById("$id");
165 glo_bulk_button.addEventListener("click", (event) => {
166 glo_bulk_button.closest(".c-modal").querySelector(".modal-body").querySelector("form").submit();
167 });
168EOT;
169 });
170
171 $mbox = $f->messageBox()->info(
172 $lng->txt("glo_bulk_confirmation")
173 )->withButtons([$button]);
174
175 $ctrl->setParameter($this, "term_language", $language);
176 $table = $this->domain->table()->getTermDefinitionBulkCreationTable($data, $this->glossary)->getComponent();
177
178 $conf_tpl->setVariable("HIDDEN_VALUE", $html_util->escape($data));
179 $conf_tpl->setVariable("ACTION", $ctrl->getFormAction($this, "createTermDefinitionPairs"));
180 $conf_tpl->setVariable("MBOX", $r->render($mbox));
181 $conf_tpl->setVariable("TABLE", $r->render($table));
182
183 return $conf_tpl->get();
184 }
185
186 protected function createTermDefinitionPairs(): void
187 {
188 $main_tpl = $this->gui->mainTemplate();
189 $ctrl = $this->gui->ctrl();
190 $lng = $this->domain->lng();
191 $request = $this->gui->editing()->request();
192
193 $data = $request->getBulkCreationData();
194 $language = $request->getTermLanguage();
195 $this->term_manager->createTermDefinitionPairsFromBulkInputString($data, $language);
196 $main_tpl->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
197 $ctrl->returnToParent($this);
198 }
199}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
term(\ilObjGlossary $glossary, int $user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
__construct(InternalDomainService $domain, InternalGUIService $gui, ilObjGlossary $glossary)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addComponent(\ILIAS\UI\Component\Component $a_comp)
$c
Definition: deliver.php:25
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31