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