ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $parent_gui = new ilObjSystemFolderGUI(null, SYSTEM_FOLDER_ID, true);
183 $parent_gui->setCreationMode(true);
184
185 $gui = new ilCronManagerGUI();
186 $data = $gui->addToExternalSettingsForm($a_form_id);
187 if (is_array($data) && count($data)) {
188 self::parseFieldDefinition("cron", $a_form, $parent_gui, $data);
189 }
190 }
191
196 protected static function parseFieldValue(
197 ?string $a_field_type,
198 &$a_field_value
199 ) {
200 global $DIC;
201
202 $lng = $DIC->language();
203
204 switch ($a_field_type) {
205 case self::VALUE_BOOL:
206 $a_field_value = $a_field_value ?
207 $lng->txt("enabled") :
208 $lng->txt("disabled");
209 return $a_field_value;
210 }
211
212 if (!is_numeric($a_field_value) &&
213 $a_field_value !== null && !trim($a_field_value)) {
214 $a_field_value = "-";
215 }
216
217 return is_numeric($a_field_value) || $a_field_value !== "";
218 }
219
220 protected static function parseFieldDefinition(
221 string $a_type,
222 ilPropertyFormGUI $a_form,
223 ilObjectGUI $a_gui,
224 $a_data
225 ): void {
227 global $DIC;
228
229 $request = new \ILIAS\Administration\AdminGUIRequest(
230 $DIC->http(),
231 $DIC->refinery()
232 );
233
234
235 $lng = $DIC->language();
236 $rbacsystem = $DIC->rbac()->system();
237 $ilCtrl = $DIC->ctrl();
238 $ilAccess = $DIC->access();
239
240 if (!is_array($a_data)) {
241 return;
242 }
243
244 ilLoggerFactory::getLogger('root')->dump($a_data, ilLogLevel::ERROR);
245
246 // write permission for current gui?
247 $has_write = $ilAccess->checkAccess(
248 "write",
249 "",
250 $request->getRefId()
251 );
252
253 foreach ($a_data as $area_caption => $fields) {
254 if (is_numeric($area_caption) || !trim($area_caption)) {
255 $area_caption = "obj_" . $a_type;
256 }
257
258 if (is_array($fields) && count($fields) === 2) {
259 $cmd = $fields[0];
260 $fields = $fields[1];
261 if (is_array($fields)) {
262 $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "components/ILIAS/Administration");
263
264
265 $stack = array();
266 foreach ($fields as $field_caption_id => $field_value) {
267 ilLoggerFactory::getLogger('root')->dump($field_caption_id, ilLogLevel::ERROR);
268 ilLoggerFactory::getLogger('root')->dump($field_value, ilLogLevel::ERROR);
269 $field_type = $subitems = null;
270 if (is_array($field_value)) {
271 $field_type = $field_value[1];
272 $subitems = $field_value[2] ?? [];
273 $field_value = $field_value[0];
274 }
275
276 if (self::parseFieldValue($field_type, $field_value)) {
277 $ftpl->setCurrentBlock("value_bl");
278 $ftpl->setVariable("VALUE", $field_value);
279 $ftpl->parseCurrentBlock();
280 }
281
282 if (is_array($subitems)) {
283 $ftpl->setCurrentBlock("subitem_bl");
284 foreach ($subitems as $sub_caption_id => $sub_value) {
285 $sub_type = null;
286 if (is_array($sub_value)) {
287 $sub_type = $sub_value[1];
288 $sub_value = $sub_value[0];
289 }
290 self::parseFieldValue($sub_type, $sub_value);
291
292 $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
293 $ftpl->setVariable("SUBVALUE", $sub_value);
294 $ftpl->parseCurrentBlock();
295 }
296 }
297
298 $ftpl->setCurrentBlock("row_bl");
299 $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
300 $ftpl->parseCurrentBlock();
301 }
302
303 if ($has_write &&
304 $rbacsystem->checkAccess("visible,read", $a_gui->getObject()->getRefId())) {
305 if (!$cmd) {
306 $cmd = "view";
307 }
308 $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->getObject()->getRefId());
309
310 $ftpl->setCurrentBlock("edit_bl");
311 $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass(array("ilAdministrationGUI", get_class($a_gui)), $cmd));
312 $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
313 $ftpl->parseCurrentBlock();
314 }
315
316 $ext = new ilCustomInputGUI($lng->txt($area_caption));
317 $ext->setHtml($ftpl->get());
318 $a_form->addItem($ext);
319 }
320 }
321 }
322 }
323}
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static parseFieldValue(?string $a_field_type, &$a_field_value)
@ilCtrl_Calls ilCronManagerGUI: ilPropertyFormGUI @ilCtrl_isCalledBy ilCronManagerGUI: ilAdministrati...
This class represents a custom property in a property form.
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
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26