ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilIncomingMailInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected bool $free_option_choice = true;
24  protected bool $options_initialized = false;
25 
26  public function __construct(string $title = '', string $post_var = '', bool $free_option_choice = true)
27  {
28  parent::__construct($title, $post_var);
29  $this->setFreeOptionChoice($free_option_choice);
30  }
31 
32  protected function initializeOptions(): void
33  {
34  if (!$this->options_initialized) {
35  $this->addSubOptions();
36  $this->options_initialized = true;
37  }
38  }
39 
40  public function getOptions(): array
41  {
42  $this->initializeOptions();
43  return parent::getOptions();
44  }
45 
46  public function setValueByArray($a_values): void
47  {
48  $this->initializeOptions();
49  parent::setValueByArray($a_values);
50  }
51 
52  public function checkInput(): bool
53  {
54  $this->initializeOptions();
55  return parent::checkInput();
56  }
57 
58  public function render(): string
59  {
60  $this->initializeOptions();
61  return parent::render();
62  }
63 
64  public function getItemByPostVar(string $a_post_var): ?ilFormPropertyGUI
65  {
66  $this->initializeOptions();
67  return parent::getItemByPostVar($a_post_var);
68  }
69 
70  public function getSubInputItemsRecursive(): array
71  {
72  $this->initializeOptions();
73  return parent::getSubInputItemsRecursive();
74  }
75 
76  public function isFreeOptionChoice(): bool
77  {
79  }
80 
81  public function setFreeOptionChoice(bool $free_option_choice): void
82  {
83  $this->free_option_choice = $free_option_choice;
84  }
85 
86  private function addSubOptions(): void
87  {
88  global $DIC;
89 
90  $incoming_local = new ilRadioOption(
91  $DIC->language()->txt('mail_incoming_local'),
93  );
94  $incoming_local->setDisabled($this->getDisabled());
95 
96  $incoming_external = new ilRadioOption(
97  $DIC->language()->txt('mail_incoming_smtp'),
99  );
100  $incoming_external->setDisabled($this->getDisabled());
101 
102  $incoming_both = new ilRadioOption(
103  $DIC->language()->txt('mail_incoming_both'),
105  );
106  $incoming_both->setDisabled($this->getDisabled());
107 
108  $this->addOption($incoming_local);
109  $this->addOption($incoming_external);
110  $this->addOption($incoming_both);
111 
112  $incoming_external_address_choice = new ilRadioGroupInputGUI('', 'mail_address_option');
113  $incoming_external_address_choice->setDisabled($this->getDisabled());
114 
115  $sub_mail_opt1 = new ilRadioOption(
116  $DIC->language()->txt('mail_first_email'),
118  );
119  $sub_mail_opt1->setDisabled($this->getDisabled());
120 
121  $sub_mail_opt2 = new ilRadioOption(
122  $DIC->language()->txt('mail_second_email'),
124  );
125  $sub_mail_opt2->setDisabled($this->getDisabled());
126  $sub_mail_opt3 = new ilRadioOption(
127  $DIC->language()->txt('mail_both_email'),
129  );
130  $sub_mail_opt3->setDisabled($this->getDisabled());
131 
132  $incoming_both_address_choice = new ilRadioGroupInputGUI('', 'mail_address_option_both');
133  $incoming_both_address_choice->setDisabled($this->getDisabled());
134  $sub_both_opt1 = new ilRadioOption(
135  $DIC->language()->txt('mail_first_email'),
137  );
138  $sub_both_opt1->setDisabled($this->getDisabled());
139 
140  $sub_both_opt2 = new ilRadioOption(
141  $DIC->language()->txt('mail_second_email'),
143  );
144  $sub_both_opt2->setDisabled($this->getDisabled());
145  $sub_both_opt3 = new ilRadioOption(
146  $DIC->language()->txt('mail_both_email'),
148  );
149  $sub_both_opt3->setDisabled($this->getDisabled());
150  if ($this->isFreeOptionChoice()) {
151  $incoming_external_address_choice->addOption($sub_mail_opt1);
152  $incoming_external_address_choice->addOption($sub_mail_opt2);
153  $incoming_external_address_choice->addOption($sub_mail_opt3);
154  $incoming_both_address_choice->addOption($sub_both_opt1);
155  $incoming_both_address_choice->addOption($sub_both_opt2);
156  $incoming_both_address_choice->addOption($sub_both_opt3);
157 
158  $incoming_external->addSubItem($incoming_external_address_choice);
159  $incoming_both->addSubItem($incoming_both_address_choice);
160  } else {
161  $email_info = [];
162  if (
163  $DIC->settings()->get('usr_settings_disable_mail_incoming_mail') === '1') {
164  $this->setDisabled(true);
165  }
166 
167  if ($DIC->user()->getEmail() === '') {
168  $sub_mail_opt1->setInfo($DIC->language()->txt('first_email_missing_info'));
169  $sub_mail_opt3->setInfo($DIC->language()->txt('first_email_missing_info'));
170  $sub_both_opt1->setInfo($DIC->language()->txt('first_email_missing_info'));
171  $sub_both_opt3->setInfo($DIC->language()->txt('first_email_missing_info'));
172  } else {
173  $email_info[] = $DIC->user()->getEmail();
174  }
175  if ($DIC->settings()->get('usr_settings_disable_mail_incoming_mail') === '1') {
176  $sub_mail_opt1->setDisabled(true);
177  $sub_mail_opt3->setDisabled(true);
178  $sub_both_opt1->setDisabled(true);
179  $sub_both_opt3->setDisabled(true);
180  }
181 
182  if ($DIC->user()->getSecondEmail() === '') {
183  $sub_mail_opt2->setInfo($DIC->language()->txt('second_email_missing_info'));
184  $sub_mail_opt3->setInfo($DIC->language()->txt('second_email_missing_info'));
185  $sub_both_opt2->setInfo($DIC->language()->txt('second_email_missing_info'));
186  $sub_both_opt3->setInfo($DIC->language()->txt('second_email_missing_info'));
187  } else {
188  $email_info[] = $DIC->user()->getSecondEmail();
189  }
190  if ($DIC->settings()->get('usr_settings_disable_mail_incoming_mail') === '1') {
191  $sub_mail_opt2->setDisabled(true);
192  $sub_mail_opt3->setDisabled(true);
193  $sub_both_opt2->setDisabled(true);
194  $sub_both_opt3->setDisabled(true);
195  }
196 
197  if (count($email_info) > 1) {
198  $sub_mail_opt1->setInfo($email_info[0]);
199  $sub_both_opt1->setInfo($email_info[0]);
200  $sub_mail_opt2->setInfo($email_info[1]);
201  $sub_both_opt2->setInfo($email_info[1]);
202  $sub_mail_opt3->setInfo(implode(', ', $email_info));
203  $sub_both_opt3->setInfo(implode(', ', $email_info));
204  }
205 
206  if (count($email_info) === 1) {
207  $incoming_external->setInfo($email_info[0]);
208  $incoming_both->setInfo($email_info[0]);
209  } else {
210  $incoming_external_address_choice->addOption($sub_mail_opt1);
211  $incoming_external_address_choice->addOption($sub_mail_opt2);
212  $incoming_external_address_choice->addOption($sub_mail_opt3);
213 
214  $incoming_both_address_choice->addOption($sub_both_opt1);
215  $incoming_both_address_choice->addOption($sub_both_opt2);
216  $incoming_both_address_choice->addOption($sub_both_opt3);
217 
218  $incoming_external->addSubItem($incoming_external_address_choice);
219  $incoming_both->addSubItem($incoming_both_address_choice);
220  }
221  }
222  }
223 }
This class represents an option in a radio group.
final const int SECOND_EMAIL
final const int INCOMING_BOTH
final const int INCOMING_LOCAL
final const int INCOMING_EMAIL
addOption(ilRadioOption $a_option)
setFreeOptionChoice(bool $free_option_choice)
This class represents a property in a property form.
global $DIC
Definition: shib_login.php:26
__construct(string $title='', string $post_var='', bool $free_option_choice=true)
final const int BOTH_EMAIL
__construct(Container $dic, ilPlugin $plugin)
setDisabled(bool $a_disabled)
final const int FIRST_EMAIL