ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilMailOptionsFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
29 {
31  protected object $parentGui;
32  protected AutoResponderRepository $autoResponderRepository;
33 
34  public function __construct(protected ilMailOptions $options, object $parentGui, protected string $positiveCmd, AutoresponderRepository $autoResponderRepository = null)
35  {
36  if (!method_exists($parentGui, 'executeCommand')) {
37  throw new InvalidArgumentException(sprintf(
38  'Parameter $parentGui must be ilCtrlInterface enabled by implementing executeCommand(), %s given.',
39  $parentGui::class
40  ));
41  }
42 
44  global $DIC;
45  $this->parentGui = $parentGui;
46  $this->positiveCmd = $positiveCmd;
47  $this->autoResponderRepository = $autoResponderRepository ?? new AutoresponderDatabaseRepository($DIC->database());
48  $this->default_auto_responder_absence_end_ts = time() + 8640;
49 
50  $this->init();
51  }
52 
53  protected function init(): void
54  {
55  $this->setTitle($this->lng->txt('mail_settings'));
56  $this->setFormAction($this->ctrl->getFormAction($this->parentGui, $this->positiveCmd));
57 
58  if ($this->options->maySeeIndividualTransportSettings()) {
59  $incoming_mail_gui = new ilIncomingMailInputGUI(
60  $this->lng->txt('mail_incoming'),
61  'incoming_type',
62  false
63  );
64  $this->addItem($incoming_mail_gui);
65  }
66 
67  $absence = new ilCheckboxInputGUI($this->lng->txt('mail_absence_status'), 'absence_status');
68  $absence->setInfo($this->lng->txt('mail_absence_status_info'));
69  $absence->setValue("1");
70  $this->lng->loadLanguageModule('dateplaner');
71  $duration = new ilDateDurationInputGUI($this->lng->txt('mail_absence_duration'), 'absence_duration');
72  $duration->setRequired(true);
73  $duration->setStartText($this->lng->txt('mail_absent_from'));
74  $duration->setEndText($this->lng->txt('mail_absent_until'));
75  $duration->setShowTime(true);
76  $auto_responder_subject = new ilTextInputGUI($this->lng->txt('mail_absence_auto_responder_subject'), 'absence_auto_responder_subject');
77  $auto_responder_subject->setMaxLength(200);
78  $auto_responder_subject->setRequired(true);
79  $auto_responder_body = new ilTextAreaInputGUI($this->lng->txt('mail_absence_auto_responder_body'), 'absence_auto_responder_body');
80  $idle_time = (int) $this->settings->get('mail_auto_responder_idle_time', (string) AutoresponderService::AUTO_RESPONDER_DEFAULT_IDLE_TIME);
81  if ($idle_time === 1) {
82  $auto_responder_body->setInfo($this->lng->txt('mail_absence_auto_responder_body_info_single_day'));
83  } else {
84  $auto_responder_body->setInfo(sprintf($this->lng->txt('mail_absence_auto_responder_body_info'), $idle_time));
85  }
86  $auto_responder_body->setRequired(true);
87  $auto_responder_body->setCols(60);
88  $auto_responder_body->setRows(10);
89  $absence->addSubItem($duration);
90  $absence->addSubItem($auto_responder_subject);
91  $absence->addSubItem($auto_responder_body);
92  $this->addItem($absence);
93 
94  $ta = new ilTextAreaInputGUI($this->lng->txt('signature'), 'signature');
95  $ta->setRows(10);
96  $ta->setCols(60);
97  $this->addItem($ta);
98 
99  if ($this->settings->get('mail_notification', '0')) {
100  $cb = new ilCheckboxInputGUI(
101  $this->lng->txt('cron_mail_notification'),
102  'cronjob_notification'
103  );
104  $cb->setInfo($this->lng->txt('mail_cronjob_notification_info'));
105  $cb->setValue('1');
106  $this->addItem($cb);
107  }
108 
109  $this->addCommandButton($this->positiveCmd, $this->lng->txt('save'));
110  }
111 
112  public function save(): bool
113  {
114  if (!$this->checkInput()) {
115  return false;
116  }
117 
118  if ($this->options->mayModifyIndividualTransportSettings()) {
119  $incoming_type = (int) $this->getInput('incoming_type');
120 
121  $mail_address_option = $this->options->getEmailAddressMode();
122  switch ($incoming_type) {
124  $mail_address_option = (int) $this->getInput('mail_address_option');
125  break;
126 
128  $mail_address_option = (int) $this->getInput('mail_address_option_both');
129  break;
130  }
131  } else {
132  $incoming_type = $this->options->getIncomingType();
133  $mail_address_option = $this->options->getEmailAddressMode();
134  }
135 
136  $absence_duration = $this->getItemByPostVar('absence_duration');
137  $absence_status = (bool) $this->getInput('absence_status');
138  $old_absence_status = $this->options->getAbsenceStatus();
139  if (!$absence_status && $old_absence_status) {
140  $this->autoResponderRepository->deleteBySenderId($this->user->getId());
141  }
142  $this->options->setAbsenceStatus((bool) $this->getInput('absence_status'));
143  if ($absence_duration && $absence_duration->getStart() && $absence_duration->getEnd()) {
144  $this->options->setAbsentFrom($absence_duration->getStart()->get(IL_CAL_UNIX));
145  $this->options->setAbsentUntil($absence_duration->getEnd()->get(IL_CAL_UNIX));
146  }
147  $this->options->setAbsenceAutoresponderSubject($this->getInput('absence_auto_responder_subject'));
148  $this->options->setAbsenceAutoresponderBody($this->getInput('absence_auto_responder_body'));
149 
150  $this->options->setSignature($this->getInput('signature'));
151  $this->options->setIsCronJobNotificationStatus((bool) $this->getInput('cronjob_notification'));
152  $this->options->setIncomingType($incoming_type);
153  $this->options->setEmailAddressMode($mail_address_option);
154 
155  $this->options->updateOptions();
156 
157  return true;
158  }
159 
160  public function populate(): void
161  {
162  $data = [
163  'signature' => $this->options->getSignature(),
164  'cronjob_notification' => $this->options->isCronJobNotificationEnabled(),
165  'absence_status' => $this->options->getAbsenceStatus(),
166  'absence_duration' => [
167  'start' => (new ilDateTime(($this->options->getAbsentFrom() ?: time()), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
168  'end' => (new ilDateTime(($this->options->getAbsentUntil() ?: $this->default_auto_responder_absence_end_ts), IL_CAL_UNIX))->get(IL_CAL_DATETIME),
169  ],
170  'absence_auto_responder_subject' => $this->options->getAbsenceAutoresponderSubject(),
171  'absence_auto_responder_body' => $this->options->getAbsenceAutoresponderBody(),
172  ];
173 
174  if ($this->options->maySeeIndividualTransportSettings()) {
175  $data['incoming_type'] = $this->options->getIncomingType();
176 
177  $mail_address_option = $this->options->getEmailAddressMode();
178 
179  $data['mail_address_option'] = $mail_address_option;
180  $data['mail_address_option_both'] = $mail_address_option;
181  }
182 
183  $this->setValuesByArray($data);
184  }
185 }
const IL_CAL_DATETIME
getItemByPostVar(string $a_post_var)
__construct(protected ilMailOptions $options, object $parentGui, protected string $positiveCmd, AutoresponderRepository $autoResponderRepository=null)
readonly int $default_auto_responder_absence_end_ts
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-...
final const INCOMING_EMAIL
Class ilMailOptionsFormGUI.
setFormAction(string $a_formaction)
global $DIC
Definition: shib_login.php:25
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.
final const INCOMING_BOTH
AutoResponderRepository $autoResponderRepository
Class ilIncomingMailInputGUI.