ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilUserProfileInfoSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 
17 {
21  protected $ctrl;
22 
26  protected $tpl;
27 
31  protected $lng;
32 
36  protected $user_prompt;
37 
41  protected $prompt_settings;
42 
46  public function __construct()
47  {
48  global $DIC;
49 
50  $this->ctrl = $DIC->ctrl();
51  $this->tpl = $DIC["tpl"];
52  $this->lng = $DIC->language();
53  $this->user_prompt = new ilUserProfilePromptService();
54  $this->prompt_settings = $this->user_prompt->data()->getSettings();
55  }
56 
57 
61  public function executeCommand()
62  {
63  $next_class = $this->ctrl->getNextClass($this);
64  $cmd = $this->ctrl->getCmd("show");
65 
66  switch ($next_class) {
67  default:
68  if (in_array($cmd, array("show", "save"))) {
69  $this->$cmd();
70  }
71  }
72  }
73 
77  public function show()
78  {
79  $tpl = $this->tpl;
80 
81  $form = $this->initForm();
82  $tpl->setContent($form->getHTML());
83  }
84 
89  public function initForm()
90  {
91  $lng = $this->lng;
94 
95  $lng->loadLanguageModule("meta");
96 
97  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
98  $form = new ilPropertyFormGUI();
99 
100  // default info text
101  $first = true;
102  foreach ($lng->getInstalledLanguages() as $l) {
103  // info text
104  include_once("Services/Form/classes/class.ilTextAreaInputGUI.php");
105  $ti = new ilTextAreaInputGUI($lng->txt("meta_l_" . $l), "user_profile_info_text_" . $l);
106  $ti->setRows(7);
107  if ($first) {
108  $ti->setInfo($lng->txt("user_profile_info_text_info"));
109  }
110  $first = false;
111  $ti->setValue($prompt_settings->getInfoText($l));
112  $form->addItem($ti);
113  }
114 
115  // prompting settings
116  $sec = new ilFormSectionHeaderGUI();
117  $sec->setTitle($lng->txt('user_prompting_settings'));
118  $form->addItem($sec);
119 
120  // prompt mode
121  $radg = new ilRadioGroupInputGUI($lng->txt("user_prompting_recurrence"), "prompt_mode");
122  $radg->setValue($prompt_settings->getMode());
123 
124  // ... only if incomplete
125  $op1 = new ilRadioOption(
126  $lng->txt("user_prompt_incomplete"),
128  $lng->txt("user_prompt_incomplete_info")
129  );
130  $radg->addOption($op1);
131 
132  // ... once after login
133  $op2 = new ilRadioOption(
134  $lng->txt("user_prompt_once_after_login"),
136  $lng->txt("user_prompt_once_after_login_info")
137  );
138  $radg->addOption($op2);
139 
140  // days after login
141  $ti = new ilNumberInputGUI($lng->txt("days"), "days_after_login");
142  $ti->setMaxLength(4);
143  $ti->setSize(4);
144  $ti->setValue($prompt_settings->getDays());
145  $op2->addSubItem($ti);
146 
147  // ... repeatly
148  $op3 = new ilRadioOption(
149  $lng->txt("user_prompt_repeat"),
151  $lng->txt("user_prompt_repeat_info")
152  );
153  $radg->addOption($op3);
154 
155  // repeat all x days
156  $ti = new ilNumberInputGUI($lng->txt("days"), "days_repeat");
157  $ti->setMaxLength(4);
158  $ti->setSize(4);
159  $ti->setValue($prompt_settings->getDays());
160  $op3->addSubItem($ti);
161 
162  $form->addItem($radg);
163 
164 
165  // prompting info text
166  $first = true;
167  foreach ($lng->getInstalledLanguages() as $l) {
168  // info text
169  include_once("Services/Form/classes/class.ilTextAreaInputGUI.php");
170  $ti = new ilTextAreaInputGUI($lng->txt("meta_l_" . $l), "user_profile_prompt_text_" . $l);
171  $ti->setRows(7);
172  if ($first) {
173  $ti->setInfo($lng->txt("user_profile_prompt_text_info"));
174  }
175  $first = false;
176  $ti->setValue($prompt_settings->getPromptText($l));
177  $form->addItem($ti);
178  }
179 
180  $form->addCommandButton("save", $lng->txt("save"));
181 
182  $form->setTitle($lng->txt("user_profile_info_std"));
183  $form->setFormAction($ctrl->getFormAction($this));
184 
185  return $form;
186  }
187 
191  public function save()
192  {
193  $lng = $this->lng;
194  $ctrl = $this->ctrl;
195  $tpl = $this->tpl;
196 
197  $form = $this->initForm();
198  if ($form->checkInput()) {
199  $days = ($form->getInput("prompt_mode") == ilProfilePromptSettings::MODE_ONCE_AFTER_LOGIN)
200  ? $form->getInput("days_after_login")
201  : $form->getInput("days_repeat");
202  $info_text = $prompt_text = [];
203  foreach ($lng->getInstalledLanguages() as $l) {
204  $info_text[$l] = $form->getInput("user_profile_info_text_" . $l);
205  $prompt_text[$l] = $form->getInput("user_profile_prompt_text_" . $l);
206  }
207  $this->user_prompt->data()->saveSettings($this->user_prompt->settings(
208  $form->getInput("prompt_mode"),
209  $days,
210  $info_text,
211  $prompt_text
212  ));
213  /*$setting = new ilSetting("user");
214  foreach ($lng->getInstalledLanguages() as $l)
215  {
216  $setting->set("user_profile_info_".$l, $form->getInput("user_profile_info_text_".$l));
217  }*/
218 
219  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
220  $ctrl->redirect($this, "show");
221  } else {
222  $form->setValuesByPost();
223  $tpl->setContent($form->getHtml());
224  }
225  }
226 }
This class represents an option in a radio group.
This class represents a property form user interface.
User profile prompt subservice.
global $DIC
Definition: saml.php:7
This class represents a section header in a property form.
User profile info settings UI class.
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
This class represents a number property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
global $l
Definition: afr.php:30
This class represents a text area property in a property form.