ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjSurveyGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
36 {
37  protected \ILIAS\Survey\Execution\ExecutionGUIRequest $execution_request;
40  protected ilTabsGUI $tabs;
41  protected ilHelpGUI $help;
42  protected ilLogger $log;
43  protected Participants\InvitationsManager $invitation_manager;
44  protected \ILIAS\Survey\InternalService $survey_service;
47  protected \ILIAS\Survey\Execution\RunManager $run_manager;
48  protected \ILIAS\Survey\Participants\StatusManager $status_manager;
49  protected ?ilObjSurvey $survey = null;
52 
53  public function __construct()
54  {
55  global $DIC;
56 
57  $this->user = $DIC->user();
58  $this->survey_service = $DIC->survey()->internal();
59 
60  $this->lng = $DIC->language();
61  $this->nav_history = $DIC["ilNavigationHistory"];
62  $this->tabs = $DIC->tabs();
63  $this->help = $DIC["ilHelp"];
64  $this->rbacsystem = $DIC->rbac()->system();
65  $this->tree = $DIC->repositoryTree();
66  $this->tpl = $DIC["tpl"];
67  $this->toolbar = $DIC->toolbar();
68  $this->access = $DIC->access();
69  $this->locator = $DIC["ilLocator"];
70  $this->senderFactory = $DIC->mail()->mime()->senderFactory();
71  $lng = $DIC->language();
72  $ilCtrl = $DIC->ctrl();
73 
74  $this->type = "svy";
75  $lng->loadLanguageModule("survey");
76  $lng->loadLanguageModule("svy");
77  $this->ctrl = $ilCtrl;
78  $this->ctrl->saveParameter($this, "ref_id");
79 
80  $this->log = ilLoggerFactory::getLogger("svy");
81 
82  $this->invitation_manager = $this->survey_service->domain()->participants()->invitations();
83 
84  $this->execution_request = $this->survey_service
85  ->gui()
86  ->execution()
87  ->request();
88 
89  parent::__construct("", $this->execution_request->getRefId(), true, false);
90 
91  if ($this->object->getType() !== "svy") {
92  $this->setCreationMode(true);
93  }
94  if ($this->object && $this->object->getType() === "svy") {
96  $survey = $this->object;
97  $this->survey = $survey;
98 
99  $this->status_manager = $this->survey_service
100  ->domain()
101  ->participants()
102  ->status($survey, $this->user->getId());
103  $this->feature_config = $this->survey_service->domain()
104  ->modeFeatureConfig($this->object->getMode());
105  $this->run_manager = $this->survey_service->domain()
106  ->execution()->run($survey, $this->user->getId());
107  $this->access_manager = $this->survey_service
108  ->domain()
109  ->access($this->requested_ref_id, $this->user->getId());
110  }
111  $this->edit_request = $this->survey_service
112  ->gui()
113  ->editing()
114  ->request();
115 
116  // this class will be treated as a baseclass in most cases, therefore
117  // we need to claim the repository context manually. see #37010
118  if (!$DIC->globalScreen()->tool()->context()->stack()->hasMatch(
119  $DIC->globalScreen()->tool()->context()->collection()->repository()
120  )) {
121  $DIC->globalScreen()->tool()->context()->claim()->repository();
122  }
123  }
124 
125  public function executeCommand(): void
126  {
127  $ilTabs = $this->tabs;
128  $access_manager = $this->access_manager;
129  $survey = $this->survey;
130  if ($survey) {
131  if (!$access_manager->canAccessInfoScreen()) {
132  $this->noPermission();
133  }
134  $this->addToNavigationHistory();
135  }
136 
137  $cmd = $this->ctrl->getCmd("properties");
138 
139  // workaround for bug #6288, needs better solution
140  if ($cmd === "saveTags") {
141  $this->ctrl->setCmdClass("ilinfoscreengui");
142  }
143 
144  // deep link from repository - "redirect" to page view
145  if (!$this->ctrl->getCmdClass() && $cmd === "questionsrepo") {
146  $this->ctrl->setParameterByClass("ilsurveyeditorgui", "pgov", "1");
147  $this->ctrl->redirectByClass("ilsurveyeditorgui", "questions");
148  }
149 
150  $next_class = $this->ctrl->getNextClass($this);
151  if ($next_class !== "") {
152  $this->ctrl->setReturn($this, "properties");
153  }
154  // deprecated, moved for less file
155  //$this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
156  $this->prepareOutput();
157 
158  $this->log->debug("next_class= $next_class");
159  switch ($next_class) {
160  case 'illtiproviderobjectsettinggui':
161  $this->addSubTabs('settings');
162  $ilTabs->activateTab("settings");
163  $ilTabs->activateSubTab('lti_provider');
164  $lti_gui = new ilLTIProviderObjectSettingGUI($this->object->getRefId());
165  $lti_gui->setCustomRolesForSelection($GLOBALS['DIC']->rbac()->review()->getLocalRoles($this->object->getRefId()));
166  $lti_gui->offerLTIRolesForSelection(false);
167  $this->ctrl->forwardCommand($lti_gui);
168  break;
169 
170 
171  case "ilinfoscreengui":
172  if (!in_array(
173  $this->ctrl->getCmdClass(),
174  array('ilpublicuserprofilegui', 'ilobjportfoliogui')
175  )) {
176  $this->addHeaderAction();
177  $this->infoScreen(); // forwards command
178  } else {
179  // #16891
180  $ilTabs->clearTargets();
181  $info = new ilInfoScreenGUI($this);
182  $this->ctrl->forwardCommand($info);
183  }
184  break;
185 
186  case 'ilobjectmetadatagui':
187  $this->checkPermission("write");
188  $ilTabs->activateTab("meta_data");
189  $this->addHeaderAction();
190  $md_gui = new ilObjectMetaDataGUI($this->object);
191  $this->ctrl->forwardCommand($md_gui);
192  break;
193 
194  case "ilsurveyevaluationgui":
195 
196  if ($this->checkRbacOrPositionPermission('read_results', 'access_results') ||
197  ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $this->user->getId())) {
198  $ilTabs->activateTab("svy_results");
199  $this->addHeaderAction();
200  $eval_gui = new ilSurveyEvaluationGUI($survey);
201  $this->ctrl->forwardCommand($eval_gui);
202  }
203  break;
204 
205  case "ilsurveyexecutiongui":
206  $ilTabs->clearTargets();
207  $exec_gui = new ilSurveyExecutionGUI($survey);
208  $this->ctrl->forwardCommand($exec_gui);
209  break;
210 
211  case 'ilpermissiongui':
212  $ilTabs->activateTab("perm_settings");
213  $this->addHeaderAction();
214  $perm_gui = new ilPermissionGUI($this);
215  $this->ctrl->forwardCommand($perm_gui);
216  break;
217 
218  case 'ilobjectcopygui':
219  $cp = new ilObjectCopyGUI($this);
220  $cp->setType('svy');
221  $this->ctrl->forwardCommand($cp);
222  break;
223 
224  case "ilcommonactiondispatchergui":
226  $this->ctrl->forwardCommand($gui);
227  break;
228 
229  // 360, skill service
230  case 'ilsurveyskillgui':
231  $ilTabs->activateTab("survey_competences");
232  $gui = new ilSurveySkillGUI($survey);
233  $this->ctrl->forwardCommand($gui);
234  break;
235 
236  case 'ilsurveyskilldeterminationgui':
237  $ilTabs->activateTab("maintenance");
238  $gui = new ilSurveySkillDeterminationGUI($survey);
239  $this->ctrl->forwardCommand($gui);
240  break;
241 
242  case 'ilsurveyeditorgui':
243  $this->checkPermission("write");
244  $ilTabs->activateTab("survey_questions");
245  $gui = new ilSurveyEditorGUI($this);
246  $this->ctrl->forwardCommand($gui);
247  break;
248 
249  case 'ilsurveyconstraintsgui':
250  $this->checkPermission("write");
251  $ilTabs->activateTab("constraints");
252  $gui = new ilSurveyConstraintsGUI($this);
253  $this->ctrl->forwardCommand($gui);
254  break;
255 
256  case 'ilsurveyparticipantsgui':
257  if (!$this->feature_config->usesAppraisees()) {
258  $ilTabs->activateTab("maintenance");
259  } else {
260  $ilTabs->activateTab("survey_360_appraisees");
261  }
262  $gui = new ilSurveyParticipantsGUI($this, $this->checkRbacOrPositionPermission('read_results', 'access_results'));
263  $this->ctrl->forwardCommand($gui);
264  break;
265 
266  case "illearningprogressgui":
267  $ilTabs->activateTab("learning_progress");
268  $new_gui = new ilLearningProgressGUI(
270  $this->object->getRefId()
271  );
272  $this->ctrl->forwardCommand($new_gui);
273  break;
274 
275  case 'ilexportgui':
276  $ilTabs->activateTab("export");
277  $exp_gui = new ilExportGUI($this);
278  $exp_gui->addFormat("xml");
279  $this->ctrl->forwardCommand($exp_gui);
280  break;
281 
282  default:
283  $this->addHeaderAction();
284  $cmd .= "Object";
285 
286  $this->log->debug("Default cmd= $cmd");
287 
288  $this->$cmd();
289  break;
290  }
291 
292  if (strtolower($this->edit_request->getBaseClass()) !== "iladministrationgui" &&
293  $this->getCreationMode() !== true) {
294  $this->tpl->printToStdout();
295 
296  //cherry pick conflict with d97cf1c77b
297  //$this->tpl->show();
298  //$this->log->debug("after tpl show");
299  }
300  }
301 
302  protected function noPermission(): void
303  {
304  throw new ilObjectException($this->lng->txt("permission_denied"));
305  }
306 
307  protected function addToNavigationHistory(): void
308  {
309  $external_rater = $this->status_manager->isExternalRater();
310  // add entry to navigation history
311  if (!$external_rater && !$this->getCreationMode() &&
312  $this->checkPermissionBool("read")) {
313  $this->ctrl->setParameterByClass("ilobjsurveygui", "ref_id", $this->ref_id);
314  $link = $this->ctrl->getLinkTargetByClass("ilobjsurveygui", "infoScreen");
315  $this->nav_history->addItem($this->ref_id, $link, "svy");
316  }
317  }
318 
323  public function evaluationObject(): void
324  {
325  $eval_gui = new ilSurveyEvaluationGUI($this->survey);
326  $this->ctrl->setCmdClass(get_class($eval_gui));
327  $this->ctrl->redirect($eval_gui, "openEvaluation");
328  }
329 
330  protected function addDidacticTemplateOptions(array &$a_options): void
331  {
332  // JF, 2013-06-10
333  $a_options["svy360_1"] = array($this->lng->txt("survey_360_mode"),
334  $this->lng->txt("survey_360_mode_info"));
335 
336  //Self evaluation only
337  $a_options["svyselfeval_1"] = array($this->lng->txt("svy_self_ev_mode"),
338  $this->lng->txt("svy_self_ev_info"));
339 
340  // individual feedback
341  $a_options["individfeedb_1"] = array($this->lng->txt("svy_ind_feedb_mode"),
342  $this->lng->txt("svy_ind_feedb_info"));
343  }
344 
345  protected function afterSave(ilObject $new_object): void
346  {
347  // #16446
348  $new_object->loadFromDb();
349 
350  //set the mode depending on didactic template
351  if ($this->getDidacticTemplateVar("svy360")) {
352  $new_object->setMode(ilObjSurvey::MODE_360);
353  } elseif ($this->getDidacticTemplateVar("svyselfeval")) {
354  $new_object->setMode(ilObjSurvey::MODE_SELF_EVAL);
355  } elseif ($this->getDidacticTemplateVar("individfeedb")) {
356  $new_object->setMode(ilObjSurvey::MODE_IND_FEEDB);
357  }
358 
359  $svy_mode = $new_object->getMode();
360  if ($svy_mode === ilObjSurvey::MODE_360) {
361  // this should rather be ilObjSurvey::ANONYMIZE_ON - see ilObjSurvey::getUserDataFromActiveId()
362  $new_object->setAnonymize(ilObjSurvey::ANONYMIZE_CODE_ALL);
363  $new_object->setEvaluationAccess(ilObjSurvey::EVALUATION_ACCESS_PARTICIPANTS);
364  } elseif ($svy_mode === ilObjSurvey::MODE_SELF_EVAL) {
365  $new_object->setEvaluationAccess(ilObjSurvey::EVALUATION_ACCESS_PARTICIPANTS);
366  }
367  $new_object->saveToDB();
368 
369  // always send a message
370  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
371  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" .
372  $new_object->getRefId() . "&cmd=properties");
373  }
374 
375  protected function getTabs(): void
376  {
377  $ilUser = $this->user;
378  $ilHelp = $this->help;
379  $feature_config = $this->feature_config;
380 
381  if (is_null($this->object)) {
382  return;
383  }
384 
385  // @todo investigate, if this can still be the case
386  if ($this->object instanceof ilObjSurveyQuestionPool) {
387  return;
388  }
389 
390  $ilHelp->setScreenIdComponent("svy");
391 
392  if ($this->checkPermissionBool("write")) {
393  $this->tabs_gui->addTab(
394  "survey_questions",
395  $this->lng->txt("survey_questions"),
396  $this->ctrl->getLinkTargetByClass(array("ilsurveyeditorgui"), "questions")
397  );
398  }
399 
400  if ($this->checkPermissionBool("read")) {
401  $this->tabs_gui->addTab(
402  "info_short",
403  $this->lng->txt("info_short"),
404  $this->ctrl->getLinkTarget($this, 'infoScreen')
405  );
406  }
407 
408  // properties
409  if ($this->checkPermissionBool("write")) {
410  $this->tabs_gui->addTab(
411  "settings",
412  $this->lng->txt("settings"),
413  $this->ctrl->getLinkTarget($this, 'properties')
414  );
415  } elseif ($this->checkPermissionBool("read")) {
416  if ($this->feature_config->usesAppraisees() &&
417  $this->object->get360SelfRaters() &&
418  $this->object->isAppraisee($ilUser->getId()) &&
419  !$this->object->isAppraiseeClosed($ilUser->getId())) {
420  $this->tabs_gui->addTab(
421  "survey_360_edit_raters",
422  $this->lng->txt("survey_360_edit_raters"),
423  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui', 'editRaters')
424  );
425 
426  // :TODO: mail to raters
427  }
428  }
429 
430  // questions
431  if ($this->checkPermissionBool("write") &&
432  $this->object->getMode() === ilObjSurvey::MODE_STANDARD) {
433  // constraints (tab called routing)
434  $this->tabs_gui->addTab(
435  "constraints",
436  $this->lng->txt("constraints"),
437  $this->ctrl->getLinkTargetByClass("ilsurveyconstraintsgui", "constraints")
438  );
439  }
440 
441  if ($this->checkPermissionBool("write")) {
442  if ($feature_config && $feature_config->supportsCompetences()) {
443  $skmg_set = new ilSkillManagementSettings();
444  if ($this->object->getSkillService() && $skmg_set->isActivated()) {
445  $this->tabs_gui->addTab(
446  "survey_competences",
447  $this->lng->txt("survey_competences"),
448  $this->ctrl->getLinkTargetByClass("ilsurveyskillgui", "listQuestionAssignment")
449  );
450  }
451  }
452 
453  if ($feature_config && $feature_config->usesAppraisees()) {
454  $this->tabs_gui->addTab(
455  "survey_360_appraisees",
456  $this->lng->txt("survey_360_appraisees"),
457  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui', 'listAppraisees')
458  );
459  } else {
460  $this->tabs_gui->addTab(
461  "maintenance",
462  $this->lng->txt("svy_participants"),
463  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui', 'maintenance')
464  );
465  }
466  }
467 
468  if ($this->access_manager->canAccessEvaluation()) {
469  // evaluation
470  $this->tabs_gui->addTab(
471  "svy_results",
472  $this->lng->txt("svy_results"),
473  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "openEvaluation")
474  );
475  }
476 
477  // learning progress
478  if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
479  $this->tabs_gui->addTarget(
480  "learning_progress",
481  $this->ctrl->getLinkTargetByClass(array("ilobjsurveygui", "illearningprogressgui"), ""),
482  "",
483  array("illplistofobjectsgui", "illplistofsettingsgui", "illearningprogressgui", "illplistofprogressgui")
484  );
485  }
486 
487  if ($this->checkPermissionBool("write")) {
488  // meta data
489  $mdgui = new ilObjectMetaDataGUI($this->object);
490  $mdtab = $mdgui->getTab();
491  if ($mdtab) {
492  $this->tabs_gui->addTab(
493  "meta_data",
494  $this->lng->txt("meta_data"),
495  $mdtab
496  );
497  }
498 
499  // export
500  $this->tabs_gui->addTab(
501  "export",
502  $this->lng->txt("export"),
503  $this->ctrl->getLinkTargetByClass("ilexportgui", "")
504  );
505  }
506 
507  if ($this->checkPermissionBool("edit_permission")) {
508  // permissions
509  $this->tabs_gui->addTab(
510  "perm_settings",
511  $this->lng->txt("perm_settings"),
512  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
513  );
514  }
515  }
516 
517 
518  //
519  // SETTINGS
520  //
521 
522  public function savePropertiesObject(): void
523  {
524  $settings_ui = $this->survey_service->gui()->surveySettings($this->survey);
525 
526  $form = $settings_ui->form("ilObjSurveyGUI");
527  if ($settings_ui->checkForm($form)) {
528  $settings_ui->saveForm($form);
529 
530  // settings change clear the code
531  // this is adopted from ILIAS 7, unsure if or when this is necessary
532  $this->run_manager->clearCode();
533 
534  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
535  $this->ctrl->redirect($this, "properties");
536  }
537 
538  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("form_input_not_valid"));
539  $form->setValuesByPost();
540  $this->propertiesObject($form);
541  }
542 
544  {
545  $form = $this->survey_service
546  ->gui()->surveySettings($this->survey)->form("ilObjSurveyGUI");
547  return $form;
548  }
549 
550  public function addSubTabs(
551  string $a_section
552  ): void {
553  if ($a_section === 'settings') {
554  $this->tabs_gui->addSubTabTarget(
555  "settings",
556  $this->ctrl->getLinkTarget($this, 'properties')
557  );
558 
559  $lti_settings = new ilLTIProviderObjectSettingGUI($this->object->getRefId());
560  if ($lti_settings->hasSettingsAccess()) {
561  $this->tabs_gui->addSubTabTarget(
562  'lti_provider',
563  $this->ctrl->getLinkTargetByClass(ilLTIProviderObjectSettingGUI::class)
564  );
565  }
566  }
567  }
568 
569 
573  public function propertiesObject(
574  ilPropertyFormGUI $a_form = null
575  ): void {
576  $ilTabs = $this->tabs;
577  $ilHelp = $this->help;
578 
579  $this->checkPermission("write");
580 
581  $this->addSubTabs('settings');
582  $ilTabs->activateTab("settings");
583  $ilTabs->activateSubTab('settings');
584 
585  if ($this->object->get360Mode()) {
586  $ilHelp->setScreenId("settings_360");
587  }
588 
589  if (!$a_form) {
590  $a_form = $this->initPropertiesForm();
591  }
592 
593  $this->tpl->setContent($a_form->getHTML());
594  }
595 
596  public function doAutoCompleteObject(): void
597  {
598  $fields = array('login','firstname','lastname','email');
599 
600  $auto = new ilUserAutoComplete();
601  $auto->setSearchFields($fields);
602  $auto->setResultField('login');
603  $auto->enableFieldSearchableCheck(true);
604  $auto->setMoreLinkAvailable(true);
605 
606  if ($this->edit_request->getFetchAll()) {
607  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
608  }
609 
610  echo $auto->getList(ilUtil::stripSlashes($this->edit_request->getTerm()));
611  exit();
612  }
613 
614  //
615  // IMPORT/EXPORT
616  //
617 
618  protected function initImportForm(string $new_type): ilPropertyFormGUI
619  {
620  $form = new ilPropertyFormGUI();
621  $form->setTarget("_top");
622  $form->setFormAction($this->ctrl->getFormAction($this));
623  $form->setTitle($this->lng->txt("import_svy"));
624 
625  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
626  $fi->setSuffixes(array("zip"));
627  $fi->setRequired(true);
628  $form->addItem($fi);
629 
630  $svy = new ilObjSurvey();
631  $questionspools = $svy->getAvailableQuestionpools(true, true, true);
632 
633  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool_short"), "spl");
634  $pools->setOptions(array("" => $this->lng->txt("dont_use_questionpool")) + $questionspools);
635  $pools->setRequired(false);
636  $form->addItem($pools);
637 
638  $form->addCommandButton("importSurvey", $this->lng->txt("import"));
639  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
640 
641  return $form;
642  }
643 
644  public function importSurveyObject(): void
645  {
646  $tpl = $this->tpl;
647 
648  $new_type = $this->edit_request->getNewType();
649 
650  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
651  $this->checkPermission("create", "", $new_type);
652 
653  $this->lng->loadLanguageModule($new_type);
654  $this->ctrl->setParameter($this, "new_type", $new_type);
655 
656  $form = $this->initImportForm($new_type);
657  if ($form->checkInput()) {
658  $newObj = new ilObjSurvey();
659  $newObj->setType($new_type);
660  $newObj->setTitle("dummy");
661  $newObj->create(true);
662  $this->putObjectInTree($newObj);
663 
664  // copy uploaded file to import directory
665 
666  $this->log->debug("form->getInput(spl) = " . $form->getInput("spl"));
667 
668  $error = $newObj->importObject($_FILES["importfile"], (int) $form->getInput("spl"));
669  if ($error !== '') {
670  $newObj->delete();
671  $this->tpl->setOnScreenMessage('failure', $error);
672  return;
673  }
674 
675  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_imported"), true);
676  ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() .
677  "&baseClass=ilObjSurveyGUI");
678  }
679 
680  // display form to correct errors
681  $form->setValuesByPost();
682  $tpl->setContent($form->getHTML());
683  }
684 
685 
686  //
687  // INFOSCREEN
688  //
689 
695  public function infoScreenObject(): void
696  {
697  $this->ctrl->setCmd("showSummary");
698  $this->ctrl->setCmdClass("ilinfoscreengui");
699  $this->infoScreen();
700  }
701 
705  public function infoScreen(): void
706  {
707  $ilTabs = $this->tabs;
708  if (!$this->access_manager->canAccessInfoScreen()) {
709  $this->noPermission();
710  }
711  $ilTabs->activateTab("info_short");
712 
713  $info = $this->survey_service->gui()->infoScreen($this, $this->toolbar);
714 
715  $this->ctrl->forwardCommand($info);
716  }
717 
718  protected function addLocatorItems(): void
719  {
720  $ilLocator = $this->locator;
721  switch ($this->ctrl->getCmd()) {
722  case "next":
723  case "previous":
724  case "start":
725  case "resume":
726  case "infoScreen":
727  case "redirectQuestion":
728  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $this->requested_ref_id);
729  break;
730  case "evaluation":
731  case "checkEvaluationAccess":
732  case "evaluationdetails":
733  case "evaluationuser":
734  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $this->requested_ref_id);
735  break;
736  case "create":
737  case "save":
738  case "cancel":
739  case "importSurvey":
740  case "cloneAll":
741  break;
742  default:
743  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $this->requested_ref_id);
744 
745  // this has to be done here because ilSurveyEditorGUI is called after finalizing the locator
746  if ($this->edit_request->getQuestionId() > 0 &&
747  !$this->edit_request->getNewForSurvey()) {
748  // not on create
749  // see ilObjSurveyQuestionPool::addLocatorItems
750  $q_id = $this->edit_request->getQuestionId();
751  $q_type = SurveyQuestion::_getQuestionType($q_id) . "GUI";
752  $this->ctrl->setParameterByClass($q_type, "q_id", $q_id);
753  $ilLocator->addItem(
755  $this->ctrl->getLinkTargetByClass(array("ilSurveyEditorGUI", $q_type), "editQuestion")
756  );
757  }
758  break;
759  }
760  }
761 
766  public static function _goto(
767  string $a_target
768  ): void {
769  global $DIC;
770  $main_tpl = $DIC->ui()->mainTemplate();
771 
772  $request = $DIC->survey()->internal()->gui()->execution()->request();
773  $a_access_code = $request->getAccessCode();
774 
775  $ilAccess = $DIC->access();
776  $lng = $DIC->language();
777  $ctrl = $DIC->ctrl();
778 
779  $t_arr = explode("_", $a_target);
780  $ref_id = (int) $t_arr[0];
781  if ($a_access_code === "" && isset($t_arr[1])) {
782  $a_access_code = $t_arr[1];
783  }
784  // see ilObjSurveyAccess::_checkGoto()
785  if ($a_access_code !== '') {
786  $sess = $DIC->survey()->internal()->repo()
787  ->execution()->runSession();
788  $sess->setCode(ilObject::_lookupObjId($ref_id), $a_access_code);
789  $ctrl->setParameterByClass("ilObjSurveyGUI", "ref_id", $ref_id);
790  $ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
791  }
792 
793  // write permission -> info screen
794  if ($ilAccess->checkAccess("write", "", $ref_id)) {
795  $ctrl->setParameterByClass("ilObjSurveyGUI", "ref_id", $ref_id);
796  $ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
797  }
798 
799  // read permission, evaluation access and finished run -> evaluation
800  if ($ilAccess->checkAccess("visible", "", $ref_id) ||
801  $ilAccess->checkAccess("read", "", $ref_id)) {
802  if ($ilAccess->checkAccess("read", "", $ref_id)) {
803  $domain_service = $DIC->survey()->internal()->domain();
804  $am = $domain_service->access($ref_id, $DIC->user()->getId());
805  $survey = new ilObjSurvey($ref_id);
806  $run_manager = $domain_service->execution()->run($survey, $DIC->user()->getId());
807  if ($am->canAccessEvaluation()) {
808  $ctrl->setParameterByClass("ilObjSurveyGUI", "ref_id", $ref_id);
809  $ctrl->redirectByClass(["ilObjSurveyGUI", "ilSurveyEvaluationGUI"], "openEvaluation");
810  }
811  }
812 
813  $ctrl->setParameterByClass("ilObjSurveyGUI", "ref_id", $ref_id);
814  $ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
815  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
816  $main_tpl->setOnScreenMessage('failure', sprintf(
817  $lng->txt("msg_no_perm_read_item"),
819  ), true);
821  }
822  }
823 
827  public function getUserResultsTable(
828  int $a_active_id
829  ): string {
830  $rtpl = new ilTemplate("tpl.svy_view_user_results.html", true, true, "Modules/Survey");
831 
832  $show_titles = $this->object->getShowQuestionTitles();
833 
834  foreach ($this->object->getSurveyPages() as $page) {
835  if (count($page) > 0) {
836  // question block
837  if (count($page) > 1) {
838  if ($page[0]["questionblock_show_blocktitle"]) {
839  $rtpl->setVariable("BLOCK_TITLE", trim($page[0]["questionblock_title"] ?? ""));
840  }
841  }
842 
843  // questions
844  foreach ($page as $question) {
845  $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
846  $rtpl->setCurrentBlock("question_bl");
847 
848  // heading
849  if (strlen($question["heading"] ?? "")) {
850  $rtpl->setVariable("HEADING", trim($question["heading"] ?? ""));
851  }
852 
853  $rtpl->setVariable(
854  "QUESTION_DATA",
855  $question_gui->getPrintView(
856  $show_titles,
857  (bool) $question["questionblock_show_questiontext"],
858  $this->object->getId(),
859  $this->object->loadWorkingData($question["question_id"], $a_active_id)
860  )
861  );
862 
863  $rtpl->parseCurrentBlock();
864  }
865 
866  $rtpl->setCurrentBlock("block_bl");
867  $rtpl->parseCurrentBlock();
868  }
869  }
870 
871  return $rtpl->get();
872  }
873 
877  protected function viewUserResultsObject(): void
878  {
879  $ilUser = $this->user;
880  $tpl = $this->tpl;
881  $ilTabs = $this->tabs;
882 
883  $anonymous_code = $this->run_manager->getCode();
884  $active_id = $this->object->getActiveID($ilUser->getId(), $anonymous_code, 0);
885 
886  if (!$this->run_manager->hasFinished() ||
887  !$active_id) {
888  $this->ctrl->redirect($this, "infoScreen");
889  }
890 
891  $ilTabs->clearTargets();
892  $ilTabs->setBackTarget(
893  $this->lng->txt("btn_back"),
894  $this->ctrl->getLinkTarget($this, "infoScreen")
895  );
896 
897  $html = $this->getUserResultsTable($active_id);
899  }
900 
904  protected function getUserResultsPlain(
905  int $a_active_id
906  ): string {
907  $res = array();
908 
909  $show_titles = (bool) $this->object->getShowQuestionTitles();
910 
911  foreach ($this->object->getSurveyPages() as $page) {
912  if (count($page) > 0) {
913  $res[] = "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
914 
915  // question block
916  if (count($page) > 1) {
917  if ($page[0]["questionblock_show_blocktitle"]) {
918  $res[$this->lng->txt("questionblock")] = trim($page[0]["questionblock_title"] ?? "") . "\n";
919  }
920  }
921 
922  // questions
923 
924  $page_res = array();
925 
926  foreach ($page as $question) {
927  $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
928  $question_parts = array();
929 
930  // heading
931  if (strlen($question["heading"] ?? "")) {
932  $question_parts[$this->lng->txt("heading")] = trim($question["heading"] ?? "");
933  }
934 
935  if ($show_titles) {
936  $question_parts[$this->lng->txt("title")] = trim($question["title"] ?? "");
937  }
938 
939  if ($question["questionblock_show_questiontext"]) {
940  $question_parts[$this->lng->txt("question")] = trim(strip_tags($question_gui->object->getQuestionText()));
941  }
942 
943  $answers = $question_gui->getParsedAnswers(
944  $this->object->loadWorkingData($question["question_id"], $a_active_id),
945  true
946  );
947 
948  if (count($answers)) {
949  $multiline = false;
950  if (count($answers) > 1 ||
951  get_class($question_gui) === "SurveyTextQuestionGUI") {
952  $multiline = true;
953  }
954 
955  $parts = array();
956  foreach ($answers as $answer) {
957  $text = null;
958  if ($answer["textanswer"] ?? false) {
959  $text = ' ("' . $answer["textanswer"] . '")';
960  }
961  if (!isset($answer["cols"])) {
962  if (isset($answer["title"])) {
963  $parts[] = $answer["title"] . $text;
964  } elseif (isset($answer["value"])) {
965  $parts[] = $answer["value"];
966  } elseif ($text) {
967  $parts[] = substr($text, 2, -1);
968  }
969  }
970  // matrix
971  else {
972  $tmp = array();
973  foreach ($answer["cols"] as $col) {
974  $tmp[] = $col["title"];
975  }
976  $parts[] = $answer["title"] . ": " . implode(", ", $tmp) . $text;
977  }
978  }
979  $question_parts[$this->lng->txt("answer")] =
980  ($multiline ? "\n" : "") . implode("\n", $parts);
981  }
982 
983  $tmp = array();
984  foreach ($question_parts as $type => $value) {
985  $tmp[] = $type . ": " . $value;
986  }
987  $page_res[] = implode("\n", $tmp);
988  }
989 
990  $res[] = implode("\n\n-------------------------------\n\n", $page_res);
991  }
992  }
993 
994  $res[] = "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
995 
996  return implode("\n", $res);
997  }
998 
999  public function sendUserResultsMail(
1000  int $a_active_id,
1001  string $a_recipient
1002  ): void {
1003  $ilUser = $this->user;
1004 
1005  $finished = $this->object->getSurveyParticipants(array($a_active_id));
1006  $finished = array_pop($finished);
1007  $finished = ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX));
1008 
1009  $body = ilMail::getSalutation($ilUser->getId()) . "\n\n";
1010  $body .= $this->lng->txt("svy_mail_own_results_body") . "\n";
1011  $body .= "\n" . $this->lng->txt("obj_svy") . ": " . $this->object->getTitle() . "\n";
1012  $body .= ilLink::_getLink($this->object->getRefId(), "svy") . "\n";
1013  $body .= "\n" . $this->lng->txt("survey_results_finished") . ": " . $finished . "\n\n";
1014 
1015  if ($this->object->hasMailOwnResults()) {
1016  $subject = "svy_mail_own_results_subject";
1017  $body .= $this->getUserResultsPlain($a_active_id);
1018  } else {
1019  $subject = "svy_mail_confirmation_subject";
1020  }
1021 
1022  // $body .= ilMail::_getAutoGeneratedMessageString($this->lng);
1024 
1025 
1026  $mmail = new ilMimeMail();
1027  $mmail->From($this->senderFactory->system());
1028  $mmail->To($a_recipient);
1029  $mmail->Subject(sprintf($this->lng->txt($subject), $this->object->getTitle()), true);
1030  $mmail->Body($body);
1031  $mmail->Send();
1032  }
1033 
1034  public function mailUserResultsObject(): void
1035  {
1036  $ilUser = $this->user;
1037 
1038  $anonymous_code = $this->run_manager->getCode();
1039  $active_id = $this->object->getActiveID($ilUser->getId(), $anonymous_code, 0);
1040  if (!$this->run_manager->hasFinished() ||
1041  !$active_id) {
1042  $this->ctrl->redirect($this, "infoScreen");
1043  }
1044 
1045  $recipient = $this->edit_request->getMail();
1046  if (!$recipient) {
1047  $recipient = $ilUser->getEmail();
1048  }
1049  if (!ilUtil::is_email($recipient)) {
1050  $this->ctrl->redirect($this, "infoScreen");
1051  }
1052 
1053  $this->sendUserResultsMail($active_id, $recipient);
1054 
1055  $this->tpl->setOnScreenMessage('success', $this->lng->txt("mail_sent"), true);
1056  $this->ctrl->redirect($this, "infoScreen");
1057  }
1058 
1062  protected function checkRbacOrPositionPermission(
1063  string $a_rbac_permission,
1064  string $a_position_permission
1065  ): bool {
1066  $access = $GLOBALS['DIC']->access();
1068  $a_rbac_permission,
1069  $a_position_permission,
1070  $this->object->getRefId()
1071  );
1072  }
1073 }
Class ilSurveyParticipantsGUI.
ILIAS Survey Mode FeatureConfig $feature_config
ilMailMimeSenderFactory $senderFactory
$res
Definition: ltiservices.php:69
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...
exit
Definition: login.php:29
Class ilInfoScreenGUI.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
Class ilSurveyEditorGUI.
static getLogger(string $a_component_id)
Get component logger.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilObjSurveyQuestionPool.
static is_email(string $a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
GUI class for the workflow of copying objects.
ILIAS Survey Participants StatusManager $status_manager
const ROOT_FOLDER_ID
Definition: constants.php:32
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const EVALUATION_ACCESS_PARTICIPANTS
prepareOutput(bool $show_sub_objects=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
ILIAS Survey Execution ExecutionGUIRequest $execution_request
ILIAS Survey Execution RunManager $run_manager
checkRbacOrPositionPermissionAccess(string $rbac_perm, string $pos_perm, int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setParameterByClass(string $a_class, string $a_parameter, $a_value)
static _goto(string $a_target)
redirect script
ilNavigationHistory $nav_history
addSubTabs(string $a_section)
static _getQuestionType(int $question_id)
Returns the question type of a question with a given id.
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
static _getTitle(int $question_id)
Returns the question title of a question with a given id.
setOptions(array $a_options)
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
setCreationMode(bool $mode=true)
If true, a creation screen is displayed the current [ref_id] does belong to the parent class The mode...
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
global $DIC
Definition: feed.php:28
Class ilObjSurveyGUI.
Export User Interface Class.
ilLanguage $lng
addDidacticTemplateOptions(array &$a_options)
__construct(VocabulariesInterface $vocabularies)
ilGlobalTemplateInterface $tpl
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
$GLOBALS["DIC"]
Definition: wac.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ServerRequestInterface $request
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
Survey execution graphical output.
Class ilObjectGUI Basic methods of all Output classes.
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually...
getUserResultsTable(int $a_active_id)
ILIAS Survey Access AccessManager $access_manager
infoScreen()
show information screen
static _hasEvaluationAccess(int $a_obj_id, int $user_id)
Last visited history for repository items.
evaluationObject()
Redirects the evaluation object call to the ilSurveyEvaluationGUI class Coming from ListGUI...
setCustomRolesForSelection(array $a_roles)
Set custom roles for mapping to LTI roles.
ilErrorHandling $error
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static redirect(string $a_script)
afterSave(ilObject $new_object)
putObjectInTree(ilObject $obj, int $parent_node_id=null)
Add object to tree at given position.
propertiesObject(ilPropertyFormGUI $a_form=null)
Display the properties form.
ilAccessHandler $access
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
initImportForm(string $new_type)
ILIAS Survey Editing EditingGUIRequest $edit_request
ilRbacSystem $rbacsystem
sendUserResultsMail(int $a_active_id, string $a_recipient)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
Participants InvitationsManager $invitation_manager
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getUserResultsPlain(int $a_active_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMIZE_CODE_ALL
ILIAS Survey InternalService $survey_service
addHeaderAction()
Add header action menu.
ilLocatorGUI $locator
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static _getInstallationSignature()
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
checkRbacOrPositionPermission(string $a_rbac_permission, string $a_position_permission)