ILIAS  release_8 Revision v8.24
class.ilMailMemberSearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Psr\Http\Message\ServerRequestInterface;
22
29{
30 private ServerRequestInterface $httpRequest;
32 private array $mail_roles;
34 private $gui;
41 public int $ref_id;
42
50 {
51 global $DIC;
52
53 $this->ctrl = $DIC['ilCtrl'];
54 $this->tpl = $DIC['tpl'];
55 $this->lng = $DIC['lng'];
56 $this->access = $DIC['ilAccess'];
57 $this->httpRequest = $DIC->http()->request();
58
59 $this->lng->loadLanguageModule('mail');
60 $this->lng->loadLanguageModule('search');
61
62 $this->gui = $gui;
63 $this->ref_id = $ref_id;
64
65 $this->objMailMemberRoles = $objMailMemberRoles;
66 $this->mail_roles = $objMailMemberRoles->getMailRoles($ref_id);
67 }
68
69
70 public function executeCommand(): bool
71 {
72 $next_class = $this->ctrl->getNextClass($this);
73 $cmd = $this->ctrl->getCmd();
74
75 $this->ctrl->setReturn($this, '');
76
77 switch ($cmd) {
78 case 'sendMailToSelectedUsers':
80 break;
81
82 case 'showSelectableUsers':
83 $this->showSelectableUsers();
84 break;
85
86 case 'nextMailForm':
87 $this->nextMailForm();
88 break;
89
90 case 'cancel':
92 break;
93
94 default:
95 if (isset($this->httpRequest->getQueryParams()['returned_from_mail']) && $this->httpRequest->getQueryParams()['returned_from_mail'] === '1') {
97 }
98 $this->showSearchForm();
99 break;
100 }
101
102
103 return true;
104 }
105
106 private function redirectToParentReferer(): void
107 {
108 $url = $this->getStoredReferer();
109 $this->unsetStoredReferer();
110 $this->ctrl->redirectToURL($url);
111 }
112
113 public function storeReferer(): void
114 {
115 $back_link = $this->ctrl->getParentReturn($this);
116
117 if (isset($this->httpRequest->getServerParams()['HTTP_REFERER'])) {
118 $referer = $this->httpRequest->getServerParams()['HTTP_REFERER'];
119 $urlParts = parse_url($referer);
120
121 if (isset($urlParts['path'])) {
122 $url = ltrim(basename($urlParts['path']), '/');
123 if (isset($urlParts['query'])) {
124 $url .= '?' . $urlParts['query'];
125 }
126 if ($url !== '') {
127 $back_link = $url;
128 }
129 }
130 }
131
132 ilSession::set('ilMailMemberSearchGUIReferer', $back_link);
133 }
134
135 private function getStoredReferer(): string
136 {
137 return (string) ilSession::get('ilMailMemberSearchGUIReferer');
138 }
139
140 private function unsetStoredReferer(): void
141 {
142 ilSession::set('ilMailMemberSearchGUIReferer', '');
143 }
144
145 protected function nextMailForm(): void
146 {
147 $form = $this->initMailToMembersForm();
148 if ($form->checkInput()) {
149 if ($form->getInput('mail_member_type') === 'mail_member_roles') {
150 if (is_array($form->getInput('roles')) && count($form->getInput('roles')) > 0) {
151 $role_mail_boxes = [];
152 $roles = $form->getInput('roles');
153 foreach ($roles as $role_id) {
154 $mailbox = $this->objMailMemberRoles->getMailboxRoleAddress((int) $role_id);
155 $role_mail_boxes[] = $mailbox;
156 }
157
158 ilSession::set('mail_roles', $role_mail_boxes);
159
160 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
161 $this,
162 'showSearchForm',
164 [
166 'rcp_to' => implode(',', $role_mail_boxes),
167 'sig' => $this->gui->createMailSignature()
168 ],
169 $this->generateContextArray()
170 ));
171 } else {
172 $form->setValuesByPost();
173 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'));
174 $this->showSearchForm();
175 return;
176 }
177 } else {
178 $this->showSelectableUsers();
179 return;
180 }
181 }
182
183 $form->setValuesByPost();
184 $this->showSearchForm();
185 }
186
187 protected function generateContextArray(): array
188 {
189 $contextParameters = [];
190
191 $type = ilObject::_lookupType($this->ref_id, true);
192 switch ($type) {
193 case 'grp':
194 case 'crs':
195 if ($this->access->checkAccess('write', '', $this->ref_id)) {
196 $contextParameters = [
197 'ref_id' => $this->ref_id,
198 'ts' => time(),
200 ilObject::_lookupObjId($this->ref_id),
202 ''
203 )
204 ];
205
206 if ('crs' === $type) {
208 }
209 }
210 break;
211
212 case 'sess':
213 if ($this->access->checkAccess('write', '', $this->ref_id)) {
214 $contextParameters = [
216 'ref_id' => $this->ref_id,
217 'ts' => time()
218 ];
219 }
220 break;
221 }
222
223 return $contextParameters;
224 }
225
226 protected function showSelectableUsers(): void
227 {
228 $this->tpl->loadStandardTemplate();
229 $tbl = new ilMailMemberSearchTableGUI($this, 'showSelectableUsers');
230 $provider = new ilMailMemberSearchDataProvider($this->getObjParticipants(), $this->ref_id);
231 $tbl->setData($provider->getData());
232
233 $this->tpl->setContent($tbl->getHTML());
234 }
235
236
237 protected function sendMailToSelectedUsers(): void
238 {
239 if (!isset($this->httpRequest->getParsedBody()['user_ids']) || !is_array($this->httpRequest->getParsedBody()['user_ids']) || 0 === count($this->httpRequest->getParsedBody()['user_ids'])) {
240 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"));
241 $this->showSelectableUsers();
242 return;
243 }
244
245 $rcps = [];
246 foreach ($this->httpRequest->getParsedBody()['user_ids'] as $usr_id) {
247 $rcps[] = ilObjUser::_lookupLogin((int) $usr_id);
248 }
249
250 if (!count(array_filter($rcps))) {
251 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"));
252 $this->showSelectableUsers();
253 return;
254 }
255
257
258 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
259 $this,
260 'members',
261 [],
262 [
264 'sig' => $this->gui->createMailSignature(),
265 ],
266 $this->generateContextArray()
267 ));
268 }
269
270 protected function showSearchForm(): void
271 {
272 $this->storeReferer();
273
274 $form = $this->initMailToMembersForm();
275 $this->tpl->setContent($form->getHTML());
276 }
277
278
279 protected function getObjParticipants(): ?ilParticipants
280 {
282 }
283
288 {
289 $this->objParticipants = $objParticipants;
290 }
291
292
294 {
295 $this->lng->loadLanguageModule('mail');
296
297 $form = new ilPropertyFormGUI();
298 $form->setTitle($this->lng->txt('mail_members'));
299
300 $form->setFormAction($this->ctrl->getFormAction($this, 'nextMailForm'));
301
302 $radio_grp = $this->getMailRadioGroup();
303
304 $form->addItem($radio_grp);
305 $form->addCommandButton('nextMailForm', $this->lng->txt('mail_members_search_continue'));
306 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
307
308 return $form;
309 }
310
314 private function getMailRoles(): array
315 {
316 return $this->mail_roles;
317 }
318
319
321 {
322 $mail_roles = $this->getMailRoles();
323
324 $radio_grp = new ilRadioGroupInputGUI($this->lng->txt('mail_sel_label'), 'mail_member_type');
325
326 $radio_sel_users = new ilRadioOption($this->lng->txt('mail_sel_users'), 'mail_sel_users');
327
328 $radio_roles = new ilRadioOption($this->objMailMemberRoles->getRadioOptionTitle(), 'mail_member_roles');
329 foreach ($mail_roles as $role) {
330 $chk_role = new ilCheckboxInputGUI($role['form_option_title'], 'roles[' . $role['role_id'] . ']');
331
332 if (isset($role['default_checked']) && $role['default_checked'] === true) {
333 $chk_role->setChecked(true);
334 }
335 $chk_role->setValue((string) $role['role_id']);
336 $chk_role->setInfo($role['mailbox']);
337 $radio_roles->addSubItem($chk_role);
338 }
339
340 $radio_grp->setValue('mail_member_roles');
341
342 $radio_grp->addOption($radio_sel_users);
343 $radio_grp->addOption($radio_roles);
344
345 return $radio_grp;
346 }
347}
Class ilAbstractMailMemberRoles.
This class represents a checkbox property in a property form.
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
language handling
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
static setRecipients(array $recipients, string $type='to')
Class ilMailMemberSearchDataProvider.
Class ilMailMemberSearchGUI.
ilGlobalTemplateInterface $tpl
ilAbstractMailMemberRoles $objMailMemberRoles
setObjParticipants(ilParticipants $objParticipants)
__construct(object $gui, int $ref_id, ilAbstractMailMemberRoles $objMailMemberRoles)
ilMailMemberSearchGUI constructor.
ServerRequestInterface $httpRequest
const PROP_CONTEXT_SUBJECT_PREFIX
static _lookupLogin(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
Base class for course and group participants.
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$provider
Definition: ltitoken.php:83
$type
$url