ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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(
71  [
72  ilRepositoryGUI::class,
73  self::class,
74  ilInfoScreenGUI::class
75  ],
76  'showSummary'
77  );
78  }
79 
80  $this->tabs->activateTab('settings');
81  $this->tabs->activateSubTab('qpl_settings_subtab_general');
82 
83  // process command
84 
85  $nextClass = $this->ctrl->getNextClass();
86 
87  switch ($nextClass) {
88  default:
89  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_FORM) . 'Cmd';
90  $this->$cmd();
91  }
92  }
93 
94  private function showFormCmd(?Form $form = null): void
95  {
96  $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
97  if ($form === null) {
98  $form = $this->buildForm();
99  }
100  $this->tpl->setContent($this->ui_renderer->render($form));
101  }
102 
103  private function saveFormCmd(): void
104  {
105  $form = $this->buildForm()->withRequest($this->http_request);
106  $result = $form->getInputGroup()->getContent();
107 
108  if (!$result->isOK()) {
109  $this->tpl->setOnScreenMessage(MessageBox::FAILURE, $this->lng->txt('form_input_not_valid'));
110  $this->showFormCmd($form);
111  return;
112  }
113 
114  $this->performSaveForm($result->value());
115  $this->tpl->setOnScreenMessage(MessageBox::SUCCESS, $this->lng->txt("msg_obj_modified"), true);
116  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_FORM);
117 
118  }
119 
120  private function performSaveForm($data): void
121  {
122  $title_and_description = $data['general_settings']['title_and_description'] ?? null;
123  if ($title_and_description instanceof ilObjectPropertyTitleAndDescription) {
124  $this->poolOBJ->getObjectProperties()->storePropertyTitleAndDescription(
125  $title_and_description
126  );
127  }
128 
129  $this->poolOBJ->getObjectProperties()->storePropertyIsOnline(
130  $data['availability']['online'] ?? $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->withOffline()
131  );
132 
133  $display_settings = $data['display_settings'] ?? [];
134  if (isset($display_settings['tile_image'])) {
135  $this->poolOBJ->getObjectProperties()->storePropertyTileImage($display_settings['tile_image']);
136  }
137 
138  $this->poolOBJ->setSkillServiceEnabled($data['additional_features']['skill_service'] ?? false);
139 
140  $this->poolOBJ->saveToDb();
141  }
142 
143  private function buildForm(): Form
144  {
145  $items = [];
146 
147  $title_and_description = $this->poolOBJ->getObjectProperties()->getPropertyTitleAndDescription()->toForm(
148  $this->lng,
149  $this->ui_factory->input()->field(),
151  );
152 
153  $items['general_settings'] = $this->ui_factory->input()->field()->section(
154  [
155  'title_and_description' => $title_and_description
156  ],
157  $this->lng->txt('qpl_form_general_settings')
158  );
159 
160  $online = $this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->toForm(
161  $this->lng,
162  $this->ui_factory->input()->field(),
164  );
165  $availability = $this->ui_factory->input()->field()->section(
166  ['online' => $online],
167  $this->lng->txt('qpl_settings_availability')
168  );
169  $items['availability'] = $availability;
170 
171  $timg = $this->poolOBJ->getObjectProperties()->getPropertyTileImage()->toForm(
172  $this->lng,
173  $this->ui_factory->input()->field(),
175  );
176  $items['display_settings'] = $this->ui_factory->input()->field()->section(
177  ['tile_image' => $timg],
178  $this->lng->txt('tst_presentation_settings_section')
179  );
180 
181  $additional_features_inputs = [];
182 
184  $additional_features_inputs['skill_service'] = $this->ui_factory->input()->field()->checkbox(
185  $this->lng->txt('tst_activate_skill_service')
186  )->withValue($this->poolOBJ->isSkillServiceEnabled());
187  }
188 
189  $items['additional_features'] = $this->ui_factory->input()->field()->section(
190  $additional_features_inputs,
191  $this->lng->txt('obj_features')
192  );
193 
194  return $this->ui_factory->input()->container()->form()->standard(
195  $this->ctrl->getFormAction($this, self::CMD_SAVE_GENERAL_FORM),
196  $items
197  );
198  }
199 }
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,)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
The progress of the process/task cannot be calculated (yet), but it has started processing.
Definition: Status.php:42
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
Class ilObjQuestionPoolGUI.
global $lng
Definition: privfeed.php:31