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