ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserProfileInfoSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected ilCtrl $ctrl;
28  protected ilLanguage $lng;
31 
32  public function __construct()
33  {
34  global $DIC;
35 
36  $this->ctrl = $DIC->ctrl();
37  $this->tpl = $DIC["tpl"];
38  $this->lng = $DIC->language();
39  $this->user_prompt = new ilUserProfilePromptService();
40  $this->prompt_settings = $this->user_prompt->data()->getSettings();
41  }
42 
43  public function executeCommand(): void
44  {
45  $next_class = $this->ctrl->getNextClass($this);
46  $cmd = $this->ctrl->getCmd("show");
47 
48  switch ($next_class) {
49  default:
50  if (in_array($cmd, array("show", "save"))) {
51  $this->$cmd();
52  }
53  }
54  }
55 
56  public function show(): void
57  {
58  $tpl = $this->tpl;
59 
60  $form = $this->initForm();
61  $tpl->setContent($form->getHTML());
62  }
63 
64  public function initForm(): ilPropertyFormGUI
65  {
66  $lng = $this->lng;
67  $ctrl = $this->ctrl;
68  $prompt_settings = $this->prompt_settings;
69 
70  $lng->loadLanguageModule("meta");
71 
72  $form = new ilPropertyFormGUI();
73 
74  // default info text
75  $first = true;
76  foreach ($lng->getInstalledLanguages() as $l) {
77  // info text
78  $ti = new ilTextAreaInputGUI($lng->txt("meta_l_" . $l), "user_profile_info_text_" . $l);
79  $ti->setRows(7);
80  if ($first) {
81  $ti->setInfo($lng->txt("user_profile_info_text_info"));
82  }
83  $first = false;
84  $ti->setValue($prompt_settings->getInfoText($l));
85  $form->addItem($ti);
86  }
87 
88  // prompting settings
89  $sec = new ilFormSectionHeaderGUI();
90  $sec->setTitle($lng->txt('user_prompting_settings'));
91  $form->addItem($sec);
92 
93  // prompt mode
94  $radg = new ilRadioGroupInputGUI($lng->txt("user_prompting_recurrence"), "prompt_mode");
95  $radg->setValue($prompt_settings->getMode());
96 
97  // ... only if incomplete
98  $op1 = new ilRadioOption(
99  $lng->txt("user_prompt_incomplete"),
101  $lng->txt("user_prompt_incomplete_info")
102  );
103  $radg->addOption($op1);
104 
105  // ... once after login
106  $op2 = new ilRadioOption(
107  $lng->txt("user_prompt_once_after_login"),
109  $lng->txt("user_prompt_once_after_login_info")
110  );
111  $radg->addOption($op2);
112 
113  // days after login
114  $ti = new ilNumberInputGUI($lng->txt("days"), "days_after_login");
115  $ti->setMaxLength(4);
116  $ti->setSize(4);
117  $ti->setValue($prompt_settings->getDays());
118  $op2->addSubItem($ti);
119 
120  // ... repeatly
121  $op3 = new ilRadioOption(
122  $lng->txt("user_prompt_repeat"),
124  $lng->txt("user_prompt_repeat_info")
125  );
126  $radg->addOption($op3);
127 
128  // repeat all x days
129  $ti = new ilNumberInputGUI($lng->txt("days"), "days_repeat");
130  $ti->setMaxLength(4);
131  $ti->setSize(4);
132  $ti->setRequired(true);
133  $ti->setMinValue(1);
134  $ti->setValue($prompt_settings->getDays());
135  $op3->addSubItem($ti);
136 
137  $form->addItem($radg);
138 
139 
140  // prompting info text
141  $first = true;
142  foreach ($lng->getInstalledLanguages() as $l) {
143  // info text
144  $ti = new ilTextAreaInputGUI($lng->txt("meta_l_" . $l), "user_profile_prompt_text_" . $l);
145  $ti->setRows(7);
146  if ($first) {
147  $ti->setInfo($lng->txt("user_profile_prompt_text_info"));
148  }
149  $first = false;
150  $ti->setValue($prompt_settings->getPromptText($l));
151  $form->addItem($ti);
152  }
153 
154  $form->addCommandButton("save", $lng->txt("save"));
155 
156  $form->setTitle($lng->txt("user_profile_info_std"));
157  $form->setFormAction($ctrl->getFormAction($this));
158 
159  return $form;
160  }
161 
162  public function save(): void
163  {
164  $lng = $this->lng;
165  $ctrl = $this->ctrl;
166  $tpl = $this->tpl;
167 
168  $form = $this->initForm();
169  if ($form->checkInput()) {
170  $days = ($form->getInput("prompt_mode") == ilProfilePromptSettings::MODE_ONCE_AFTER_LOGIN)
171  ? $form->getInput("days_after_login")
172  : $form->getInput("days_repeat");
173  $info_text = $prompt_text = [];
174  foreach ($lng->getInstalledLanguages() as $l) {
175  $info_text[$l] = $form->getInput("user_profile_info_text_" . $l);
176  $prompt_text[$l] = $form->getInput("user_profile_prompt_text_" . $l);
177  }
178  $this->user_prompt->data()->saveSettings($this->user_prompt->settings(
179  (int) $form->getInput("prompt_mode"),
180  (int) $days,
181  $info_text,
182  $prompt_text
183  ));
184  /*$setting = new ilSetting("user");
185  foreach ($lng->getInstalledLanguages() as $l)
186  {
187  $setting->set("user_profile_info_".$l, $form->getInput("user_profile_info_text_".$l));
188  }*/
189 
190  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
191  $ctrl->redirect($this, "show");
192  } else {
193  $form->setValuesByPost();
194  $tpl->setContent($form->getHTML());
195  }
196  }
197 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMaxLength(int $a_maxlength)
loadLanguageModule(string $a_module)
Load language module.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This class represents a property in a property form.
setContent(string $a_html)
Sets content for standard template.
This class represents a number property in a property form.
getInstalledLanguages()
Get installed languages.
This class represents a text area property in a property form.
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)