ILIAS  release_8 Revision v8.24
class.ilSurveyRaterGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27 protected \ILIAS\Survey\Editing\EditingGUIRequest $edit_request;
28 protected \ilCtrl $ctrl;
29 protected \ilLanguage $lng;
30 protected \ILIAS\DI\UIServices $ui;
31 protected \ILIAS\Refinery\Factory $refinery;
32 protected \ilGlobalTemplateInterface $main_tpl;
35 protected \ilObjUser $user;
36 protected \ilAccessHandler $access;
37 protected ilTabsGUI $tabs;
38
39 public function __construct(
42 ) {
43 global $DIC;
44
45 $this->ctrl = $DIC->ctrl();
46 $this->lng = $DIC->language();
47 $this->ui = $DIC->ui();
48 $this->refinery = $DIC->refinery();
49 $this->main_tpl = $DIC->ui()->mainTemplate();
50 $this->parent = $parent;
51 $this->survey = $survey;
52 $this->user = $DIC->user();
53 $this->access = $DIC->access();
54 $this->tabs = $DIC->tabs();
55
56 $this->ctrl->saveParameter($this, "appr_id");
57 $this->edit_request = $DIC->survey()
58 ->internal()
59 ->gui()
60 ->editing()
61 ->request();
62 }
63
64 public function executeCommand(): void
65 {
67
68 $next_class = $ctrl->getNextClass($this);
69 $cmd = $ctrl->getCmd("add");
70
71 switch ($next_class) {
72
73 case 'ilrepositorysearchgui':
74 $rep_search = new ilRepositorySearchGUI();
75
76 $this->ctrl->setParameter($this, "rate360", 1);
77 $this->ctrl->saveParameter($this, "appr_id");
78
79 $rep_search->setCallback(
80 $this,
81 'addFromSearch',
82 array()
83 );
84
85 // Set tabs
86 $this->ctrl->setReturn($this, 'add');
87 $this->ctrl->forwardCommand($rep_search);
88 break;
89
90 default:
91 if (in_array($cmd, ["add",
92 "doAutoComplete",
93 "continue",
94 "mailRaters",
95 "mailRatersAction",
96 "cancel"
97 ])) {
98 $this->$cmd();
99 }
100 break;
101 }
102 }
103
104 protected function cancel(): void
105 {
106 $this->ctrl->redirect($this->parent, "editRaters");
107 }
108
109 protected function add(
110 ilPropertyFormGUI $form = null
111 ): void {
112 $form_html = (!is_null($form))
113 ? $form->getHTML()
114 : $this->initOptionSelectForm()->getHTML();
116 $main_tpl->setContent($form_html);
117 }
118
120 {
121 $ctrl = $this->ctrl;
123
124 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
125 $form = new ilPropertyFormGUI();
126
127 //
128 $radg = new ilRadioGroupInputGUI($lng->txt("svy_type_of_rater"), "type");
129 //$radg->setInfo($lng->txt(""));
130 //$radg->setValue();
131 $op1 = new ilRadioOption($lng->txt("svy_add_internal_user"), "direct", $lng->txt("svy_add_internal_user_info"));
132 $radg->addOption($op1);
133 $radg->setValue("direct");
134
135 $user = new \ilTextInputGUI($lng->txt("obj_user"), "user");
136 $user->setDataSource(
137 $ctrl->getLinkTargetByClass(
138 "ilsurveyratergui",
139 "doAutoComplete",
140 "",
141 true
142 )
143 );
144 $user->setRequired(true);
145 $user->setMulti(false);
146 $op1->addSubItem($user);
147
148
149 $op2 = new ilRadioOption($lng->txt("svy_search_user"), "search", $lng->txt("svy_search_user_info"));
150 $radg->addOption($op2);
151
152 $op3 = new ilRadioOption($lng->txt("svy_external_rater"), "external", $lng->txt("svy_external_rater_info"));
153 $radg->addOption($op3);
154
155 $email = new ilEMailInputGUI($this->lng->txt("email"), "email");
156 $email->setRequired(true);
157 $op3->addSubItem($email);
158
159 $lname = new ilTextInputGUI($this->lng->txt("lastname"), "lname");
160 $lname->setSize(30);
161 $op3->addSubItem($lname);
162
163 $fname = new ilTextInputGUI($this->lng->txt("firstname"), "fname");
164 $fname->setSize(30);
165 $op3->addSubItem($fname);
166
167
168 $form->addItem($radg);
169
170 // save and cancel commands
171 $form->addCommandButton("continue", $lng->txt("svy_save_and_continue"));
172 $form->addCommandButton("cancel", $lng->txt("cancel"));
173
174 $form->setTitle($lng->txt("svy_add_rater"));
175 $form->setFormAction($ctrl->getFormAction($this));
176
177 return $form;
178 }
179
180 public function doAutoComplete(): void
181 {
182 $fields = array('login','firstname','lastname','email');
183
184 $auto = new ilUserAutoComplete();
185 $auto->setSearchFields($fields);
186 $auto->setResultField('login');
187 $auto->enableFieldSearchableCheck(true);
188 $auto->setMoreLinkAvailable(true);
190
191 if ($this->edit_request->getFetchAll()) {
192 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
193 }
194
195 echo $auto->getList($this->edit_request->getTerm());
196 exit();
197 }
198
199 protected function continue(): void
200 {
201 $form = $this->initOptionSelectForm();
202 if ($form->checkInput()) {
203 switch ($form->getInput("type")) {
204 case "direct":
205 $this->addRater($form);
206 break;
207
208 case "external":
209 $this->addExternalRater($form);
210 break;
211
212 case "search":
213 $this->ctrl->redirectByClass("ilrepositorysearchgui", "");
214 break;
215
216 }
217 } else {
218 $form->setValuesByPost();
219 $this->add($form);
220 }
221 }
222
223 public function addRater(ilPropertyFormGUI $form): void
224 {
225 // check access
226 $ilAccess = $this->access;
227 $ilUser = $this->user;
228
229 $appr_id = $this->parent->handleRatersAccess();
230 $user = $form->getInput("user");
231 $user_id = ilObjUser::_lookupId($user);
232 if ($user_id > 0) {
233 if ($ilAccess->checkAccess("write", "", $this->survey->getRefId()) ||
234 $this->survey->get360SelfEvaluation() ||
235 $user_id !== $ilUser->getId()) {
236 if ($appr_id !== $user_id) {
237 $this->survey->addRater($appr_id, $user_id);
238 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
239 } else {
240 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("svy_appraisses_cannot_be_raters"), true);
241 $user_id = 0;
242 }
243 }
244 } else {
245 $this->main_tpl->setOnScreenMessage(
246 'failure',
247 $this->lng->txt("svy_user_not_found") . " (" . $user . ")",
248 true
249 );
250 }
251
252 $this->ctrl->setParameter($this->parent, "appr_id", $appr_id);
253 if ($user_id > 0) {
254 $this->ctrl->setParameter($this, "rater_id", "u" . $user_id);
255 $this->ctrl->redirect($this, "mailRaters");
256 }
257 $this->ctrl->redirect($this->parent, "editRaters");
258 }
259
260
261 public function mailRaters(ilPropertyFormGUI $a_form = null): void
262 {
263 $appr_id = $this->parent->handleRatersAccess();
264 $this->ctrl->setParameterByClass("ilSurveyParticipantsGUI", "appr_id", $appr_id);
265 $this->ctrl->setParameterByClass("ilSurveyParticipantsGUI", "rater_id", $this->edit_request->getRaterId());
266 $this->ctrl->redirectByClass("ilSurveyParticipantsGUI", "mailRaters");
267 }
268
269 public function initMailRatersForm(
270 int $appr_id,
271 array $rec_ids
273 $form = new ilPropertyFormGUI();
274 $form->setFormAction($this->ctrl->getFormAction($this, "mailRatersAction"));
275 $form->setTitle($this->lng->txt('compose'));
276
277 $all_data = $this->survey->getRatersData($appr_id);
278
279 $rec_data = array();
280 foreach ($rec_ids as $rec_id) {
281 if (isset($all_data[$rec_id])) {
282 $rec_data[] = $all_data[$rec_id]["lastname"] . ", " .
283 $all_data[$rec_id]["firstname"] .
284 " (" . $all_data[$rec_id]["email"] . ")";
285 }
286 }
287 sort($rec_data);
288 $rec = new ilCustomInputGUI($this->lng->txt('recipients'));
289 $rec->setHtml(implode("<br />", $rec_data));
290 $form->addItem($rec);
291
292 $subject = new ilTextInputGUI($this->lng->txt('subject'), 'subject');
293 $subject->setSize(50);
294 $subject->setRequired(true);
295 $form->addItem($subject);
296
297 $existingdata = $this->survey->getExternalCodeRecipients();
298 $existingcolumns = array();
299 if (count($existingdata)) {
300 $first = array_shift($existingdata);
301 foreach ($first as $key => $value) {
302 if (strcmp($key, 'code') !== 0 && strcmp($key, 'email') !== 0 && strcmp($key, 'sent') !== 0) {
303 $existingcolumns[] = '[' . $key . ']';
304 }
305 }
306 }
307
308 $mailmessage_u = new ilTextAreaInputGUI($this->lng->txt('survey_360_rater_message_content_registered'), 'message_u');
309 $mailmessage_u->setRequired(true);
310 $mailmessage_u->setCols(80);
311 $mailmessage_u->setRows(10);
312 $form->addItem($mailmessage_u);
313
314 $mailmessage_a = new ilTextAreaInputGUI($this->lng->txt('survey_360_rater_message_content_anonymous'), 'message_a');
315 $mailmessage_a->setRequired(true);
316 $mailmessage_a->setCols(80);
317 $mailmessage_a->setRows(10);
318 $mailmessage_a->setInfo(sprintf($this->lng->txt('message_content_info'), implode(', ', $existingcolumns)));
319 $form->addItem($mailmessage_a);
320
321 $recf = new ilHiddenInputGUI("rtr_id");
322 $recf->setValue(implode(";", $rec_ids));
323 $form->addItem($recf);
324
325 $form->addCommandButton("mailRatersAction", $this->lng->txt("send"));
326 $form->addCommandButton("cancel", $this->lng->txt("svy_dont_send"));
327
328 $subject->setValue(sprintf($this->lng->txt('survey_360_rater_subject_default'), $this->survey->getTitle()));
329 $mailmessage_u->setValue($this->lng->txt('survey_360_rater_message_content_registered_default'));
330 $mailmessage_a->setValue($this->lng->txt('survey_360_rater_message_content_anonymous_default'));
331
332 return $form;
333 }
334
335
336 public function mailRatersAction(): void
337 {
338 $ilUser = $this->user;
339
340 $appr_id = $this->parent->handleRatersAccess();
341 $this->ctrl->setParameter($this, "appr_id", $appr_id);
342
343 $rec_ids = $this->edit_request->getRaterIds();
344 if (count($rec_ids) === 0) {
345 $this->ctrl->redirect($this, "editRaters");
346 }
347
348 $form = $this->initMailRatersForm($appr_id, $rec_ids);
349 if ($form->checkInput()) {
350 $txt_u = $form->getInput("message_u");
351 $txt_a = $form->getInput("message_a");
352 $subj = $form->getInput("subject");
353
354 // #12743
355 $sender_id = (trim($ilUser->getEmail()))
356 ? $ilUser->getId()
358
359 $all_data = $this->survey->getRatersData($appr_id);
360 foreach ($rec_ids as $rec_id) {
361 if (isset($all_data[$rec_id])) {
362 $user = $all_data[$rec_id];
363
364 // anonymous
365 if (strpos($rec_id, "a") === 0) {
366 $mytxt = $txt_a;
367 $url = $user["href"];
368 $rcp = $user["email"];
369 }
370 // reg
371 else {
372 $mytxt = $txt_u;
373 $user["code"] = $this->lng->txt("survey_code_mail_on_demand");
374 $url = ilLink::_getStaticLink($this->survey->getRefId());
375 $rcp = $user["login"]; // #15141
376 }
377
378 $mytxt = str_replace(
379 ["[lastname]", "[firstname]", "[url]", "[code]"],
380 [$user["lastname"], $user["firstname"], $url, $user["code"]],
381 $mytxt
382 );
383
384 $mail = new ilMail($sender_id);
385 $mail->enqueue(
386 $rcp, // to
387 "", // cc
388 "", // bcc
389 $subj, // subject
390 $mytxt, // message
391 array() // attachments
392 );
393
394 $this->survey->set360RaterSent(
395 $appr_id,
396 (strpos($rec_id, "a") === 0) ? 0 : (int) substr($rec_id, 1),
397 (strpos($rec_id, "u") === 0) ? 0 : (int) substr($rec_id, 1)
398 );
399 }
400 }
401
402 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("mail_sent"), true);
403 $this->ctrl->redirect($this->parent, "editRaters");
404 }
405
406 $form->setValuesByPost();
407// $this->mailRatersObject($form);
408 }
409
410 public function addExternalRater(ilPropertyFormGUI $form): void
411 {
412 $appr_id = $this->edit_request->getAppraiseeId();
413
414 if (!$appr_id) {
415 $this->ctrl->redirect($this, "listAppraisees");
416 }
417
418 $this->ctrl->setParameter($this, "appr_id", $appr_id);
419
420 $code_id = $this->parent->addCodeForExternal(
421 $form->getInput("email"),
422 $form->getInput("lname"),
423 $form->getInput("fname")
424 );
425
426 $this->survey->addRater($appr_id, 0, $code_id);
427
428 $this->ctrl->setParameter($this->parent, "appr_id", $appr_id);
429 if ($code_id > 0) {
430 $this->ctrl->setParameter($this, "rater_id", "a" . $code_id);
431 $this->ctrl->redirect($this, "mailRaters");
432 }
433 $this->ctrl->redirect($this->parent, "editRaters");
434 }
435
436 public function addFromSearch(
437 array $user_ids
438 ): void {
439 // check access
440 $ilAccess = $this->access;
441 $ilUser = $this->user;
442
443 $user_id = 0;
444
445 $appr_id = $this->parent->handleRatersAccess();
446
447 foreach ($user_ids as $user_id) {
448 if ($user_id > 0) {
449 if ($ilAccess->checkAccess("write", "", $this->survey->getRefId()) ||
450 $this->survey->get360SelfEvaluation() ||
451 $user_id != $ilUser->getId()) {
452 if ($appr_id != $user_id) {
453 $this->survey->addRater($appr_id, $user_id);
454 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
455 } else {
456 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("svy_appraisses_cannot_be_raters"), true);
457 $user_id = 0;
458 }
459 }
460 }
461 }
462
463 $user_str = implode(";", array_map(static function ($u): string {
464 return "u" . $u;
465 }, $user_ids));
466
467 $this->ctrl->setParameter($this->parent, "appr_id", $appr_id);
468 if ($user_id > 0) {
469 $this->ctrl->setParameter($this, "rater_id", $user_str);
470 $this->ctrl->redirect($this, "mailRaters");
471 }
472 $this->ctrl->redirect($this->parent, "editRaters");
473 }
474}
getNextClass($a_gui_class=null)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
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...
setFormAction(string $a_formaction)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupId($a_user_str)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
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...
Class ilSurveyParticipantsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initMailRatersForm(int $appr_id, array $rec_ids)
ILIAS DI UIServices $ui
addRater(ilPropertyFormGUI $form)
mailRaters(ilPropertyFormGUI $a_form=null)
ILIAS Survey Editing EditingGUIRequest $edit_request
ILIAS Refinery Factory $refinery
addFromSearch(array $user_ids)
addExternalRater(ilPropertyFormGUI $form)
add(ilPropertyFormGUI $form=null)
ilGlobalTemplateInterface $main_tpl
ilSurveyParticipantsGUI $parent
__construct(ilSurveyParticipantsGUI $parent, ilObjSurvey $survey)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
setContent(string $a_html)
Sets content for standard template.
exit
Definition: login.php:28
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:302
string $key
Consumer key/client ID value.
Definition: System.php:193
$url
$lng