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