ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjQuestionPoolSettingsGeneralGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
40 {
41  public const CMD_SHOW_GENERAL_FORM = 'showForm';
42  public const CMD_SAVE_GENERAL_FORM = 'saveForm';
43  public const TAB_COMMON_SETTINGS = 'settings';
45 
46  public function __construct(
47  private readonly ilCtrl $ctrl,
48  private readonly ilAccessHandler $access,
49  private readonly ilLanguage $lng,
50  private readonly ilGlobalTemplateInterface $tpl,
51  private readonly ilTabsGUI $tabs,
52  private readonly ilObjQuestionPoolGUI $poolGUI,
53  private readonly Refinery $refinery,
54  private readonly UIFactory $ui_factory,
55  private readonly UIRenderer $ui_renderer,
56  private readonly HttpRequest $http_request,
57  ) {
58  $this->poolOBJ = $poolGUI->getObject();
59  }
60 
64  public function executeCommand(): void
65  {
66  // allow only write access
67 
68  if (!$this->access->checkAccess('write', '', $this->poolGUI->getRefId())) {
69  $this->tpl->setOnScreenMessage('info', $this->lng->txt('cannot_edit_question_pool'), true);
70  $this->ctrl->redirectByClass('ilObjQuestionPoolGUI', 'infoScreen');
71  }
72 
73  $this->tabs->activateTab('settings');
74  $this->tabs->activateSubTab('qpl_settings_subtab_general');
75 
76  // process command
77 
78  $nextClass = $this->ctrl->getNextClass();
79 
80  switch ($nextClass) {
81  default:
82  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_FORM) . 'Cmd';
83  $this->$cmd();
84  }
85  }
86 
87  private function showFormCmd(Form $form = null): void
88  {
89  $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
90  if ($form === null) {
91  $form = $this->buildForm();
92  }
93  $this->tpl->setContent($this->ui_renderer->render($form));
94  }
95 
96  private function saveFormCmd(): void
97  {
98  $form = $this->buildForm();
99  $form = $form->withRequest($this->http_request);
100 
101  $result = $form->getInputGroup()->getContent();
102 
103  if ($result->isOK()) {
104  $values = $result->value();
105  $this->performSaveForm($values);
106  $this->tpl->setOnScreenMessage(MessageBox::SUCCESS, $this->lng->txt("msg_obj_modified"), true);
107  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_FORM);
108  } else {
109  $this->tpl->setOnScreenMessage(MessageBox::FAILURE, $this->lng->txt('form_input_not_valid'));
110  $this->showFormCmd($form);
111  }
112  }
113 
114  private function performSaveForm($data): void
115  {
116  $title_and_description = $data['general_settings']['title_and_description'] ?? null;
117  if ($title_and_description instanceof ilObjectPropertyTitleAndDescription) {
118  $this->poolOBJ->getObjectProperties()->storePropertyTitleAndDescription(
119  $title_and_description
120  );
121  }
122 
123  $online = $data['availability']['online'] ?? null;
124  $this->poolOBJ->getObjectProperties()->storePropertyIsOnline(
125  $online ?? $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->withOffline()
126  );
127 
128  $display_settings = $data['display_settings'] ?? [];
129  if (isset($display_settings['tile_image'])) {
130  $this->poolOBJ->getObjectProperties()->storePropertyTileImage($display_settings['tile_image']);
131  }
132 
133 
134  $additional_features = $data['additional_features'] ?? [];
135  $this->poolOBJ->setSkillServiceEnabled($additional_features['skill_service'] ?? false);
136  $this->poolOBJ->setShowTaxonomies($additional_features['show_tax'] ?? false);
137 
138  $this->poolOBJ->saveToDb();
139  }
140 
141  private function buildForm(): Form
142  {
143  $items = [];
144 
145  $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
146  $md_section = $md_obj->getGeneral();
147 
148  $title_and_description = $this->poolOBJ->getObjectProperties()->getPropertyTitleAndDescription()->toForm(
149  $this->lng,
150  $this->ui_factory->input()->field(),
152  );
153 
154  $items['general_settings'] = $this->ui_factory->input()->field()->section(
155  [
156  'title_and_description' => $title_and_description
157  ],
158  $this->lng->txt('qpl_form_general_settings')
159  );
160 
161  $online = $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->toForm(
162  $this->lng,
163  $this->ui_factory->input()->field(),
165  );
166  $availability = $this->ui_factory->input()->field()->section(
167  ['online' => $online],
168  $this->lng->txt('qpl_settings_availability')
169  );
170  $items['availability'] = $availability;
171 
172  $timg = $this->poolOBJ->getObjectProperties()->getPropertyTileImage()->toForm(
173  $this->lng,
174  $this->ui_factory->input()->field(),
176  );
177  $items['display_settings'] = $this->ui_factory->input()->field()->section(
178  ['tile_image' => $timg],
179  $this->lng->txt('tst_presentation_settings_section')
180  );
181 
182  $additional_features_inputs = [];
183 
185  $additional_features_inputs['skill_service'] = $this->ui_factory->input()->field()->checkbox(
186  $this->lng->txt('tst_activate_skill_service')
187  )->withValue($this->poolOBJ->isSkillServiceEnabled());
188  }
189 
190  $additional_features_inputs['show_tax'] = $this->ui_factory->input()->field()->checkbox(
191  $this->lng->txt('qpl_settings_general_form_property_show_taxonomies')
192  )->withValue($this->poolOBJ->getShowTaxonomies());
193 
194  $items['additional_features'] = $this->ui_factory->input()->field()->section(
195  $additional_features_inputs,
196  $this->lng->txt('obj_features')
197  );
198 
199  return $this->ui_factory->input()->container()->form()->standard(
200  $this->ctrl->getFormAction($this, self::CMD_SAVE_GENERAL_FORM),
201  $items
202  );
203  }
204 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private readonly ilCtrl $ctrl, private readonly ilAccessHandler $access, private readonly ilLanguage $lng, private readonly ilGlobalTemplateInterface $tpl, private readonly ilTabsGUI $tabs, private readonly ilObjQuestionPoolGUI $poolGUI, private readonly Refinery $refinery, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly HttpRequest $http_request,)
$lng
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
getGeneral()
Definition: class.ilMD.php:34
Refinery Factory $refinery