ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
41 protected $mail_options;
42
53 public function __construct(
55 ilCtrl $ctrl = null,
56 ilLanguage $lng = null,
57 ilObjUser $user = null,
58 ServerRequestInterface $request = null,
59 ilFormatMail $mail = null,
60 ilMailbox $malBox = null,
62 ) {
63 global $DIC;
64
65 $this->tpl = $tpl;
66 if (null === $this->tpl) {
67 $this->tpl = $DIC->ui()->mainTemplate();
68 }
69
70 $this->ctrl = $ctrl;
71 if (null === $this->ctrl) {
72 $this->ctrl = $DIC->ctrl();
73 }
74
75 $this->lng = $lng;
76 if (null === $this->lng) {
77 $this->lng = $DIC->language();
78 }
79
80 $this->user = $user;
81 if (null === $this->user) {
82 $this->user = $DIC->user();
83 }
84
85 $this->request = $request;
86 if (null === $this->request) {
87 $this->request = $DIC->http()->request();
88 }
89
90 $this->umail = $mail;
91 if (null === $this->umail) {
92 $this->umail = new ilFormatMail($this->user->getId());
93 }
94
95 $this->mbox = $malBox;
96 if (null === $this->mbox) {
97 $this->mbox = new ilMailbox($this->user->getId());
98 }
99 $this->mail_options = $mail_options ?? new ilMailOptions((int) $this->user->getId());
100
101 $this->lng->loadLanguageModule('mail');
102 $this->ctrl->saveParameter($this, 'mobj_id');
103 }
104
105 public function executeCommand() : void
106 {
107 if (!$this->mail_options->mayManageInvididualSettings()) {
108 $referrer = $this->request->getQueryParams()['referrer'] ?? '';
109 if (strtolower('ilPersonalSettingsGUI') === strtolower($referrer)) {
110 $this->ctrl->redirectByClass('ilPersonalSettingsGUI');
111 return;
112 }
113 $this->ctrl->redirectByClass('ilMailGUI');
114 return;
115 }
116
117 $nextClass = $this->ctrl->getNextClass($this);
118 switch ($nextClass) {
119 default:
120 if (!($cmd = $this->ctrl->getCmd())) {
121 $cmd = 'showOptions';
122 }
123
124 $this->$cmd();
125 break;
126 }
127 }
128
132 public function setForm(ilMailOptionsFormGUI $form) : void
133 {
134 $this->form = $form;
135 }
136
140 protected function getForm() : ilMailOptionsFormGUI
141 {
142 if (null !== $this->form) {
143 return $this->form;
144 }
145
146 return new ilMailOptionsFormGUI(
147 $this->mail_options,
148 $this,
149 'saveOptions'
150 );
151 }
152
157 protected function saveOptions() : void
158 {
159 $this->tpl->setTitle($this->lng->txt('mail'));
160
161 $form = $this->getForm();
162 if ($form->save()) {
163 ilUtil::sendSuccess($this->lng->txt('mail_options_saved'), true);
164 $this->ctrl->redirect($this, 'showOptions');
165 }
166
167 $this->showOptions($form);
168 }
169
174 protected function showOptions(ilMailOptionsFormGUI $form = null) : void
175 {
176 if (null === $form) {
177 $form = $this->getForm();
178 $form->populate();
179 } else {
180 $form->setValuesByPost();
181 }
182
183 $this->tpl->setContent($form->getHTML());
184 $this->tpl->printToStdout();
185 }
186}
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.
__construct(ilGlobalPageTemplate $tpl=null, ilCtrl $ctrl=null, ilLanguage $lng=null, ilObjUser $user=null, ServerRequestInterface $request=null, ilFormatMail $mail=null, ilMailbox $malBox=null, ilMailOptions $mail_options=null)
ilMailOptionsGUI constructor.
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.
setForm(ilMailOptionsFormGUI $form)
Class ilMailOptions this class handles user mails.
Mail Box class Base class for creating and handling mail boxes.
global $DIC
Definition: goto.php:24