ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailOptionsFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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,
35  ?AutoresponderRepository $auto_responder_repository = null
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->maySeeIndividualTransportSettings()) {
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  $cb = new ilCheckboxInputGUI(
102  $this->lng->txt('cron_mail_notification'),
103  'cronjob_notification'
104  );
105  $cb->setInfo($this->lng->txt('mail_cronjob_notification_info'));
106  $cb->setValue('1');
107  $this->addItem($cb);
108  }
109 
110  $this->addCommandButton($this->positive_command, $this->lng->txt('save'));
111  }
112 
113  public function save(): bool
114  {
115  if (!$this->checkInput()) {
116  return false;
117  }
118 
119  if ($this->options->mayModifyIndividualTransportSettings()) {
120  $incoming_type = (int) $this->getInput('incoming_type');
121 
122  $mail_address_option = $this->options->getEmailAddressMode();
123  switch ($incoming_type) {
125  $mail_address_option = (int) $this->getInput('mail_address_option');
126  break;
127 
129  $mail_address_option = (int) $this->getInput('mail_address_option_both');
130  break;
131  }
132  } else {
133  $incoming_type = $this->options->getIncomingType();
134  $mail_address_option = $this->options->getEmailAddressMode();
135  }
136 
137  $absence_duration = $this->getItemByPostVar('absence_duration');
138  $absence_status = (bool) $this->getInput('absence_status');
139  $old_absence_status = $this->options->getAbsenceStatus();
140  if (!$absence_status && $old_absence_status) {
141  $this->auto_responder_repository->deleteBySenderId($this->user->getId());
142  }
143  $this->options->setAbsenceStatus((bool) $this->getInput('absence_status'));
144  if ($absence_duration && $absence_duration->getStart() && $absence_duration->getEnd()) {
145  $this->options->setAbsentFrom($absence_duration->getStart()->get(IL_CAL_UNIX));
146  $this->options->setAbsentUntil($absence_duration->getEnd()->get(IL_CAL_UNIX));
147  }
148  $this->options->setAbsenceAutoresponderSubject($this->getInput('absence_auto_responder_subject'));
149  $this->options->setAbsenceAutoresponderBody($this->getInput('absence_auto_responder_body'));
150 
151  $this->options->setSignature($this->getInput('signature'));
152  $this->options->setIsCronJobNotificationStatus((bool) $this->getInput('cronjob_notification'));
153  $this->options->setIncomingType($incoming_type);
154  $this->options->setEmailAddressmode($mail_address_option);
155 
156  $this->options->updateOptions();
157 
158  return true;
159  }
160 
161  public function populate(): void
162  {
163  $data = [
164  'signature' => $this->options->getSignature(),
165  'cronjob_notification' => $this->options->isCronJobNotificationEnabled(),
166  'absence_status' => $this->options->getAbsenceStatus(),
167  'absence_duration' => [
168  'start' => (new ilDateTime(($this->options->getAbsentFrom() ?: time()), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
169  'end' => (new ilDateTime(($this->options->getAbsentUntil() ?: $this->default_auto_responder_absence_end_ts), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
170  ],
171  'absence_auto_responder_subject' => $this->options->getAbsenceAutoresponderSubject(),
172  'absence_auto_responder_body' => $this->options->getAbsenceAutoresponderBody(),
173  ];
174 
175  if ($this->options->maySeeIndividualTransportSettings()) {
176  $data['incoming_type'] = $this->options->getIncomingType();
177 
178  $mail_address_option = $this->options->getEmailAddressMode();
179 
180  $data['mail_address_option'] = $mail_address_option;
181  $data['mail_address_option_both'] = $mail_address_option;
182  }
183 
184  $this->setValuesByArray($data);
185  }
186 }
final const int INCOMING_BOTH
const IL_CAL_DATETIME
getItemByPostVar(string $a_post_var)
__construct(protected ilMailOptions $options, object $parent_gui, protected string $positive_command, ?AutoresponderRepository $auto_responder_repository=null)
readonly int $default_auto_responder_absence_end_ts
final const int INCOMING_EMAIL
const IL_CAL_UNIX
$duration
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-...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
AutoResponderRepository $auto_responder_repository
setFormAction(string $a_formaction)
global $DIC
Definition: shib_login.php:26
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.