ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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\Survey\InternalGUIService $gui;
37  protected \ILIAS\DI\UIServices $ui;
38  protected \ilObjSurvey $survey;
39  protected \ilObjUser $user;
40  protected \ilToolbarGUI $toolbar;
41  protected \ilObjSurveyGUI $survey_gui;
45  protected ServerRequestInterface $request;
46  protected string $requested_code;
47  protected \ILIAS\Survey\Mode\FeatureConfig $feature_config;
48  protected \ilLanguage $lng;
49  protected \ilCtrl $ctrl;
50  private \ilGlobalTemplateInterface $main_tpl;
51 
52  public function __construct(
53  \ilObjSurveyGUI $survey_gui,
54  \ilToolbarGUI $toolbar,
55  \ilObjUser $user,
56  \ilLanguage $lng,
57  \ilCtrl $ctrl,
58  ServerRequestInterface $request,
59  InternalDomainService $domain_service
60  ) {
61  global $DIC;
62  $this->main_tpl = $DIC->ui()->mainTemplate();
63  $this->user = $user;
64  $this->toolbar = $toolbar;
65  $this->survey_gui = $survey_gui;
66  $this->ui = $DIC->ui();
68  $survey = $survey_gui->getObject();
69  $this->survey = $survey;
70  $this->status_manager = $domain_service->participants()->status($this->survey, $user->getId());
71  $this->access_manager = $domain_service->access($this->survey->getRefId(), $user->getId());
72  $this->run_manager = $domain_service->execution()->run($this->survey, $user->getId());
73  $this->feature_config = $domain_service->modeFeatureConfig($this->survey->getMode());
74 
75  $this->lng = $lng;
76  $this->ctrl = $ctrl;
77 
78  $body = $request->getParsedBody();
79  $this->requested_code = (string) ($body["anonymous_id"] ?? "");
80  $this->gui = $DIC->survey()->internal()->gui();
81  }
82 
83  public function getInfoScreenGUI(): \ilInfoScreenGUI
84  {
85  $user = $this->user;
86  $toolbar = $this->toolbar;
87  $status_manager = $this->status_manager;
88  $survey = $this->survey;
89 
90  $external_rater = $status_manager->isExternalRater();
91 
92  $output_gui = new \ilSurveyExecutionGUI($survey);
93 
94  $info = new \ilInfoScreenGUI($this->survey_gui);
95  $info->enablePrivateNotes();
96 
97  // appraisee infos
98  $this->addAppraiseeInfo($info);
99 
100  // handle (anonymous) code
101 
102  try {
103  $this->run_manager->initSession($this->requested_code);
104  } catch (\ilWrongSurveyCodeException $e) {
105  $this->main_tpl->setOnScreenMessage("failure", $e->getMessage(), true);
106  $this->ctrl->redirect($this->survey_gui, "infoScreen");
107  }
108  $anonymous_code = $this->run_manager->getCode();
109 
110  // completed message
111  if ($this->status_manager->cantStartAgain()) {
112  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("already_completed_survey"));
113  }
114 
115  $separator = false;
116 
117  // view results button
118  if ($this->status_manager->canViewUserResults()) {
119  $this->gui->link(
120  $this->lng->txt("svy_view_own_results"),
121  $this->ctrl->getLinkTarget($this->survey_gui, "viewUserResults")
122  )->toToolbar();
123  $separator = true;
124  }
125 
126  // confirmation mail button / input
127  if ($this->status_manager->canMailUserResults()) {
128  if ($separator) {
129  $toolbar->addSeparator();
130  }
131 
132  if (!$user->getEmail()) {
133  $mail = new \ilTextInputGUI($this->lng->txt("email"), "mail");
134  $mail->setSize(25);
135  $mail->setValue($user->getEmail());
136  $toolbar->addInputItem($mail, true);
137  }
138 
139  $toolbar->setFormAction($this->ctrl->getFormAction($this->survey_gui, "mailUserResults"));
140 
141  $this->gui->button(
142  $this->lng->txt("svy_mail_send_confirmation"),
143  "mailUserResults"
144  )->submit()->toToolbar();
145  }
146 
147  $this->displayNotStartableReasons($info);
148 
149  if ($status_manager->mustEnterCode($anonymous_code)) {
150  $info->setFormAction($this->ctrl->getFormAction($this->survey_gui, "infoScreen"));
151  $info->addSection($this->lng->txt("anonymization"));
152  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
153  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", "8", "infoScreen", $this->lng->txt("submit"), true);
154  }
155 
156  // display start / resume links/buttons
157  $this->addStartResumeSection($info, $anonymous_code, $output_gui);
158 
159  if ($status_manager->canAddItselfAsAppraisee()) { // #14968
160  $link = $this->ctrl->getLinkTargetByClass("ilsurveyparticipantsgui", "addSelfAppraisee");
161  $toolbar->addButton(
162  $this->lng->txt("survey_360_add_self_appraisee"),
163  $link
164  );
165  }
166 
167  //if ($big_button) {
168  /*
169  $toolbar->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
170 
171  $toolbar->setCloseFormTag(false);
172  $info->setOpenFormTag(false);*/
173  //}
174  /* #12016
175  else
176  {
177  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
178  }
179  */
180  $toolbar->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
181 
182  // introduction
183  if ($survey->getIntroduction() !== '') {
184  $introduction = $survey->getIntroduction();
185  $info->addSection($this->lng->txt("introduction"));
186  $info->addProperty("", $survey->prepareTextareaOutput($introduction) .
187  "<br />" . $info->getHiddenToggleButton());
188  } else {
189  $info->addSection($this->lng->txt("show_details"));
190  $info->addProperty("", $info->getHiddenToggleButton());
191  }
192 
193  $info->hideFurtherSections(false);
194 
195  if (!$this->feature_config->usesAppraisees()) {
196  $info->addSection($this->lng->txt("svy_general_properties"));
197 
198  $info->addProperty(
199  $this->lng->txt("survey_results_anonymization"),
200  !$survey->hasAnonymizedResults()
201  ? $this->lng->txt("survey_results_personalized_info")
202  : $this->lng->txt("survey_results_anonymized_info")
203  );
204 
205  if ($this->access_manager->canAccessEvaluation()) {
206  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
207  }
208  }
209 
210  $info->addMetaDataSections($survey->getId(), 0, $survey->getType());
211 
212  return $info;
213  }
214 
220  protected function addStartResumeSection(
221  \ilInfoScreenGUI $info,
222  string $anonymous_code,
223  $output_gui
224  ): void {
225  $survey = $this->survey;
226 
227  $status_manager = $this->status_manager;
228  if ($this->access_manager->canStartSurvey() &&
229  !$status_manager->mustEnterCode($anonymous_code)) {
230  if (!$this->feature_config->usesAppraisees()) {
231  if ($anonymous_code) {
232  $info->addHiddenElement("anonymous_id", $anonymous_code);
233  }
234  $big_button = false;
235  if ($this->run_manager->hasStarted() &&
236  !$this->run_manager->hasFinished()) {
237  $big_button = array("resume", $this->lng->txt("resume_survey"));
238  } elseif (!$this->run_manager->hasStarted()) {
239  $big_button = array("start", $this->lng->txt("start_survey"));
240  }
241  if ($big_button) {
242  $this->gui->button(
243  $big_button[1],
244  $big_button[0]
245  )->primary()->submit()->toToolbar();
246  }
247  } else {
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 = $this->gui->button(
310  $item[1],
311  $href
312  );
313  $big_button_360 = '<div>' . $button->render() . '</div>';
314 
315  $info->addProperty($appr_name, $big_button_360);
316  }
317  }
318  } elseif (!$status_manager->isAppraisee()) {
319  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("survey_360_no_appraisees"));
320  }
321  }
322  }
323  }
324 
325  protected function addPrivacyInfo(
326  \ilInfoScreenGUI $info
327  ): void {
328  $survey = $this->survey;
329  $privacy_info = $this->lng->txt("svy_rater_see_app_info");
330  if (in_array($survey->get360Results(), [\ilObjSurvey::RESULTS_360_OWN, \ilObjSurvey::RESULTS_360_ALL], true)) {
331  $privacy_info .= " " . $this->lng->txt("svy_app_see_rater_info");
332  }
333  $info->addProperty($this->lng->txt("svy_privacy_info"), $privacy_info);
334  }
335 
336  protected function addAppraiseeInfo(
337  \ilInfoScreenGUI $info
338  ): void {
339  $survey = $this->survey;
340  if ($this->status_manager->isAppraisee()) {
341  $info->addSection($this->lng->txt("survey_360_appraisee_info"));
342 
343  $this->addPrivacyInfo($info);
344 
345  $appr_data = $survey->getAppraiseesData();
346  $appr_data = $appr_data[$this->user->getId()];
347  $info->addProperty($this->lng->txt("survey_360_raters_status_info"), $appr_data["finished"]);
348 
349  if ($survey->get360Mode()) {
350  if (!$appr_data["closed"]) {
351  $button = $this->gui->button(
352  $this->lng->txt("survey_360_appraisee_close_action"),
353  $this->ctrl->getLinkTargetByClass(
354  "ilsurveyparticipantsgui",
355  "confirmappraiseeclose"
356  )
357  );
358  $close_button_360 = '<div>' . $button->render() . '</div>';
359 
360  $txt = "survey_360_appraisee_close_action_info";
361  if ($survey->getSkillService()) {
362  $txt .= "_skill";
363  }
364  $info->addProperty(
365  $this->lng->txt("status"),
366  $close_button_360 . $this->lng->txt($txt)
367  );
368  } else {
370 
371  $dt = new \ilDateTime($appr_data["closed"], IL_CAL_UNIX);
372  $info->addProperty(
373  $this->lng->txt("status"),
374  sprintf(
375  $this->lng->txt("survey_360_appraisee_close_action_status"),
377  )
378  );
379  }
380  }
381  }
382  }
383 
384  protected function displayNotStartableReasons(\ilInfoScreenGUI $info): void
385  {
386  $survey = $this->survey;
387 
388  $links = [];
389 
390  if (!$this->access_manager->canStartSurvey() &&
391  $this->access_manager->canEditSettings()) {
392  $messages = [];
393 
394  if (!$survey->hasStarted()) {
395  $messages[] = $this->lng->txt('start_date_not_reached') . ' (' .
397  $survey->getStartDate(),
399  )) . ")";
400  }
401 
402  if ($survey->hasEnded()) {
403  $messages[] = $this->lng->txt('end_date_reached') . ' (' .
404  \ilDatePresentation::formatDate(new \ilDateTime($survey->getEndDate(), IL_CAL_TIMESTAMP)) . ")";
405  }
406 
407  if ($survey->getOfflineStatus()) {
408  $messages[] = $this->lng->txt("survey_is_offline");
409  }
410 
411  if (count($messages) > 0) {
412  $links[] = $this->ui->factory()->link()->standard(
413  $this->lng->txt("survey_edit_settings"),
414  $this->ctrl->getLinkTarget($this->survey_gui, "properties")
415  );
416  $mbox = $this->ui->factory()->messageBox()->info(implode("<br />", $messages));
417  if (count($links) > 0) {
418  $mbox = $mbox->withLinks($links);
419  }
420  $info->setMessageBox($mbox);
421  }
422  }
423  }
424 }
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...
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)
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:
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
addSection(string $a_title)
$txt
Definition: error.php:14
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
ILIAS Survey InternalGUIService $gui
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)