ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMailOptionsGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use Psr\Http\Message\ServerRequestInterface;
5
13{
15 private $tpl;
16
18 private $ctrl;
19
21 private $lng;
22
24 private $settings;
25
27 private $user;
28
30 private $umail;
31
33 private $mbox;
34
36 protected $request;
37
39 protected $form;
40
52 public function __construct(
54 ilCtrl $ctrl = null,
55 ilSetting $setting = null,
56 ilLanguage $lng = null,
57 ilObjUser $user = null,
58 ServerRequestInterface $request = null,
59 ilFormatMail $mail = null,
60 ilMailbox $malBox = null
61 ) {
62 global $DIC;
63
64 $this->tpl = $tpl;
65 if (null === $this->tpl) {
66 $this->tpl = $DIC->ui()->mainTemplate();
67 }
68
69 $this->ctrl = $ctrl;
70 if (null === $this->ctrl) {
71 $this->ctrl = $DIC->ctrl();
72 }
73
74 $this->settings = $setting;
75 if (null === $this->settings) {
76 $this->settings = $DIC->settings();
77 }
78
79 $this->lng = $lng;
80 if (null === $this->lng) {
81 $this->lng = $DIC->language();
82 }
83
84 $this->user = $user;
85 if (null === $this->user) {
86 $this->user = $DIC->user();
87 }
88
89 $this->request = $request;
90 if (null === $this->request) {
91 $this->request = $DIC->http()->request();
92 }
93
94 $this->umail = $mail;
95 if (null === $this->umail) {
96 $this->umail = new ilFormatMail($this->user->getId());
97 }
98
99 $this->mbox = $malBox;
100 if (null === $this->mbox) {
101 $this->mbox = new ilMailbox($this->user->getId());
102 }
103
104 $this->lng->loadLanguageModule('mail');
105 $this->ctrl->saveParameter($this, 'mobj_id');
106 }
107
108 public function executeCommand() : void
109 {
110 if (!$this->settings->get('show_mail_settings')) {
111 $referrer = $this->request->getQueryParams()['referrer'] ?? '';
112 if (strtolower('ilPersonalSettingsGUI') === strtolower($referrer)) {
113 $this->ctrl->redirectByClass('ilPersonalSettingsGUI');
114 return;
115 }
116 $this->ctrl->redirectByClass('ilMailGUI');
117 return;
118 }
119
120 $nextClass = $this->ctrl->getNextClass($this);
121 switch ($nextClass) {
122 default:
123 if (!($cmd = $this->ctrl->getCmd())) {
124 $cmd = 'showOptions';
125 }
126
127 $this->$cmd();
128 break;
129 }
130 }
131
135 public function setForm(ilMailOptionsFormGUI $form) : void
136 {
137 $this->form = $form;
138 }
139
143 protected function getForm() : ilMailOptionsFormGUI
144 {
145 if (null !== $this->form) {
146 return $this->form;
147 }
148
149 return new ilMailOptionsFormGUI(
150 new ilMailOptions((int) $this->user->getId()),
151 $this,
152 'saveOptions'
153 );
154 }
155
160 protected function saveOptions() : void
161 {
162 $this->tpl->setTitle($this->lng->txt('mail'));
163
164 $form = $this->getForm();
165 if ($form->save()) {
166 ilUtil::sendSuccess($this->lng->txt('mail_options_saved'), true);
167 $this->ctrl->redirect($this, 'showOptions');
168 }
169
170 $this->showOptions($form);
171 }
172
177 protected function showOptions(ilMailOptionsFormGUI $form = null) : void
178 {
179 if (null === $form) {
180 $form = $this->getForm();
181 $form->populate();
182 } else {
183 $form->setValuesByPost();
184 }
185
186 $this->tpl->setContent($form->getHTML());
187 $this->tpl->printToStdout();
188 }
189}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
This class provides processing control methods.
Class UserMail this class handles user mails.
Class ilGlobalPageTemplate.
language handling
Class ilMailOptionsFormGUI.
showOptions(ilMailOptionsFormGUI $form=null)
Called to display the mail options form.
saveOptions()
Called if the user pushes the submit button of the mail options form.
__construct(ilGlobalPageTemplate $tpl=null, ilCtrl $ctrl=null, ilSetting $setting=null, ilLanguage $lng=null, ilObjUser $user=null, ServerRequestInterface $request=null, ilFormatMail $mail=null, ilMailbox $malBox=null)
ilMailOptionsGUI constructor.
setForm(ilMailOptionsFormGUI $form)
Class ilMailOptions this class handles user mails.
Mail Box class Base class for creating and handling mail boxes.
ILIAS Setting Class.
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46