ILIAS  release_8 Revision v8.24
class.ilStudyProgrammeMailMemberSearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ilCtrl $ctrl;
25 protected ilLanguage $lng;
29
30 protected array $assignments = [];
31 protected array $user_ids = [];
33 private ?string $back_target = null;
34
35 public function __construct(
40 ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper,
41 ILIAS\Refinery\Factory $refinery,
43 ) {
44 $this->ctrl = $ctrl;
45 $this->tpl = $tpl;
46 $this->lng = $lng;
47 $this->access = $access;
48 $this->http_wrapper = $http_wrapper;
49 $this->refinery = $refinery;
50 $this->permission_helper = $permission_helper;
51
52 $this->lng->loadLanguageModule('mail');
53 $this->lng->loadLanguageModule('search');
54 }
55
56 public function getAssignments(): array
57 {
58 return $this->assignments;
59 }
60
61 public function setAssignments(array $assignments): void
62 {
63 $this->assignments = $assignments;
64 }
65
66 public function getBackTarget(): ?string
67 {
68 return $this->back_target;
69 }
70
71 public function setBackTarget(string $target): void
72 {
73 $this->back_target = $target;
74 }
75
76 public function executeCommand(): void
77 {
78 $cmd = $this->ctrl->getCmd();
79
80 $this->ctrl->setReturn($this, '');
81
82 switch ($cmd) {
83 case 'showSelectableUsers':
84 case 'members':
85 $this->showSelectableUsers();
86 break;
87 case 'sendMailToSelectedUsers':
88 $this->user_ids = $this->retrieveUserIds();
90 break;
91 case 'mailUserMulti':
92 $this->user_ids = array_keys($this->getProcessData());
94 break;
95 case 'cancel':
96 $this->redirectToParent();
97 break;
98 default:
99 throw new Exception('Unknown command ' . $cmd);
100 }
101 }
102
103 protected function showSelectableUsers(): void
104 {
105 $this->tpl->loadStandardTemplate();
106 $tbl = new ilStudyProgrammeMailMemberSearchTableGUI($this, $this->getRootPrgObjId(), 'showSelectableUsers');
107 $tbl->setData($this->getProcessData());
108
109 $this->tpl->setContent($tbl->getHTML());
110 }
111
112 protected function getProcessData(): array
113 {
114 $data = [];
115
116 foreach ($this->getAssignments() as $assignment) {
117 $user_id = $assignment->getUserId();
118 $name = ilObjUser::_lookupName($user_id);
119 $login = ilObjUser::_lookupLogin($user_id);
120
121 $publicName = $name['lastname'] . ', ' . $name['firstname'];
122
123 $data[$user_id]['user_id'] = $user_id;
124 $data[$user_id]['login'] = $login;
125 $data[$user_id]['name'] = $publicName;
126 }
127
128 $allowed_user_ids = $this->permission_helper->filterUserIds(
129 array_keys($data),
131 );
132
133 $ret = [];
134 foreach ($data as $usr_id => $entry) {
135 if (in_array($usr_id, $allowed_user_ids)) {
136 $ret[$usr_id] = $entry;
137 }
138 }
139
140 return $ret;
141 }
142
144 {
145 return ilStudyProgrammeDIC::dic()['ilObjStudyProgrammeMembersGUI'];
146 }
147
148 protected function retrieveUserIds(): array
149 {
150 $user_ids = [];
151 if ($this->http_wrapper->post()->has("user_ids")) {
152 $user_ids = $this->http_wrapper->post()->retrieve(
153 "user_ids",
154 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
155 );
156 }
157 return $user_ids;
158 }
159
160 protected function sendMailToSelectedUsers(): bool
161 {
163 if (!count($user_ids)) {
164 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("no_checkbox"));
165 $this->showSelectableUsers();
166 return false;
167 }
168
169 $rcps = array();
170 foreach ($user_ids as $usr_id) {
171 $rcps[] = ilObjUser::_lookupLogin($usr_id);
172 }
173
174 if (!count(array_filter($rcps))) {
175 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("no_checkbox"));
176 $this->showSelectableUsers();
177 return false;
178 }
180
181 $members_gui = $this->getPRGMembersGUI();
182 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
183 $members_gui,
184 'view',
185 array(),
186 array(
187 'type' => 'new',
188 'sig' => $this->createMailSignature()
189 ),
190 $this->generateContextArray()
191 ));
192
193 return true;
194 }
195
196 protected function generateContextArray(): array
197 {
198 $context_array = [];
199 $ref_id = $this->getRootPrgRefId();
201 switch ($type) {
202 case 'prg':
203 if ($this->access->checkAccess('write', "", $ref_id)) {
204 $context_array = array(
206 'ref_id' => $ref_id,
207 'ts' => time()
208 );
209 }
210 break;
211 }
212 return $context_array;
213 }
214
215 protected function redirectToParent(): void
216 {
217 $back_target = $this->getBackTarget();
218 if (is_null($back_target)) {
219 throw new LogicException("Can't redirect. No back target given.");
220 }
221
222 $this->ctrl->redirectToURL($back_target);
223 }
224
225 protected function createMailSignature(): string
226 {
227 $link = chr(13) . chr(10) . chr(13) . chr(10);
228 $link .= $this->lng->txt('prg_mail_permanent_link');
229 $link .= chr(13) . chr(10) . chr(13) . chr(10);
230 $link .= ilLink::_getLink($this->getRootPrgRefId());
231 return rawurlencode(base64_encode($link));
232 }
233
234 protected function getRootPrgRefId(): int
235 {
236 $assignments = $this->getAssignments();
237 $assignment = array_shift($assignments);
238 return ilObjStudyProgramme::getRefIdFor($assignment->getRootId());
239 }
240
241 protected function getRootPrgObjId(): int
242 {
243 $assignments = $this->getAssignments();
244 $assignment = array_shift($assignments);
245 return (int) $assignment->getRootId();
246 }
247}
Builds data types.
Definition: Factory.php:21
Class ilCtrl provides processing control methods.
language handling
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
static setRecipients(array $recipients, string $type='to')
@ilCtrl_Calls ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI @ilCtrl_Calls ilObjS...
static getRefIdFor(int $obj_id)
static _lookupName(int $a_user_id)
lookup user name
static _lookupLogin(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccessHandler $access, ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper, ILIAS\Refinery\Factory $refinery, ilPRGPermissionsHelper $permission_helper)
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...
$ref_id
Definition: ltiauth.php:67
if($format !==null) $name
Definition: metadata.php:247
Class ChatMainBarProvider \MainMenu\Provider.
$type