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