ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilOrgUnitGlobalSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
25 
32 {
33  protected const CMD_EDIT = 'edit';
34  protected const CMD_SAVE = 'save';
35 
36  protected ilCtrl $ctrl;
37  protected ilLanguage $lng;
39 
40  protected ilSetting $settings;
44  protected Refinery $refinery;
46 
47  public function __construct()
48  {
49  global $DIC;
50  $main_tpl = $DIC->ui()->mainTemplate();
51 
52  $this->ctrl = $DIC->ctrl();
53  $this->lng = $DIC->language();
54  $this->lng->loadLanguageModule('orgu');
55  $this->tpl = $DIC->ui()->mainTemplate();
56  $this->request = $DIC->http()->request();
57  $to_int = $DIC['refinery']->kindlyTo()->int();
58  $ref_id = $DIC['http']->wrapper()->query()->retrieve('ref_id', $to_int);
59 
61  $main_tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
62  $this->ctrl->redirectByClass(ilObjOrgUnitGUI::class);
63  }
64 
65  $this->settings = $DIC->settings();
66  $this->object_definition = $DIC["objDefinition"];
67  $this->ui_factory = $DIC['ui.factory'];
68  $this->ui_renderer = $DIC['ui.renderer'];
69  $this->refinery = $DIC['refinery'];
70  }
71 
72  public function executeCommand(): void
73  {
74  $cmd = $this->ctrl->getCmd(self::CMD_EDIT);
75  $next_class = $this->ctrl->getNextClass($this);
76 
77  switch ($next_class) {
78  default:
79  switch ($cmd) {
80  case self::CMD_SAVE:
81  $this->save();
82  break;
83  case self::CMD_EDIT:
84  default:
85  $this->edit();
86  }
87  }
88  }
89 
90  private function edit(): void
91  {
92  $form = $this->getSettingsForm();
93  $this->tpl->setContent(
94  $this->ui_renderer->render($form)
95  );
96  }
97 
98  private function save(): void
99  {
100  $form = $this->getSettingsForm()->withRequest($this->request);
101  $data = $form->getData();
102 
103  if (!$data) {
104  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), false);
105  $this->tpl->setContent($this->ui_renderer->render($form));
106  }
107  $enable_my_staff = current(array_shift($data));
108  $obj_settings = array_shift($data);
109 
110  $this->settings->set("enable_my_staff", $enable_my_staff);
111 
112  $available_types = $this->object_definition->getOrgUnitPermissionTypes();
113  foreach ($available_types as $object_type) {
114 
115  $active = false;
116  $changeable = false;
117  $default = false;
118  if (!is_null($obj_settings[$object_type])) {
119  list($active, $changeable, $default) = array_shift($obj_settings[$object_type]);
120  }
121  $obj_setting = new ilOrgUnitObjectTypePositionSetting($object_type);
122  $obj_setting->setActive($active);
123  $obj_setting->setChangeableForObject($changeable);
124  $obj_setting->setActivationDefault((int) $default);
125  $obj_setting->update();
126  }
127  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
128  $this->ctrl->redirect($this, self::CMD_EDIT);
129  }
130 
131  protected function getSettingsForm(): StandardForm
132  {
133  $sections = [];
134  $sections[] = $this->ui_factory->input()->field()->section(
135  [
136  $this->ui_factory->input()->field()->checkbox(
137  $this->lng->txt("orgu_enable_my_staff"),
138  $this->lng->txt("orgu_enable_my_staff_info")
139  )
140  ->withValue($this->settings->get("enable_my_staff") ? true : false)
141  ],
142  $this->lng->txt("orgu_enable_my_staff")
143  );
144 
145  $groups = [];
146  $values = [];
147  $available_types = $this->object_definition->getOrgUnitPermissionTypes();
148  foreach ($available_types as $object_type) {
149 
150  $setting = new ilOrgUnitObjectTypePositionSetting($object_type);
151  $is_multi = false;
152 
153  if ($this->object_definition->isPlugin($object_type)) {
154  $label = ilObjectPlugin::lookupTxtById($object_type, 'objs_' . $object_type);
155  } else {
156  $is_multi = !$this->object_definition->isSystemObject($object_type)
157  && $object_type != ilOrgUnitOperationContext::CONTEXT_ETAL;
158  $lang_prefix = $is_multi ? 'objs_' : 'obj_';
159  $label = $this->lng->txt($lang_prefix . $object_type);
160  }
161 
162  $changeable = [];
163  if ($is_multi) {
164  $changeable[] = $this->ui_factory->input()->field()->switchableGroup(
165  [
166  $this->ui_factory->input()->field()->group(
167  [
168  $this->ui_factory->input()->field()->checkbox(
169  $this->lng->txt('orgu_global_set_type_default'),
170  $this->lng->txt('orgu_global_set_type_default_info'),
171  )
172  ->withValue((bool) $setting->getActivationDefault())
173  ],
174  $this->lng->txt('orgu_global_set_type_changeable_object'),
175  )
176  ,
177  $this->ui_factory->input()->field()->group(
178  [
179 
180  ],
181  $this->lng->txt('orgu_global_set_type_changeable_no'),
182  )
183  ],
184  $this->lng->txt('orgu_global_set_type_changeable')
185  )
186  ->withValue(
187  $setting->isChangeableForObject() ? 0 : 1
188  )
190  $this->refinery->custom()->transformation(
191  function ($v) {
192  $active = true;
193  $changeable = !(bool) array_shift($v);
194  $default = false;
195  if ($changeable) {
196  $default = (bool) current(array_shift($v));
197  }
198  return [$active, $changeable, $default];
199  }
200  )
201  );
202  } else {
203  $changeable[] = $this->ui_factory->input()->field()->hidden()->withValue('true')
204  ->withAdditionalTransformation(
205  $this->refinery->custom()->transformation(
206  fn($v) => [true, false, false]
207  )
208  );
209  }
210 
211  $groups[$object_type] = $this->ui_factory->input()->field()->optionalGroup(
212  $changeable,
213  $this->lng->txt('orgu_global_set_positions_type_active') . ' ' . $label
214  );
215 
216  if (!$setting->isActive()) {
217  $groups[$object_type] = $groups[$object_type]->withValue(null);
218  }
219  }
220 
221  $sections[] = $this->ui_factory->input()->field()->section(
222  $groups,
223  $this->lng->txt("orgu_global_set_positions")
224  );
225 
226  $form_action = $this->ctrl->getFormAction($this, self::CMD_SAVE);
227  return $this->ui_factory->input()->container()->form()->standard(
228  $form_action,
229  $sections
230  );
231  }
232 
233 }
static _checkAccessSettings(int $ref_id)
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:25
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
static lookupTxtById(string $plugin_id, string $lang_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...