ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilIndividualAssessmentSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
22 use ILIAS\Refinery;
23 use ILIAS\UI;
26 
31 {
32  public const TAB_EDIT = 'settings';
33  public const TAB_EDIT_INFO = 'infoSettings';
34  public const TAB_COMMON_SETTINGS = 'commonSettings';
35 
36  protected ilCtrl $ctrl;
39  protected ilLanguage $lng;
40  protected ilTabsGUI $tabs_gui;
42  protected Input\Factory $input_factory;
43  protected Refinery\Factory $refinery;
44  protected UI\Renderer $ui_renderer;
45 
49  protected $http_request;
52 
53  public function __construct(
55  ilCtrl $ctrl,
57  ilLanguage $lng,
58  ilTabsGUI $tabs_gui,
59  Input\Factory $factory,
60  Refinery\Factory $refinery,
61  UI\Renderer $ui_renderer,
63  ilErrorHandling $error_object,
64  ilIndividualAssessmentCommonSettingsGUI $common_settings_gui
65  ) {
66  $this->ctrl = $ctrl;
67  $this->object = $object;
68  $this->tpl = $tpl;
69  $this->lng = $lng;
70  $this->tabs_gui = $tabs_gui;
71  $this->iass_access = $this->object->accessHandler();
72 
73  $this->input_factory = $factory;
74  $this->refinery = $refinery;
75  $this->ui_renderer = $ui_renderer;
76  $this->http_request = $http_request;
77 
78  $this->error_object = $error_object;
79  $this->common_settings_gui = $common_settings_gui;
80 
81  $this->getSubTabs($this->tabs_gui);
82  $this->lng->loadLanguageModule('content');
83  $this->lng->loadLanguageModule('obj');
84  $this->lng->loadLanguageModule('cntr');
85  }
86 
87  protected function getSubTabs(ilTabsGUI $tabs): void
88  {
89  $tabs->addSubTab(
90  self::TAB_EDIT,
91  $this->lng->txt("edit"),
92  $this->ctrl->getLinkTarget($this, 'edit')
93  );
94  $tabs->addSubTab(
95  self::TAB_COMMON_SETTINGS,
96  $this->lng->txt("obj_features"),
97  $this->ctrl->getLinkTargetByClass(
98  [
99  self::class,
100  ilIndividualAssessmentCommonSettingsGUI::class
101  ],
103  )
104  );
105  $tabs->addSubTab(
106  self::TAB_EDIT_INFO,
107  $this->lng->txt("iass_edit_info"),
108  $this->ctrl->getLinkTarget($this, 'editInfo')
109  );
110  }
111 
112  public function executeCommand(): void
113  {
114  if (!$this->iass_access->mayEditObject()) {
115  $this->handleAccessViolation();
116  }
117  $next_class = $this->ctrl->getNextClass();
118  $cmd = $this->ctrl->getCmd();
119  switch ($next_class) {
120  case 'ilindividualassessmentcommonsettingsgui':
121  $this->tabs_gui->activateSubTab(self::TAB_COMMON_SETTINGS);
122  $this->ctrl->forwardCommand($this->common_settings_gui);
123  break;
124  default:
125  switch ($cmd) {
126  case 'edit':
127  $this->edit();
128  break;
129  case 'update':
130  $this->update();
131  break;
132  case 'editInfo':
133  $this->editInfo();
134  break;
135  case 'updateInfo':
136  $this->updateInfo();
137  break;
138  }
139  }
140  }
141 
142  protected function buildForm(): Form\Form
143  {
144  $settings = $this->object->getSettings();
145  $field = $settings->toFormInput(
146  $this->input_factory->field(),
147  $this->lng,
149  );
150 
151  // Use centralized on/offline
152  $online = $this->object->getObjectProperties()->getPropertyIsOnline()->toForm(
153  $this->lng,
154  $this->input_factory->field(),
156  );
157  $availability = $this->input_factory->field()->section(
158  [$online],
159  $this->lng->txt('iass_settings_availability')
161  $this->refinery->custom()->transformation(function ($v) {
162  return array_shift($v);
163  })
164  );
165 
166  return $this->input_factory->container()->form()->standard(
167  $this->ctrl->getFormAction($this, "update"),
168  [$field, $availability]
169  );
170  }
171 
172  protected function edit(): void
173  {
174  $this->tabs_gui->setSubTabActive(self::TAB_EDIT);
175  $form = $this->buildForm();
176  $this->tpl->setContent($this->ui_renderer->render($form));
177  }
178 
179  protected function update(): void
180  {
181  $form = $this->buildForm();
182  $form = $form->withRequest($this->http_request);
183 
184  $settings = $form->getData();
185 
186  if (!is_null($settings)) {
187  $this->object->setSettings($settings[0]);
188  $this->object->update();
189 
190  $this->object->getObjectProperties()->storePropertyIsOnline($settings[1]);
191 
192  $this->tpl->setOnScreenMessage("success", $this->lng->txt("settings_saved"), true);
193  $this->ctrl->redirect($this, "edit");
194  } else {
195  $this->tpl->setContent($this->ui_renderer->render($form));
196  }
197  }
198 
199  protected function editInfo(): void
200  {
201  $this->tabs_gui->setSubTabActive(self::TAB_EDIT_INFO);
202  $form = $this->buildInfoSettingsForm();
203  $this->tpl->setContent($this->ui_renderer->render($form));
204  }
205 
206  protected function updateInfo(): void
207  {
208  $form = $this->buildInfoSettingsForm();
209  $form = $form->withRequest($this->http_request);
210 
211  $info_settings = $form->getData();
212 
213  if (!is_null($info_settings)) {
214  $this->object->setInfoSettings($info_settings);
215  $this->object->updateInfo();
216  $this->ctrl->redirect($this, "editInfo");
217  } else {
218  $this->tpl->setContent($this->ui_renderer->render($form));
219  }
220  }
221 
222  protected function buildInfoSettingsForm(): Form\Form
223  {
224  $info_settings = $this->object->getInfoSettings();
225  $field = $info_settings->toFormInput(
226  $this->input_factory->field(),
227  $this->lng,
229  );
230  return $this->input_factory->container()->form()->standard(
231  $this->ctrl->getFormAction($this, "updateInfo"),
232  [$field]
233  )
235  $this->refinery->custom()->transformation(function ($v) {
236  return array_shift($v);
237  })
238  );
239  }
240 
241  public function handleAccessViolation(): void
242  {
243  $this->error_object->raiseError($this->lng->txt("msg_no_perm_read"), $this->error_object->WARNING);
244  }
245 }
An entity that renders components to a string output.
Definition: Renderer.php:30
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This describes commonalities between all forms.
Definition: Form.php:32
For the purpose of streamlining the grading and learning-process status definition outside of tests...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
Mechanic regarding the access control and roles of an objet goes here.
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjIndividualAssessment $object, ilCtrl $ctrl, ilGlobalPageTemplate $tpl, ilLanguage $lng, ilTabsGUI $tabs_gui, Input\Factory $factory, Refinery\Factory $refinery, UI\Renderer $ui_renderer, $http_request, ilErrorHandling $error_object, ilIndividualAssessmentCommonSettingsGUI $common_settings_gui)
ilIndividualAssessmentCommonSettingsGUI $common_settings_gui
Error Handling & global info handling.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between all inputs.
Definition: Input.php:46
ilIndividualAssessmentSettingsGUI: ilIndividualAssessmentCommonSettingsGUI
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...