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