ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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_CALENDAR = 17;
48 public const FORM_PRG = 18;
49
50 public const SETTINGS_USER = "usrf";
51 public const SETTINGS_GENERAL = "adm";
52 public const SETTINGS_FILE = "facs";
53 public const SETTINGS_ROLE = "rolf";
54 public const SETTINGS_FORUM = "frma";
55 public const SETTINGS_LRES = "lrss";
56 public const SETTINGS_REPOSITORY = "reps";
57 public const SETTINGS_PR = "prss";
58 public const SETTINGS_COURSE = "crss";
59 public const SETTINGS_GROUP = "grps";
60 public const SETTINGS_PRIVACY_SECURITY = "ps";
61 public const SETTINGS_CALENDAR = "cals";
62 public const SETTINGS_AUTH = "auth";
63 public const SETTINGS_WIKI = "wiks";
64 public const SETTINGS_PORTFOLIO = "prfa";
65 public const SETTINGS_LP_COMPLETION_STATUS = "trac";
66 public const SETTINGS_LEARNINGSEQUENCE = "lsos";
67 public const SETTINGS_COMMENTS = "coms";
68
69 public const VALUE_BOOL = "bool";
70
71 protected static function initObjectMap(): void
72 {
74 global $DIC;
75
76 $tree = $DIC->repositoryTree();
77
78 $map = array("adm" => SYSTEM_FOLDER_ID);
79 foreach ($tree->getChilds(SYSTEM_FOLDER_ID) as $obj) {
80 $map[$obj["type"]] = (int) $obj["ref_id"];
81 }
82
83 self::$OBJ_MAP = $map;
84 }
85
86 protected static function getRefId(string $a_obj_type): int
87 {
88 if (!isset(self::$OBJ_MAP)) {
89 self::initObjectMap();
90 }
91 return self::$OBJ_MAP[$a_obj_type] ?? 0;
92 }
93
94 public static function getSettingsGUIInstance(string $a_settings_obj_type): ilObjectGUI
95 {
96 global $DIC;
97
98 $objDefinition = $DIC["objDefinition"];
99
100 $ref_id = self::getRefId($a_settings_obj_type);
101 $obj_type = ilObject::_lookupType($ref_id, true);
102
103 $class_name = $objDefinition->getClassName($obj_type);
104 $class_name = "ilObj" . $class_name . "GUI";
105 if (is_subclass_of($class_name, "ilObject2GUI")) {
106 $gui_obj = new $class_name($ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
107 } else {
108 $gui_obj = new $class_name([], $ref_id, true, false);
109 }
110
111 $gui_obj->setCreationMode(true);
112
113 return $gui_obj;
114 }
115
116 public static function addFieldsToForm(
117 int $a_form_id,
118 ilPropertyFormGUI $a_form,
119 ilObjectGUI $a_parent_gui
120 ): void {
121 switch ($a_form_id) {
123 $types = array(self::SETTINGS_USER, self::SETTINGS_FILE, self::SETTINGS_ROLE);
124 break;
125
127 $types = array(self::SETTINGS_ROLE, self::SETTINGS_FORUM, self::SETTINGS_LRES, self::SETTINGS_COMMENTS);
128 break;
129
131 case self::FORM_LP:
132 $types = array(self::SETTINGS_REPOSITORY);
133 break;
134
136 $types = array(self::SETTINGS_FORUM, self::SETTINGS_AUTH, self::SETTINGS_WIKI);
137 break;
138
139 case self::FORM_MAIL:
140 $types = array(self::SETTINGS_COURSE, self::SETTINGS_GROUP, self::SETTINGS_LEARNINGSEQUENCE);
141 break;
142
144 $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL);
145 break;
146
147 case self::FORM_GROUP:
148 $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL, self::SETTINGS_COURSE);
149 break;
150
151 case self::FORM_WSP:
152 $types = array(self::SETTINGS_PORTFOLIO);
153 break;
154
156 $types = array(self::SETTINGS_LP_COMPLETION_STATUS);
157 break;
158
159 case self::FORM_PRG:
160 $types = array(self::SETTINGS_PRIVACY_SECURITY);
161 break;
162
163 default:
164 $types = null;
165 break;
166 }
167
168 if (is_array($types)) {
169 foreach ($types as $type) {
170 $gui = self::getSettingsGUIInstance($type);
171 if ($gui && method_exists($gui, "addToExternalSettingsForm")) {
172 $data = $gui->addToExternalSettingsForm($a_form_id);
173 if (is_array($data)) {
174 self::parseFieldDefinition($type, $a_form, $gui, $data);
175 }
176 }
177 }
178 }
179
180 // cron jobs - special handling
181
182 $gui = ilObjCronGUI::create();
183 $data = $gui->addToExternalSettingsForm($a_form_id);
184 if ($data !== []) {
185 self::parseFieldDefinition("cron", $a_form, $gui, $data);
186 }
187 }
188
193 protected static function parseFieldValue(
194 ?string $a_field_type,
195 &$a_field_value
196 ) {
197 global $DIC;
198
199 $lng = $DIC->language();
200
201 switch ($a_field_type) {
202 case self::VALUE_BOOL:
203 $a_field_value = $a_field_value ?
204 $lng->txt("enabled") :
205 $lng->txt("disabled");
206 return $a_field_value;
207 }
208
209 if (!is_numeric($a_field_value) &&
210 $a_field_value !== null && !trim($a_field_value)) {
211 $a_field_value = "-";
212 }
213
214 return is_numeric($a_field_value) || $a_field_value !== "";
215 }
216
217 protected static function parseFieldDefinition(
218 string $a_type,
219 ilPropertyFormGUI $a_form,
220 ilObjectGUI $a_gui,
221 $a_data
222 ): void {
224 global $DIC;
225
226 $request = new \ILIAS\Administration\AdminGUIRequest(
227 $DIC->http(),
228 $DIC->refinery()
229 );
230
231
232 $lng = $DIC->language();
233 $rbacsystem = $DIC->rbac()->system();
234 $ilCtrl = $DIC->ctrl();
235 $ilAccess = $DIC->access();
236
237 if (!is_array($a_data)) {
238 return;
239 }
240
241 ilLoggerFactory::getLogger('root')->dump($a_data, ilLogLevel::ERROR);
242
243 // write permission for current gui?
244 $has_write = $ilAccess->checkAccess(
245 "write",
246 "",
247 $request->getRefId()
248 );
249
250 foreach ($a_data as $area_caption => $fields) {
251 if (is_numeric($area_caption) || !trim($area_caption)) {
252 $area_caption = "obj_" . $a_type;
253 }
254
255 if (is_array($fields) && count($fields) === 2) {
256 $cmd = $fields[0];
257 $fields = $fields[1];
258 if (is_array($fields)) {
259 $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "components/ILIAS/Administration");
260
261
262 $stack = array();
263 foreach ($fields as $field_caption_id => $field_value) {
264 ilLoggerFactory::getLogger('root')->dump($field_caption_id, ilLogLevel::ERROR);
265 ilLoggerFactory::getLogger('root')->dump($field_value, ilLogLevel::ERROR);
266 $field_type = $subitems = null;
267 if (is_array($field_value)) {
268 $field_type = $field_value[1];
269 $subitems = $field_value[2] ?? [];
270 $field_value = $field_value[0];
271 }
272
273 if (self::parseFieldValue($field_type, $field_value)) {
274 $ftpl->setCurrentBlock("value_bl");
275 $ftpl->setVariable("VALUE", $field_value);
276 $ftpl->parseCurrentBlock();
277 }
278
279 if (is_array($subitems)) {
280 $ftpl->setCurrentBlock("subitem_bl");
281 foreach ($subitems as $sub_caption_id => $sub_value) {
282 $sub_type = null;
283 if (is_array($sub_value)) {
284 $sub_type = $sub_value[1];
285 $sub_value = $sub_value[0];
286 }
287 self::parseFieldValue($sub_type, $sub_value);
288
289 $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
290 $ftpl->setVariable("SUBVALUE", $sub_value);
291 $ftpl->parseCurrentBlock();
292 }
293 }
294
295 $ftpl->setCurrentBlock("row_bl");
296 $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
297 $ftpl->parseCurrentBlock();
298 }
299
300 if ($has_write &&
301 $rbacsystem->checkAccess("read", $a_gui->getObject()->getRefId())) {
302 if (!$cmd) {
303 $cmd = "view";
304 }
305 $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->getObject()->getRefId());
306
307 $ftpl->setCurrentBlock("edit_bl");
308 $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass([ilAdministrationGUI::class, $a_gui::class], $cmd));
309 $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
310 $ftpl->parseCurrentBlock();
311 }
312
313 $ext = new ilCustomInputGUI($lng->txt($area_caption));
314 $ext->setHtml($ftpl->get());
315 $a_form->addItem($ext);
316 }
317 }
318 }
319 }
320}
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static parseFieldValue(?string $a_field_type, &$a_field_value)
This class represents a custom property in a property form.
static getLogger(string $a_component_id)
Get component logger.
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
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26