ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 protected int $context_prg_obj_id,
45 ) {
46 $this->ctrl = $ctrl;
47 $this->tpl = $tpl;
48 $this->lng = $lng;
49 $this->access = $access;
50 $this->http_wrapper = $http_wrapper;
51 $this->refinery = $refinery;
52 $this->permission_helper = $permission_helper;
53
54 $this->lng->loadLanguageModule('mail');
55 $this->lng->loadLanguageModule('search');
56 }
57
58 public function getAssignments(): array
59 {
60 return $this->assignments;
61 }
62
63 public function setAssignments(array $assignments): void
64 {
65 $this->assignments = $assignments;
66 }
67
68 public function getBackTarget(): ?string
69 {
70 return $this->back_target;
71 }
72
73 public function setBackTarget(string $target): void
74 {
75 $this->back_target = $target;
76 }
77
78 public function executeCommand(): void
79 {
80 $cmd = $this->ctrl->getCmd();
81
82 $this->ctrl->setReturn($this, '');
83
84 switch ($cmd) {
85 case 'showSelectableUsers':
86 case 'members':
87 $this->showSelectableUsers();
88 break;
89 case 'sendMailToSelectedUsers':
90 $this->user_ids = $this->retrieveUserIds();
92 break;
93 case 'mailUserMulti':
94 $this->user_ids = array_keys($this->getProcessData());
96 break;
97 case 'cancel':
98 $this->redirectToParent();
99 break;
100 default:
101 throw new Exception('Unknown command ' . $cmd);
102 }
103 }
104
105 protected function showSelectableUsers(): void
106 {
107 $this->tpl->loadStandardTemplate();
108 $tbl = new ilStudyProgrammeMailMemberSearchTableGUI($this, $this->getRootPrgObjId(), 'showSelectableUsers');
109 $tbl->setData($this->getProcessData());
110
111 $this->tpl->setContent($tbl->getHTML());
112 }
113
114 protected function getProcessData(): array
115 {
116 $data = [];
117 $usr_ids = [];
118 foreach ($this->getAssignments() as $assignment) {
119 $usr_id = $assignment->getUserId();
120 $name = ilObjUser::_lookupName($usr_id);
121 $login = ilObjUser::_lookupLogin($usr_id);
122 $publicName = $name['lastname'] . ', ' . $name['firstname'];
123 $data[] = [
124 'user_id' => $usr_id,
125 'login' => $login,
126 'name' => $publicName,
127 'root_id' => $assignment->getRootId()
128 ];
129 $usr_ids[] = $usr_id;
130 }
131
132 $allowed_user_ids = $this->permission_helper->filterUserIds(
133 array_unique($usr_ids),
135 );
136
137 $ret = [];
138 $foreign = $this->messages->getMessageCollection('mails_foreign_assignment');
139
140 foreach($data as $entry) {
141 if($entry['root_id'] === $this->context_prg_obj_id) {
142 $ret[$entry['user_id']] = $entry;
143 } else {
144 $foreign->add(false, 'foreign_assignment', $entry['name']);
145 }
146 }
147
148 if($foreign->hasErrors()) {
149 $this->messages->showMessages($foreign);
150 }
151
152
153 return $ret;
154 }
155
157 {
158 return ilStudyProgrammeDIC::dic()['ilObjStudyProgrammeMembersGUI'];
159 }
160
161 protected function retrieveUserIds(): array
162 {
163 $user_ids = [];
164 if ($this->http_wrapper->post()->has("user_ids")) {
165 $user_ids = $this->http_wrapper->post()->retrieve(
166 "user_ids",
167 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
168 );
169 }
170 return $user_ids;
171 }
172
173 protected function sendMailToSelectedUsers(): bool
174 {
176 if (!count($user_ids)) {
177 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("no_checkbox"));
178 $this->showSelectableUsers();
179 return false;
180 }
181
182 $rcps = array();
183 foreach ($user_ids as $usr_id) {
184 $rcps[] = ilObjUser::_lookupLogin($usr_id);
185 }
186
187 if (!count(array_filter($rcps))) {
188 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("no_checkbox"));
189 $this->showSelectableUsers();
190 return false;
191 }
193
194 $members_gui = $this->getPRGMembersGUI();
195 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
196 $members_gui,
197 'view',
198 array(),
199 array(
200 'type' => 'new',
201 'sig' => $this->createMailSignature()
202 ),
203 $this->generateContextArray()
204 ));
205
206 return true;
207 }
208
209 protected function generateContextArray(): array
210 {
211 $context_array = [];
212 $ref_id = $this->getRootPrgRefId();
213 $type = ilObject::_lookupType($ref_id, true);
214 switch ($type) {
215 case 'prg':
216 if ($this->access->checkAccess('write', "", $ref_id)) {
217 $context_array = array(
219 'ref_id' => $ref_id,
220 'ts' => time()
221 );
222 }
223 break;
224 }
225 return $context_array;
226 }
227
228 protected function redirectToParent(): void
229 {
230 $back_target = $this->getBackTarget();
231 if (is_null($back_target)) {
232 throw new LogicException("Can't redirect. No back target given.");
233 }
234
235 $this->ctrl->redirectToURL($back_target);
236 }
237
238 protected function createMailSignature(): string
239 {
240 $link = chr(13) . chr(10) . chr(13) . chr(10);
241 $link .= $this->lng->txt('prg_mail_permanent_link');
242 $link .= chr(13) . chr(10) . chr(13) . chr(10);
243 $link .= ilLink::_getLink($this->getRootPrgRefId());
244 return rawurlencode(base64_encode($link));
245 }
246
247 protected function getRootPrgRefId(): int
248 {
249 $assignments = $this->getAssignments();
250 $assignment = array_shift($assignments);
251 return ilObjStudyProgramme::getRefIdFor($assignment->getRootId());
252 }
253
254 protected function getRootPrgObjId(): int
255 {
256 $assignments = $this->getAssignments();
257 $assignment = array_shift($assignments);
258 return (int) $assignment->getRootId();
259 }
260}
Builds data types.
Definition: Factory.php:36
Class ilCtrl provides processing control methods.
language handling
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
final const string CONTEXT_KEY
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)
static _lookupLogin(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
Util around ilPRGMessageCollection factors and output collections.
Both role and OrgU-based permissions are relevant in many places of the PRG.
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccessHandler $access, ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper, ILIAS\Refinery\Factory $refinery, ilPRGPermissionsHelper $permission_helper, protected int $context_prg_obj_id, protected ilPRGMessagePrinter $messages,)
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$messages
Definition: xapiexit.php:21