ILIAS  release_8 Revision v8.24
class.ilAdministrationSettingsFormHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
31 protected static array $OBJ_MAP;
32
33 public const FORM_PRIVACY = 1;
34 public const FORM_SECURITY = 2;
35 public const FORM_LP = 4;
36 public const FORM_MAIL = 5;
37 public const FORM_COURSE = 6;
38 public const FORM_GROUP = 7;
39 public const FORM_REPOSITORY = 8;
40 public const FORM_LDAP = 9;
41 public const FORM_FORUM = 10;
42 public const FORM_ACCESSIBILITY = 11;
43 public const FORM_WSP = 12;
44 public const FORM_TAGGING = 13;
45 public const FORM_CERTIFICATE = 14;
46 public const FORM_META_COPYRIGHT = 15;
47 public const FORM_TOS = 16;
48
49 public const FORM_CALENDAR = 17;
50
51 public const SETTINGS_USER = "usrf";
52 public const SETTINGS_GENERAL = "adm";
53 public const SETTINGS_FILE = "facs";
54 public const SETTINGS_ROLE = "rolf";
55 public const SETTINGS_FORUM = "frma";
56 public const SETTINGS_LRES = "lrss";
57 public const SETTINGS_REPOSITORY = "reps";
58 public const SETTINGS_PR = "prss";
59 public const SETTINGS_COURSE = "crss";
60 public const SETTINGS_GROUP = "grps";
61 public const SETTINGS_PRIVACY_SECURITY = "ps";
62 public const SETTINGS_CALENDAR = "cals";
63 public const SETTINGS_AUTH = "auth";
64 public const SETTINGS_WIKI = "wiks";
65 public const SETTINGS_PORTFOLIO = "prfa";
66 public const SETTINGS_LP_COMPLETION_STATUS = "trac";
67 public const SETTINGS_LEARNINGSEQUENCE = "lsos";
68 public const SETTINGS_COMMENTS = "coms";
69
70 public const VALUE_BOOL = "bool";
71
72 protected static function initObjectMap(): void
73 {
75 global $DIC;
76
77 $tree = $DIC->repositoryTree();
78
79 $map = array("adm" => SYSTEM_FOLDER_ID);
80 foreach ($tree->getChilds(SYSTEM_FOLDER_ID) as $obj) {
81 $map[$obj["type"]] = (int) $obj["ref_id"];
82 }
83
84 self::$OBJ_MAP = $map;
85 }
86
87 protected static function getRefId(string $a_obj_type): int
88 {
89 if (!isset(self::$OBJ_MAP)) {
90 self::initObjectMap();
91 }
92 return self::$OBJ_MAP[$a_obj_type] ?? 0;
93 }
94
95 public static function getSettingsGUIInstance(string $a_settings_obj_type): ilObjectGUI
96 {
97 global $DIC;
98
99 $objDefinition = $DIC["objDefinition"];
100
101 $ref_id = self::getRefId($a_settings_obj_type);
102 $obj_type = ilObject::_lookupType($ref_id, true);
103
104 $class_name = $objDefinition->getClassName($obj_type);
105 $class_name = "ilObj" . $class_name . "GUI";
106 if (is_subclass_of($class_name, "ilObject2GUI")) {
107 $gui_obj = new $class_name($ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
108 } else {
109 $gui_obj = new $class_name([], $ref_id, true, false);
110 }
111
112 $gui_obj->setCreationMode(true);
113
114 return $gui_obj;
115 }
116
117 public static function addFieldsToForm(
118 int $a_form_id,
119 ilPropertyFormGUI $a_form,
120 ilObjectGUI $a_parent_gui
121 ): void {
122 switch ($a_form_id) {
124 $types = array(self::SETTINGS_USER, self::SETTINGS_FILE, self::SETTINGS_ROLE);
125 break;
126
128 $types = array(self::SETTINGS_ROLE, self::SETTINGS_FORUM, self::SETTINGS_LRES, self::SETTINGS_COMMENTS);
129 break;
130
132 case self::FORM_LP:
133 $types = array(self::SETTINGS_REPOSITORY);
134 break;
135
137 $types = array(self::SETTINGS_FORUM, self::SETTINGS_AUTH, self::SETTINGS_WIKI);
138 break;
139
140 case self::FORM_MAIL:
141 $types = array(self::SETTINGS_COURSE, self::SETTINGS_GROUP, self::SETTINGS_LEARNINGSEQUENCE);
142 break;
143
145 $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL);
146 break;
147
148 case self::FORM_GROUP:
149 $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL, self::SETTINGS_COURSE);
150 break;
151
152 case self::FORM_WSP:
153 $types = array(self::SETTINGS_PORTFOLIO);
154 break;
155
157 $types = array(self::SETTINGS_LP_COMPLETION_STATUS);
158 break;
159
160 case self::FORM_TOS:
161 $types = [self::SETTINGS_USER];
162 break;
163
164 default:
165 $types = null;
166 break;
167 }
168
169 if (is_array($types)) {
170 foreach ($types as $type) {
172 if ($gui && method_exists($gui, "addToExternalSettingsForm")) {
173 $data = $gui->addToExternalSettingsForm($a_form_id);
174 if (is_array($data)) {
175 self::parseFieldDefinition($type, $a_form, $gui, $data);
176 }
177 }
178 }
179 }
180
181 // cron jobs - special handling
182
183 $parent_gui = new ilObjSystemFolderGUI(null, SYSTEM_FOLDER_ID, true);
184 $parent_gui->setCreationMode(true);
185
186 $gui = new ilCronManagerGUI();
187 $data = $gui->addToExternalSettingsForm($a_form_id);
188 if (is_array($data) && count($data)) {
189 self::parseFieldDefinition("cron", $a_form, $parent_gui, $data);
190 }
191 }
192
197 protected static function parseFieldValue(
198 ?string $a_field_type,
199 &$a_field_value
200 ) {
201 global $DIC;
202
203 $lng = $DIC->language();
204
205 switch ($a_field_type) {
206 case self::VALUE_BOOL:
207 $a_field_value = $a_field_value ?
208 $lng->txt("enabled") :
209 $lng->txt("disabled");
210 return $a_field_value;
211 }
212
213 if (!is_numeric($a_field_value) &&
214 $a_field_value !== null && !trim($a_field_value)) {
215 $a_field_value = "-";
216 }
217
218 return is_numeric($a_field_value) || $a_field_value !== "";
219 }
220
221 protected static function parseFieldDefinition(
222 string $a_type,
223 ilPropertyFormGUI $a_form,
224 ilObjectGUI $a_gui,
225 $a_data
226 ): void {
228 global $DIC;
229
230 $request = new \ILIAS\Administration\AdminGUIRequest(
231 $DIC->http(),
232 $DIC->refinery()
233 );
234
235
236 $lng = $DIC->language();
237 $rbacsystem = $DIC->rbac()->system();
238 $ilCtrl = $DIC->ctrl();
239 $ilAccess = $DIC->access();
240
241 if (!is_array($a_data)) {
242 return;
243 }
244
245 ilLoggerFactory::getLogger('root')->dump($a_data, ilLogLevel::ERROR);
246
247 // write permission for current gui?
248 $has_write = $ilAccess->checkAccess(
249 "write",
250 "",
251 $request->getRefId()
252 );
253
254 foreach ($a_data as $area_caption => $fields) {
255 if (is_numeric($area_caption) || !trim($area_caption)) {
256 $area_caption = "obj_" . $a_type;
257 }
258
259 if (is_array($fields) && count($fields) === 2) {
260 $cmd = $fields[0];
261 $fields = $fields[1];
262 if (is_array($fields)) {
263 $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "Services/Administration");
264
265
266 $stack = array();
267 foreach ($fields as $field_caption_id => $field_value) {
268 ilLoggerFactory::getLogger('root')->dump($field_caption_id, ilLogLevel::ERROR);
269 ilLoggerFactory::getLogger('root')->dump($field_value, ilLogLevel::ERROR);
270 $field_type = $subitems = null;
271 if (is_array($field_value)) {
272 $field_type = $field_value[1];
273 $subitems = $field_value[2] ?? [];
274 $field_value = $field_value[0];
275 }
276
277 if (self::parseFieldValue($field_type, $field_value)) {
278 $ftpl->setCurrentBlock("value_bl");
279 $ftpl->setVariable("VALUE", $field_value);
280 $ftpl->parseCurrentBlock();
281 }
282
283 if (is_array($subitems)) {
284 $ftpl->setCurrentBlock("subitem_bl");
285 foreach ($subitems as $sub_caption_id => $sub_value) {
286 $sub_type = null;
287 if (is_array($sub_value)) {
288 $sub_type = $sub_value[1];
289 $sub_value = $sub_value[0];
290 }
291 self::parseFieldValue($sub_type, $sub_value);
292
293 $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
294 $ftpl->setVariable("SUBVALUE", $sub_value);
295 $ftpl->parseCurrentBlock();
296 }
297 }
298
299 $ftpl->setCurrentBlock("row_bl");
300 $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
301 $ftpl->parseCurrentBlock();
302 }
303
304 if ($has_write &&
305 $rbacsystem->checkAccess("visible,read", $a_gui->getObject()->getRefId())) {
306 if (!$cmd) {
307 $cmd = "view";
308 }
309 $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->getObject()->getRefId());
310
311 $ftpl->setCurrentBlock("edit_bl");
312 $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass(array("ilAdministrationGUI", get_class($a_gui)), $cmd));
313 $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
314 $ftpl->parseCurrentBlock();
315 }
316
317 $ext = new ilCustomInputGUI($lng->txt($area_caption));
318 $ext->setHtml($ftpl->get());
319 $a_form->addItem($ext);
320 }
321 }
322 }
323 }
324}
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static parseFieldValue(?string $a_field_type, &$a_field_value)
Class ilCronManagerGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
Class ilObjSystemFolderGUI.
Class ilObjectGUI Basic methods of all Output classes.
static _lookupType(int $id, bool $reference=false)
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
$type
$lng