ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.InfoScreenGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 
35 {
36  protected \ILIAS\DI\UIServices $ui;
37  protected \ilObjSurvey $survey;
38  protected \ilObjUser $user;
39  protected \ilToolbarGUI $toolbar;
40  protected \ilObjSurveyGUI $survey_gui;
44  protected ServerRequestInterface $request;
45  protected string $requested_code;
46  protected \ILIAS\Survey\Mode\FeatureConfig $feature_config;
47  protected \ilLanguage $lng;
48  protected \ilCtrl $ctrl;
49  private \ilGlobalTemplateInterface $main_tpl;
50 
51  public function __construct(
52  \ilObjSurveyGUI $survey_gui,
53  \ilToolbarGUI $toolbar,
54  \ilObjUser $user,
55  \ilLanguage $lng,
56  \ilCtrl $ctrl,
57  ServerRequestInterface $request,
58  InternalDomainService $domain_service
59  ) {
60  global $DIC;
61  $this->main_tpl = $DIC->ui()->mainTemplate();
62  $this->user = $user;
63  $this->toolbar = $toolbar;
64  $this->survey_gui = $survey_gui;
65  $this->ui = $DIC->ui();
67  $survey = $survey_gui->getObject();
68  $this->survey = $survey;
69  $this->status_manager = $domain_service->participants()->status($this->survey, $user->getId());
70  $this->access_manager = $domain_service->access($this->survey->getRefId(), $user->getId());
71  $this->run_manager = $domain_service->execution()->run($this->survey, $user->getId());
72  $this->feature_config = $domain_service->modeFeatureConfig($this->survey->getMode());
73 
74  $this->lng = $lng;
75  $this->ctrl = $ctrl;
76 
77  $body = $request->getParsedBody();
78  $this->requested_code = (string) ($body["anonymous_id"] ?? "");
79  }
80 
81  public function getInfoScreenGUI(): \ilInfoScreenGUI
82  {
83  $user = $this->user;
84  $toolbar = $this->toolbar;
85  $status_manager = $this->status_manager;
86  $survey = $this->survey;
87 
88  $external_rater = $status_manager->isExternalRater();
89 
90  $output_gui = new \ilSurveyExecutionGUI($survey);
91 
92  $info = new \ilInfoScreenGUI($this->survey_gui);
93  $info->enablePrivateNotes();
94 
95  // appraisee infos
96  $this->addAppraiseeInfo($info);
97 
98  // handle (anonymous) code
99 
100  try {
101  $this->run_manager->initSession($this->requested_code);
102  } catch (\ilWrongSurveyCodeException $e) {
103  $this->main_tpl->setOnScreenMessage("failure", $e->getMessage(), true);
104  $this->ctrl->redirect($this->survey_gui, "infoScreen");
105  }
106  $anonymous_code = $this->run_manager->getCode();
107 
108  // completed message
109  if ($this->status_manager->cantStartAgain()) {
110  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("already_completed_survey"));
111  }
112 
113  $separator = false;
114 
115  // view results button
116  if ($this->status_manager->canViewUserResults()) {
117  $button = \ilLinkButton::getInstance();
118  $button->setCaption("svy_view_own_results");
119  $button->setUrl($this->ctrl->getLinkTarget($this->survey_gui, "viewUserResults"));
120  $toolbar->addButtonInstance($button);
121  $separator = true;
122  }
123 
124  // confirmation mail button / input
125  if ($this->status_manager->canMailUserResults()) {
126  if ($separator) {
127  $toolbar->addSeparator();
128  }
129 
130  if (!$user->getEmail()) {
131  $mail = new \ilTextInputGUI($this->lng->txt("email"), "mail");
132  $mail->setSize(25);
133  $mail->setValue($user->getEmail());
134  $toolbar->addInputItem($mail, true);
135  }
136 
137  $toolbar->setFormAction($this->ctrl->getFormAction($this->survey_gui, "mailUserResults"));
138 
139  $button = \ilSubmitButton::getInstance();
140  $button->setCaption("svy_mail_send_confirmation");
141  $button->setCommand("mailUserResults");
142  $toolbar->addButtonInstance($button);
143  }
144 
145  $this->displayNotStartableReasons($info);
146 
147  if ($status_manager->mustEnterCode($anonymous_code)) {
148  $info->setFormAction($this->ctrl->getFormAction($this->survey_gui, "infoScreen"));
149  $info->addSection($this->lng->txt("anonymization"));
150  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
151  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", "8", "infoScreen", $this->lng->txt("submit"), true);
152  }
153 
154  // display start / resume links/buttons
155  $this->addStartResumeSection($info, $anonymous_code, $output_gui);
156 
157  if ($status_manager->canAddItselfAsAppraisee()) { // #14968
158  $link = $this->ctrl->getLinkTargetByClass("ilsurveyparticipantsgui", "addSelfAppraisee");
159  $toolbar->addButton(
160  $this->lng->txt("survey_360_add_self_appraisee"),
161  $link
162  );
163  }
164 
165  //if ($big_button) {
166  /*
167  $toolbar->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
168 
169  $toolbar->setCloseFormTag(false);
170  $info->setOpenFormTag(false);*/
171  //}
172  /* #12016
173  else
174  {
175  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
176  }
177  */
178  $toolbar->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
179 
180  // introduction
181  if ($survey->getIntroduction() !== '') {
182  $introduction = $survey->getIntroduction();
183  $info->addSection($this->lng->txt("introduction"));
184  $info->addProperty("", $survey->prepareTextareaOutput($introduction) .
185  "<br />" . $info->getHiddenToggleButton());
186  } else {
187  $info->addSection($this->lng->txt("show_details"));
188  $info->addProperty("", $info->getHiddenToggleButton());
189  }
190 
191  $info->hideFurtherSections(false);
192 
193  if (!$this->feature_config->usesAppraisees()) {
194  $info->addSection($this->lng->txt("svy_general_properties"));
195 
196  $info->addProperty(
197  $this->lng->txt("survey_results_anonymization"),
198  !$survey->hasAnonymizedResults()
199  ? $this->lng->txt("survey_results_personalized_info")
200  : $this->lng->txt("survey_results_anonymized_info")
201  );
202 
203  if ($this->access_manager->canAccessEvaluation()) {
204  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
205  }
206  }
207 
208  $info->addMetaDataSections($survey->getId(), 0, $survey->getType());
209 
210  return $info;
211  }
212 
218  protected function addStartResumeSection(
219  \ilInfoScreenGUI $info,
220  string $anonymous_code,
221  $output_gui
222  ): void {
223  $survey = $this->survey;
224 
225  $status_manager = $this->status_manager;
226  if ($this->access_manager->canStartSurvey() &&
227  !$status_manager->mustEnterCode($anonymous_code)) {
228  if (!$this->feature_config->usesAppraisees()) {
229  if ($anonymous_code) {
230  $info->addHiddenElement("anonymous_id", $anonymous_code);
231  }
232  $big_button = false;
233  if ($this->run_manager->hasStarted() &&
234  !$this->run_manager->hasFinished()) {
235  $big_button = array("resume", $this->lng->txt("resume_survey"));
236  } elseif (!$this->run_manager->hasStarted()) {
237  $big_button = array("start", $this->lng->txt("start_survey"));
238  }
239  if ($big_button) {
240  $button = \ilSubmitButton::getInstance();
241  $button->setCaption($big_button[1], false);
242  $button->setCommand($big_button[0]);
243  $button->setPrimary(true);
244  $this->toolbar->addButtonInstance($button);
245  }
246  } else {
247 
248  // list appraisees
249  $appr_ids = array();
250 
251  // use given code (if proper external one)
252  if ($anonymous_code) {
253  $anonymous_id = $survey->getAnonymousIdByCode($anonymous_code);
254  if ($anonymous_id) {
255  $appr_ids = $survey->getAppraiseesToRate(0, $anonymous_id);
256  }
257  }
258 
259  // registered user
260  // if an auto-code was generated, we still have to check for the original user id
261  if (!$appr_ids && $this->user->getId() !== ANONYMOUS_USER_ID) {
262  $appr_ids = $survey->getAppraiseesToRate($this->user->getId());
263  }
264 
265  if (count($appr_ids)) {
266  // map existing runs to appraisees
267  $active_appraisees = array();
268  foreach ($this->run_manager
269  ->getRunsForUser($this->user->getId(), $anonymous_code) as $item) {
270  $active_appraisees[$item->getAppraiseeId()] = $item->getFinished();
271  }
272 
273  $list = array();
274  foreach ($appr_ids as $appr_id) {
275  if ($survey->isAppraiseeClosed($appr_id)) {
276  // closed
277  $list[$appr_id] = $this->lng->txt("survey_360_appraisee_is_closed");
278  } elseif (array_key_exists($appr_id, $active_appraisees)) {
279  // already done
280  if ($active_appraisees[$appr_id]) {
281  $list[$appr_id] = $this->lng->txt("already_completed_survey");
282  }
283  // resume
284  else {
285  $list[$appr_id] = array("resume", $this->lng->txt("resume_survey"));
286  }
287  } else {
288  // start
289  $list[$appr_id] = array("start", $this->lng->txt("start_survey"));
290  }
291  }
292 
293  $info->addSection($this->lng->txt("survey_360_rate_other_appraisees"));
294 
295  if (!$this->status_manager->isAppraisee()) {
296  $this->addPrivacyInfo($info);
297  }
298 
299  foreach ($list as $appr_id => $item) {
300  $appr_name = \ilUserUtil::getNamePresentation($appr_id, false, false, "", true);
301 
302  if (!is_array($item)) {
303  $info->addProperty($appr_name, $item);
304  } else {
305  $this->ctrl->setParameter($output_gui, "appr_id", $appr_id);
306  $href = $this->ctrl->getLinkTarget($output_gui, $item[0]);
307  $this->ctrl->setParameter($output_gui, "appr_id", "");
308 
309  $button = \ilLinkButton::getInstance();
310  $button->setCaption($item[1], false);
311  $button->setUrl($href);
312  $big_button_360 = '<div>' . $button->render() . '</div>';
313 
314  $info->addProperty($appr_name, $big_button_360);
315  }
316  }
317  } elseif (!$status_manager->isAppraisee()) {
318  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("survey_360_no_appraisees"));
319  }
320  }
321  }
322  }
323 
324  protected function addPrivacyInfo(
325  \ilInfoScreenGUI $info
326  ): void {
327  $survey = $this->survey;
328  $privacy_info = $this->lng->txt("svy_rater_see_app_info");
329  if (in_array($survey->get360Results(), [\ilObjSurvey::RESULTS_360_OWN, \ilObjSurvey::RESULTS_360_ALL], true)) {
330  $privacy_info .= " " . $this->lng->txt("svy_app_see_rater_info");
331  }
332  $info->addProperty($this->lng->txt("svy_privacy_info"), $privacy_info);
333  }
334 
335  protected function addAppraiseeInfo(
336  \ilInfoScreenGUI $info
337  ): void {
338  $survey = $this->survey;
339  if ($this->status_manager->isAppraisee()) {
340  $info->addSection($this->lng->txt("survey_360_appraisee_info"));
341 
342  $this->addPrivacyInfo($info);
343 
344  $appr_data = $survey->getAppraiseesData();
345  $appr_data = $appr_data[$this->user->getId()];
346  $info->addProperty($this->lng->txt("survey_360_raters_status_info"), $appr_data["finished"]);
347 
348  if ($survey->get360Mode()) {
349  if (!$appr_data["closed"]) {
350  $button = \ilLinkButton::getInstance();
351  $button->setCaption("survey_360_appraisee_close_action");
352  $button->setUrl($this->ctrl->getLinkTargetByClass(
353  "ilsurveyparticipantsgui",
354  "confirmappraiseeclose"
355  ));
356  $close_button_360 = '<div>' . $button->render() . '</div>';
357 
358  $txt = "survey_360_appraisee_close_action_info";
359  if ($survey->getSkillService()) {
360  $txt .= "_skill";
361  }
362  $info->addProperty(
363  $this->lng->txt("status"),
364  $close_button_360 . $this->lng->txt($txt)
365  );
366  } else {
368 
369  $dt = new \ilDateTime($appr_data["closed"], IL_CAL_UNIX);
370  $info->addProperty(
371  $this->lng->txt("status"),
372  sprintf(
373  $this->lng->txt("survey_360_appraisee_close_action_status"),
375  )
376  );
377  }
378  }
379  }
380  }
381 
382  protected function displayNotStartableReasons(\ilInfoScreenGUI $info): void
383  {
384  $survey = $this->survey;
385 
386  $links = [];
387 
388  if (!$this->access_manager->canStartSurvey() &&
389  $this->access_manager->canEditSettings()) {
390  $messages = [];
391 
392  if (!$survey->hasStarted()) {
393  $messages[] = $this->lng->txt('start_date_not_reached') . ' (' .
395  $survey->getStartDate(),
397  )) . ")";
398  }
399 
400  if ($survey->hasEnded()) {
401  $messages[] = $this->lng->txt('end_date_reached') . ' (' .
402  \ilDatePresentation::formatDate(new \ilDateTime($survey->getEndDate(), IL_CAL_TIMESTAMP)) . ")";
403  }
404 
405  if ($survey->getOfflineStatus()) {
406  $messages[] = $this->lng->txt("survey_is_offline");
407  }
408 
409  if (count($messages) > 0) {
410  $links[] = $this->ui->factory()->link()->standard(
411  $this->lng->txt("survey_edit_settings"),
412  $this->ctrl->getLinkTarget($this->survey_gui, "properties")
413  );
414  $mbox = $this->ui->factory()->messageBox()->info(implode("<br />", $messages));
415  if (count($links) > 0) {
416  $mbox = $mbox->withLinks($links);
417  }
418  $info->setMessageBox($mbox);
419  }
420  }
421  }
422 }
Info screen wrapper for the survey.
addStartResumeSection(\ilInfoScreenGUI $info, string $anonymous_code, $output_gui)
Add start/resume buttons or appraisee list to info screen.
Class ilInfoScreenGUI.
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...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
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...
const IL_CAL_UNIX
displayNotStartableReasons(\ilInfoScreenGUI $info)
global $DIC
Definition: feed.php:28
Class ilObjSurveyGUI.
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
addHiddenElement(string $a_name, string $a_value)
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
addSection(string $a_title)
$txt
Definition: error.php:13
ILIAS Survey Mode FeatureConfig $feature_config
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Survey Run Note: The manager should get the current user id passed.
Participants StatusManager $status_manager
const IL_CAL_TIMESTAMP
static setUseRelativeDates(bool $a_status)
set use relative dates
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMessageBox(ILIAS\UI\Component\MessageBox\MessageBox $a_val)