ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilUserFieldSettingsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  private bool $confirm_change = false;
30 
32 
33  public function __construct(
34  object $a_parent_obj,
35  string $a_parent_cmd
36  ) {
37  global $DIC;
38 
39  $ilCtrl = $DIC['ilCtrl'];
40  $lng = $DIC['lng'];
41 
42  $this->user_settings_config = new ilUserSettingsConfig();
43 
44  parent::__construct($a_parent_obj, $a_parent_cmd);
45  $this->setTitle($lng->txt("usr_settings_header_profile"));
46  $this->main_tpl->setOnScreenMessage('info', $lng->txt('usr_settings_explanation_profile'));
47  $this->setLimit(9999);
48 
49  //$this->addColumn($this->lng->txt("usrs_group"), "");
50  //$this->addColumn("", "");
51  $this->addColumn($this->lng->txt("user_field"), "");
52  $this->addColumn($this->lng->txt("access"), "");
53  $this->addColumn($this->lng->txt("export") . " / " . $this->lng->txt("search"), "");
54  $this->addColumn($this->lng->txt("default"), "");
55 
56  $this->setEnableHeader(true);
57  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
58  $this->setRowTemplate("tpl.std_fields_settings_row.html", "components/ILIAS/User");
59  $this->disable("footer");
60  $this->setEnableTitle(true);
61 
62  $up = new ilUserProfile();
63  $up->skipField("username");
64  $fds = $up->getStandardFields();
65  foreach ($fds as $k => $f) {
66  $fds[$k]["key"] = $k;
67  }
68  $this->setData($fds);
69  $this->addCommandButton("saveGlobalUserSettings", $lng->txt("save"));
70 
71  $this->user_request = new UserGUIRequest(
72  $DIC->http(),
73  $DIC->refinery()
74  );
75  }
76 
81  protected function fillRow(array $a_set): void
82  {
83  global $DIC;
84 
85  $lng = $DIC['lng'];
86  $ilSetting = $DIC['ilSetting'];
87  $user_settings_config = $this->user_settings_config;
88  $req_checked = $this->user_request->getChecked();
89 
90  $field = $a_set["key"];
91 
92  foreach (ilObjUserFolderGUI::USER_FIELD_TRANSLATION_MAPPING as $prop => $lv) {
93  $up_prop = strtoupper($prop);
94 
95  if (($prop != "searchable" && ($a_set[$prop . "_hide"] ?? false) != true) ||
96  ($prop == "searchable" && ilUserSearchOptions::_isSearchable($field))) {
97  $this->tpl->setCurrentBlock($prop);
98  $this->tpl->setVariable(
99  "HEADER_" . $up_prop,
100  $lng->txt($lv)
101  );
102  $this->tpl->setVariable("PROFILE_OPTION_" . $up_prop, $prop . "_" . $field);
103 
104  // determine checked status
105  $checked = false;
106  if ($prop === "visible" && $user_settings_config->isVisible($field)) {
107  $checked = true;
108  }
109  if ($prop === "changeable" && $user_settings_config->isChangeable($field)) {
110  $checked = true;
111  }
112  if ($prop === "searchable" && ilUserSearchOptions::_isEnabled($field)) {
113  $checked = true;
114  }
115  if ($prop === "required" && $ilSetting->get("require_" . $field) == "1") {
116  $checked = true;
117  }
118  if ($prop === "export" && $ilSetting->get("usr_settings_export_" . $field) == "1") {
119  $checked = true;
120  }
121  if ($prop === "course_export" && $ilSetting->get("usr_settings_course_export_" . $field) == "1") {
122  $checked = true;
123  }
124  if ($prop === "group_export" && $ilSetting->get("usr_settings_group_export_" . $field) == "1") {
125  $checked = true;
126  }
127  if ($prop === "visib_reg" && (int) $ilSetting->get('usr_settings_visib_reg_' . $field, '1')) {
128  $checked = true;
129  }
130  if ($prop === "visib_lua" && (int) $ilSetting->get('usr_settings_visib_lua_' . $field, '1')) {
131  $checked = true;
132  }
133  if ($prop === "changeable_lua" && (int) $ilSetting->get('usr_settings_changeable_lua_' . $field, '1')) {
134  $checked = true;
135  }
136  if ($prop === "prg_export" && $ilSetting->get("usr_settings_prg_export_" . $field) === "1") {
137  $checked = true;
138  }
139 
140  if ($this->confirm_change == 1) { // confirm value
141  $checked = $req_checked[$prop . "_" . $field] ?? false;
142  }
143  if (isset($a_set[$prop . "_fix_value"])) { // fix values overwrite everything
144  $checked = $a_set[$prop . "_fix_value"];
145  }
146 
147  if ($checked) {
148  $this->tpl->setVariable("CHECKED_" . $up_prop, " checked=\"checked\"");
149  if (!isset($a_set["{$prop}_fix_value"])) {
150  $this->tpl->setVariable("CURRENT_OPTION_VISIBLE", "1");
151  }
152  } else {
153  $this->tpl->setVariable("CURRENT_OPTION_VISIBLE", "0");
154  }
155 
156  if (isset($a_set[$prop . "_fix_value"])) {
157  $this->tpl->setVariable("DISABLE_" . $up_prop, " disabled=\"disabled\"");
158  }
159  $this->tpl->parseCurrentBlock();
160  }
161  }
162 
163  // default
164  if (($a_set["default"] ?? "") != "") {
165  switch ($a_set["input"]) {
166  case "selection":
167  $selected_option = $ilSetting->get($field);
168  if ($selected_option == "") {
169  $selected_option = $a_set["default"];
170  }
171  foreach ($a_set["options"] as $k => $v) {
172  $this->tpl->setCurrentBlock("def_sel_option");
173  $this->tpl->setVariable("OPTION_VALUE", $k);
174  $text = ($a_set["input"] == "selection")
175  ? $lng->txt($v)
176  : $v;
177  if ($selected_option == $k) {
178  $this->tpl->setVariable(
179  "OPTION_SELECTED",
180  ' selected="selected" '
181  );
182  }
183  $this->tpl->setVariable("OPTION_TEXT", $text);
184  $this->tpl->parseCurrentBlock();
185  }
186  $this->tpl->setCurrentBlock("def_selection");
187  $this->tpl->setVariable("PROFILE_OPTION_DEFAULT_VALUE", "default_" . $field);
188  $this->tpl->parseCurrentBlock();
189  break;
190  case 'numeric':
191  $this->tpl->setCurrentBlock('def_input');
192 
193  $this->tpl->setVariable('PROFILE_OPTION_DEFAULT_VALUE', 'default_' . $field);
194  $session_reminder = ilSessionReminder::byLoggedInUser();
195  $this->tpl->setVariable('CURRENT_OPTION_VISIBLE', $session_reminder->getGlobalSessionReminderLeadTime());
196  $this->tpl->setVariable('CURRENT_OPTION_MAXIMUM', $session_reminder->getMaxPossibleLeadTime());
197  $this->tpl->setVariable('CURRENT_OPTION_MINIMUM', ilSessionReminder::LEAD_TIME_DISABLED);
198 
199  $this->tpl->parseCurrentBlock();
200 
201  break;
202  }
203  $this->tpl->setCurrentBlock("default");
204  $this->tpl->parseCurrentBlock();
205  }
206 
207  // group name
208  $this->tpl->setVariable("TXT_GROUP", $lng->txt($a_set["group"]));
209 
210  // field name
211  $lv = (($a_set["lang_var"] ?? "") == "")
212  ? $a_set["key"]
213  : $a_set["lang_var"];
214  if ($a_set["key"] == "country") {
215  $lv = "country_free_text";
216  }
217  if ($a_set["key"] == "sel_country") {
218  $lv = "country_selection";
219  }
220 
221  $this->tpl->setVariable("TXT_FIELD", $lng->txt($lv));
222  }
223 
224  public function setConfirmChange(): void
225  {
226  $this->confirm_change = true;
227  }
228 }
setData(array $a_data)
__construct(object $a_parent_obj, string $a_parent_cmd)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
isVisible(string $field)
Is setting visible to user?
setEnableTitle(bool $a_enabletitle)
static _isSearchable(string $a_key)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
Class ilUserProfile.
isChangeable(string $field)
Is setting changeable by user?
ilLanguage $lng
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:26
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
global $ilSetting
Definition: privfeed.php:31
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
disable(string $a_module_name)
setEnableHeader(bool $a_enableheader)