ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.SettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Glossary\Settings;
22 
27 
32 {
33  public function __construct(
34  protected InternalDataService $data,
35  protected InternalDomainService $domain,
36  protected InternalGUIService $gui,
37  protected int $obj_id,
38  protected int $ref_id,
39  protected bool $creation_mode,
40  protected object $parent_gui,
41  protected object $parent_obj
42  ) {
43  }
44 
45  public function executeCommand(): void
46  {
47  $ctrl = $this->gui->ctrl();
48  $next_class = $ctrl->getNextClass($this);
49  $cmd = $ctrl->getCmd("edit");
50 
51  switch ($next_class) {
52  case strtolower(\ilDidacticTemplateGUI::class):
53  $ctrl->setReturn($this, 'edit');
54  $did = new \ilDidacticTemplateGUI(
55  $this->parent_gui,
56  $this->getEditForm()->getDidacticTemplateIdFromRequest()
57  );
58  $ctrl->forwardCommand($did);
59  break;
60 
61  default:
62  if (in_array($cmd, ["edit", "save"])) {
63  $this->$cmd();
64  }
65  }
66  }
67 
68  protected function edit(): void
69  {
70  $mt = $this->gui->ui()->mainTemplate();
71  $form = $this->getEditForm();
72  $mt->setContent($form->render());
73  }
74 
75  protected function getEditForm(): FormAdapterGUI
76  {
77  $lng = $this->domain->lng();
78  $settings = $this->domain->glossarySettings()->getByObjId($this->obj_id);
80  $glo_obj = $this->parent_obj;
81 
82  $glo_mode_disabled = false;
83  $glo_mode_disabled_info = "";
84  if (!empty($glo_obj->getGlossariesForCollection()) && $glo_obj->isVirtual()) {
85  $glo_mode_disabled = true;
86  $glo_mode_disabled_info = $lng->txt("glo_change_to_standard_unavailable_info");
87  } elseif (!empty(\ilGlossaryTerm::getTermsOfGlossary($glo_obj->getId())) && !$glo_obj->isVirtual()) {
88  $glo_mode_disabled = true;
89  $glo_mode_disabled_info = $lng->txt("glo_change_to_collection_unavailable_info");
90  }
91 
92  $form = $this->gui
93  ->form(self::class, "save")
94  ->section("general", $lng->txt("cont_glo_properties"))
96  $this->obj_id,
97  "glo"
98  );
99 
100  $form = $form->addDidacticTemplates(
101  "glo",
102  $this->ref_id,
103  $this->creation_mode
104  );
105 
106  $form = $form->radio(
107  "glo_mode",
108  $lng->txt("glo_content_assembly"),
109  $glo_mode_disabled_info,
110  $settings->getVirtualMode()
111  )
112  ->disabled($glo_mode_disabled)
113  ->radioOption(
114  "none",
115  $lng->txt("glo_mode_normal"),
116  $lng->txt("glo_mode_normal_info")
117  )->radioOption(
118  "coll",
119  $lng->txt("glo_collection"),
120  $lng->txt("glo_collection_info")
121  )
122  ->section("avail", $lng->txt('rep_activation_availability'))
123  ->addOnline($this->obj_id, "glo")
124  //->addStdAvailability($this->ref_id, "glo")
125  ->section("presentation", $lng->txt('cont_presentation'))
126  ->addStdTile($this->obj_id, "glo")
127  ->switch(
128  "pres_mode",
129  $lng->txt("glo_presentation_mode"),
130  "",
131  $settings->getPresentationMode()
132  )
133  ->group(
134  "table",
135  $lng->txt("glo_table_form"),
136  $lng->txt("glo_table_form_info")
137  )
138  ->number(
139  "snippet_length",
140  $lng->txt("glo_text_snippet_length"),
141  $lng->txt("characters") . " - " . $lng->txt("glo_text_snippet_length_info"),
142  $settings->getSnippetLength(),
143  100,
144  3000
145  )
146  ->group(
147  "full_def",
148  $lng->txt("glo_full_definitions"),
149  $lng->txt("glo_full_definitions_info")
150  )
151  ->end()
152  ->checkbox(
153  "flash_active",
154  $lng->txt("glo_flashcard_training"),
155  $lng->txt("glo_flashcard_training_info"),
156  $settings->getActiveFlashcards()
157  )
158  ->radio(
159  "flash_mode",
160  $lng->txt("glo_mode"),
161  "",
162  $settings->getFlashcardsMode()
163  )
164  ->radioOption("term", $lng->txt("glo_term_vs_def"), $lng->txt("glo_term_vs_def_info"))
165  ->radioOption("def", $lng->txt("glo_def_vs_term"), $lng->txt("glo_def_vs_term_info"));
166 
167  $form = $form->addAdditionalFeatures(
168  $this->obj_id,
169  [
172  ]
173  );
174 
175  return $form;
176  }
177 
178  protected function save(): void
179  {
180  $mt = $this->gui->ui()->mainTemplate();
181  $form = $this->getEditForm();
182  $ctrl = $this->gui->ctrl();
183  $lng = $this->domain->lng();
184 
185  $old_settings = $this->domain->glossarySettings()->getByObjId($this->obj_id);
186 
187  if ($form->isValid()) {
188  $form->saveStdTitleAndDescription(
189  $this->obj_id,
190  "glo"
191  );
192  $form->saveStdTile(
193  $this->obj_id,
194  "glo"
195  );
196  $form->saveOnline(
197  $this->obj_id,
198  "glo"
199  );
200  $form->saveStdAvailability(
201  $this->ref_id
202  );
203  $form->saveAdditionalFeatures(
204  $this->obj_id,
205  [
208  ]
209  );
210 
212  $online_prop = $form->getData("is_online");
213 
214  $settings = $this->data->settings(
215  $this->obj_id,
216  $online_prop->getIsOnline(), // must be temporarily kept until usages are refactored
217  $form->getData("glo_mode"),
218  $old_settings->getActiveGlossaryMenu(), // obsolete?
219  $form->getData("pres_mode"),
220  $old_settings->getShowTaxonomy(),
221  (int) $form->getData("snippet_length") ?: 200,
222  (bool) $form->getData("flash_active"),
223  $form->getData("flash_mode")
224  );
225 
226  $this->domain->glossarySettings()->update($settings);
227 
228  // check if template is changed
229  $form->redirectToDidacticConfirmationIfChanged(
230  $this->ref_id,
231  "glo",
232  static::class
233  );
234 
235  $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
236  $ctrl->redirectByClass(self::class, "edit");
237  } else {
238  $mt = $this->gui->ui()->mainTemplate();
239  $mt->setContent($form->render());
240  }
241  }
242 }
$ref_id
Definition: ltiauth.php:65
static getTermsOfGlossary(int $a_glo_id)
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $obj_id, protected int $ref_id, protected bool $creation_mode, protected object $parent_gui, protected object $parent_obj)
addStdTitleAndDescription(int $obj_id, string $type)
addStdTile(int $obj_id, string $type)
global $lng
Definition: privfeed.php:31
disabled()
description: > Example showing how to plug a disabled checkbox into a form
Definition: disabled.php:32
addOnline(int $obj_id, string $type)