ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeMailMemberSearchGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5declare(strict_types=1);
6
8{
12 protected $gui;
13
17 protected $ctrl;
18
22 protected $tpl;
23
27 protected $lng;
28
32 protected $access;
33
37 protected $assignments;
38
39 public function __construct(
44 ) {
45 $this->ctrl = $ctrl;
46 $this->tpl = $tpl;
47 $this->lng = $lng;
48 $this->access = $access;
49
50 $this->lng->loadLanguageModule('mail');
51 $this->lng->loadLanguageModule('search');
52 }
53
54 public function getAssignments() : array
55 {
56 return $this->assignments;
57 }
58
59 public function setAssignments(array $assignments) : void
60 {
61 $this->assignments = $assignments;
62 }
63
64 public function getBackTarget() : string
65 {
66 return $this->back_target;
67 }
68
69 public function setBackTarget(string $target)
70 {
71 $this->back_target = $target;
72 }
73
74 public function executeCommand() : void
75 {
76 $next_class = $this->ctrl->getNextClass($this);
77 $cmd = $this->ctrl->getCmd();
78
79 $this->ctrl->setReturn($this, '');
80
81 switch ($next_class) {
82 default:
83 switch ($cmd) {
84 case 'sendMailToSelectedUsers':
86 break;
87 case 'showSelectableUsers':
88 case 'members':
89 $this->showSelectableUsers();
90 break;
91 case 'cancel':
92 $this->redirectToParent();
93 break;
94 default:
95 throw new Exception('Unknown command ' . $cmd);
96 break;
97 }
98 break;
99 }
100 }
101
102 protected function showSelectableUsers() : void
103 {
104 $this->tpl->loadStandardTemplate();
105 $tbl = new ilStudyProgrammeMailMemberSearchTableGUI($this, 'showSelectableUsers');
106 $tbl->setData($this->getProcessData());
107
108 $this->tpl->setContent($tbl->getHTML());
109 }
110
111 protected function getProcessData() : array
112 {
113 $data = [];
114
115 foreach ($this->getAssignments() as $assignment) {
116 $user_id = $assignment->getUserId();
117 $name = ilObjUser::_lookupName($user_id);
119
120 $publicName = '';
121 if (in_array(ilObjUser::_lookupPref($user_id, 'public_profile'), array('g', 'y'))) {
122 $publicName = $name['lastname'] . ', ' . $name['firstname'];
123 }
124
125 $data[$user_id]['user_id'] = $user_id;
126 $data[$user_id]['login'] = $login;
127 $data[$user_id]['name'] = $publicName;
128 }
129
130 return $data;
131 }
132
134 {
135 return ilStudyProgrammeDIC::dic()['ilObjStudyProgrammeMembersGUI'];
136 }
137
138 protected function sendMailToSelectedUsers() : bool
139 {
140 if (!isset($_POST['user_ids']) || !count($_POST['user_ids'])) {
141 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
142 $this->showSelectableUsers();
143 return false;
144 }
145
146 $rcps = array();
147 foreach ($_POST['user_ids'] as $usr_id) {
148 $rcps[] = ilObjUser::_lookupLogin($usr_id);
149 }
150
151 if (!count(array_filter($rcps))) {
152 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
153 $this->showSelectableUsers();
154 return false;
155 }
157
158 $members_gui = $this->getPRGMembersGUI();
160 $members_gui,
161 'view',
162 array(),
163 array(
164 'type' => 'new',
165 'sig' => $this->createMailSignature()
166 ),
167 $this->generateContextArray()
168 ));
169
170 return true;
171 }
172
173 protected function generateContextArray() : array
174 {
175 $context_array = [];
176 $ref_id = $this->getRootPrgRefId();
177 $type = ilObject::_lookupType($ref_id, true);
178 switch ($type) {
179 case 'prg':
180 if ($this->access->checkAccess('write', "", $ref_id)) {
181 $context_array = array(
183 'ref_id' => $ref_id,
184 'ts' => time()
185 );
186 }
187 break;
188 }
189 return $context_array;
190 }
191
192 protected function redirectToParent() : void
193 {
195 }
196
197 protected function createMailSignature() : string
198 {
199 $link = chr(13) . chr(10) . chr(13) . chr(10);
200 $link .= $this->lng->txt('prg_mail_permanent_link');
201 $link .= chr(13) . chr(10) . chr(13) . chr(10);
202 include_once 'Services/Link/classes/class.ilLink.php';
203 $link .= ilLink::_getLink($this->getRootPrgRefId());
204 return rawurlencode(base64_encode($link));
205 }
206
207 protected function getRootPrgRefId() : int
208 {
209 $assignment = array_shift($this->getAssignments());
210 return ilObjStudyProgramme::getRefIdFor($assignment->getRootId());
211 }
212}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class provides processing control methods.
language handling
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
const CONTEXT_KEY
Session parameter for the context.
static setRecipients(array $recipients, string $type='to')
@ilCtrl_Calls ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI @ilCtrl_Calls ilObjS...
static getRefIdFor(int $obj_id)
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccessHandler $access)
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$login
Definition: cron.php:13
Interface ilAccessHandler.
if($format !==null) $name
Definition: metadata.php:230
$type
$data
Definition: storeScorm.php:23