ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailOptionsFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
26{
28 protected object $parent_gui;
29 protected AutoResponderRepository $auto_responder_repository;
30
31 public function __construct(
32 protected ilMailOptions $options,
33 object $parent_gui,
34 protected string $positive_command,
36 ) {
37 if (!method_exists($parent_gui, 'executeCommand')) {
38 throw new InvalidArgumentException(sprintf(
39 'Parameter $parent_gui must be ilCtrlInterface enabled by implementing executeCommand(), %s given.',
40 $parent_gui::class
41 ));
42 }
43
45 global $DIC;
46 $this->parent_gui = $parent_gui;
47 $this->positive_command = $positive_command;
48 $this->auto_responder_repository = $auto_responder_repository ?? new AutoresponderDatabaseRepository($DIC->database());
49 $this->default_auto_responder_absence_end_ts = time() + 8640;
50
51 $this->init();
52 }
53
54 protected function init(): void
55 {
56 $this->setTitle($this->lng->txt('mail_settings'));
57 $this->setFormAction($this->ctrl->getFormAction($this->parent_gui, $this->positive_command));
58
59 if ($this->options->mayModifyIndividualTransportSetting()) {
60 $incoming_mail_gui = new ilIncomingMailInputGUI(
61 $this->lng->txt('mail_incoming'),
62 'incoming_type',
63 false
64 );
65 $this->addItem($incoming_mail_gui);
66 }
67
68 $absence = new ilCheckboxInputGUI($this->lng->txt('mail_absence_status'), 'absence_status');
69 $absence->setInfo($this->lng->txt('mail_absence_status_info'));
70 $absence->setValue("1");
71 $this->lng->loadLanguageModule('dateplaner');
72 $duration = new ilDateDurationInputGUI($this->lng->txt('mail_absence_duration'), 'absence_duration');
73 $duration->setRequired(true);
74 $duration->setStartText($this->lng->txt('mail_absent_from'));
75 $duration->setEndText($this->lng->txt('mail_absent_until'));
76 $duration->setShowTime(true);
77 $auto_responder_subject = new ilTextInputGUI($this->lng->txt('mail_absence_auto_responder_subject'), 'absence_auto_responder_subject');
78 $auto_responder_subject->setMaxLength(200);
79 $auto_responder_subject->setRequired(true);
80 $auto_responder_body = new ilTextAreaInputGUI($this->lng->txt('mail_absence_auto_responder_body'), 'absence_auto_responder_body');
81 $idle_time = (int) $this->settings->get('mail_auto_responder_idle_time', (string) AutoresponderService::AUTO_RESPONDER_DEFAULT_IDLE_TIME);
82 if ($idle_time === 1) {
83 $auto_responder_body->setInfo($this->lng->txt('mail_absence_auto_responder_body_info_single_day'));
84 } else {
85 $auto_responder_body->setInfo(sprintf($this->lng->txt('mail_absence_auto_responder_body_info'), $idle_time));
86 }
87 $auto_responder_body->setRequired(true);
88 $auto_responder_body->setCols(60);
89 $auto_responder_body->setRows(10);
90 $absence->addSubItem($duration);
91 $absence->addSubItem($auto_responder_subject);
92 $absence->addSubItem($auto_responder_body);
93 $this->addItem($absence);
94
95 $ta = new ilTextAreaInputGUI($this->lng->txt('signature'), 'signature');
96 $ta->setRows(10);
97 $ta->setCols(60);
98 $this->addItem($ta);
99
100 if ($this->settings->get('mail_notification', '0')
101 && $this->options->mayModifyNewMailNotificationSetting()) {
102 $cb = new ilCheckboxInputGUI(
103 $this->lng->txt('cron_mail_notification'),
104 'cronjob_notification'
105 );
106 $cb->setInfo($this->lng->txt('mail_cronjob_notification_info'));
107 $cb->setValue('1');
108 $this->addItem($cb);
109 }
110
111 $this->addCommandButton($this->positive_command, $this->lng->txt('save'));
112 }
113
114 public function save(): bool
115 {
116 if (!$this->checkInput()) {
117 return false;
118 }
119
120 if ($this->options->mayModifyIndividualTransportSetting()) {
121 $incoming_type = (int) $this->getInput('incoming_type');
122
123 $mail_address_option = $this->options->getEmailAddressMode();
124 switch ($incoming_type) {
126 $mail_address_option = (int) $this->getInput('mail_address_option');
127 break;
128
130 $mail_address_option = (int) $this->getInput('mail_address_option_both');
131 break;
132 }
133 } else {
134 $incoming_type = $this->options->getIncomingType();
135 $mail_address_option = $this->options->getEmailAddressMode();
136 }
137
138 if ($this->options->mayModifyNewMailNotificationSetting()) {
139 $cronjob_notification_status = (bool) $this->getInput('cronjob_notification');
140 } else {
141 $cronjob_notification_status = $this->options->isCronJobNotificationEnabled();
142 }
143
144 $absence_duration = $this->getItemByPostVar('absence_duration');
145 $absence_status = (bool) $this->getInput('absence_status');
146 $old_absence_status = $this->options->getAbsenceStatus();
147 if (!$absence_status && $old_absence_status) {
148 $this->auto_responder_repository->deleteBySenderId($this->user->getId());
149 }
150 $this->options->setAbsenceStatus((bool) $this->getInput('absence_status'));
151 if ($absence_duration && $absence_duration->getStart() && $absence_duration->getEnd()) {
152 $this->options->setAbsentFrom($absence_duration->getStart()->get(IL_CAL_UNIX));
153 $this->options->setAbsentUntil($absence_duration->getEnd()->get(IL_CAL_UNIX));
154 }
155 $this->options->setAbsenceAutoresponderSubject($this->getInput('absence_auto_responder_subject'));
156 $this->options->setAbsenceAutoresponderBody($this->getInput('absence_auto_responder_body'));
157
158 $this->options->setSignature($this->getInput('signature'));
159 $this->options->setIsCronJobNotificationStatus($cronjob_notification_status);
160 $this->options->setIncomingType($incoming_type);
161 $this->options->setEmailAddressmode($mail_address_option);
162
163 $this->options->updateOptions();
164
165 return true;
166 }
167
168 public function populate(): void
169 {
170 $data = [
171 'signature' => $this->options->getSignature(),
172 'absence_status' => $this->options->getAbsenceStatus(),
173 'absence_duration' => [
174 'start' => (new ilDateTime(($this->options->getAbsentFrom() ?: time()), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
175 'end' => (new ilDateTime(($this->options->getAbsentUntil() ?: $this->default_auto_responder_absence_end_ts), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
176 ],
177 'absence_auto_responder_subject' => $this->options->getAbsenceAutoresponderSubject(),
178 'absence_auto_responder_body' => $this->options->getAbsenceAutoresponderBody(),
179 ];
180
181 if ($this->options->mayModifyIndividualTransportSetting()) {
182 $data['incoming_type'] = $this->options->getIncomingType();
183
184 $mail_address_option = $this->options->getEmailAddressMode();
185
186 $data['mail_address_option'] = $mail_address_option;
187 $data['mail_address_option_both'] = $mail_address_option;
188 }
189
190 if ($this->options->mayModifyNewMailNotificationSetting()) {
191 $data['cronjob_notification'] = $this->options->isCronJobNotificationEnabled();
192 }
193
194 $this->setValuesByArray($data);
195 }
196}
$duration
const IL_CAL_UNIX
const IL_CAL_DATETIME
This class represents a checkbox property in a property form.
input GUI for a time span (start and end date)
@classDescription Date and time handling
setFormAction(string $a_formaction)
readonly int $default_auto_responder_absence_end_ts
AutoResponderRepository $auto_responder_repository
__construct(protected ilMailOptions $options, object $parent_gui, protected string $positive_command, ?AutoresponderRepository $auto_responder_repository=null)
final const int INCOMING_BOTH
final const int INCOMING_EMAIL
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a text area property in a property form.
This class represents a text property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26