ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSurveyEvaluationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
20 protected $tabs;
21
25 protected $access;
26
30 protected $user;
31
35 protected $rbacsystem;
36
40 protected $tree;
41
45 protected $toolbar;
46
47 const TYPE_XLS = "excel";
48 const TYPE_SPSS = "csv";
49
50 const EXCEL_SUBTITLE = "DDDDDD";
51
52 public $object;
53 public $lng;
54 public $tpl;
55 public $ctrl;
56 public $appr_id = null;
57
66 public function __construct($a_object)
67 {
68 global $DIC;
69
70 $this->tabs = $DIC->tabs();
71 $this->access = $DIC->access();
72 $this->user = $DIC->user();
73 $this->rbacsystem = $DIC->rbac()->system();
74 $this->tree = $DIC->repositoryTree();
75 $this->toolbar = $DIC->toolbar();
76 $this->ui = $DIC->ui();
77 $lng = $DIC->language();
78 $tpl = $DIC["tpl"];
79 $ilCtrl = $DIC->ctrl();
80
81 $this->lng = $lng;
82 $this->tpl = $tpl;
83 $this->ctrl = $ilCtrl;
84 $this->object = $a_object;
85 $this->log = ilLoggerFactory::getLogger("svy");
86 $this->array_panels = array();
87
88 if ($this->object->get360Mode() || $this->object->getMode() == ilObjSurvey::MODE_SELF_EVAL) {
89 $this->determineAppraiseeId();
90 }
91 }
92
96 public function executeCommand()
97 {
98 include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
99 $skmg_set = new ilSkillManagementSettings();
100 if ($this->object->getSkillService() && $skmg_set->isActivated()) {
101 $cmd = $this->ctrl->getCmd("competenceEval");
102 } else {
103 $cmd = $this->ctrl->getCmd("evaluation");
104 }
105
106 $next_class = $this->ctrl->getNextClass($this);
107
108 $cmd = $this->getCommand($cmd);
109 switch ($next_class) {
110 default:
111 $this->setEvalSubTabs();
112 $ret = &$this->$cmd();
113 break;
114 }
115 return $ret;
116 }
117
118 public function getCommand($cmd)
119 {
120 return $cmd;
121 }
122
128 public function setEvalSubtabs()
129 {
130 $ilTabs = $this->tabs;
131 $ilAccess = $this->access;
132
133 include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
134 $skmg_set = new ilSkillManagementSettings();
135 if ($this->object->getSkillService() && $skmg_set->isActivated()) {
136 $ilTabs->addSubTabTarget(
137 "svy_eval_competences",
138 $this->ctrl->getLinkTarget($this, "competenceEval"),
139 array("competenceEval")
140 );
141 }
142
143 $ilTabs->addSubTabTarget(
144 "svy_eval_cumulated",
145 $this->ctrl->getLinkTarget($this, "evaluation"),
146 array("evaluation", "checkEvaluationAccess")
147 );
148
149 $ilTabs->addSubTabTarget(
150 "svy_eval_detail",
151 $this->ctrl->getLinkTarget($this, "evaluationdetails"),
152 array("evaluationdetails")
153 );
154
155 if ($this->hasResultsAccess()) {
156 $ilTabs->addSubTabTarget(
157 "svy_eval_user",
158 $this->ctrl->getLinkTarget($this, "evaluationuser"),
159 array("evaluationuser")
160 );
161 }
162 }
163
164
170 public function setAppraiseeId($a_val)
171 {
172 $this->appr_id = $a_val;
173 }
174
180 public function getAppraiseeId()
181 {
182 return $this->appr_id;
183 }
184
188 public function determineAppraiseeId()
189 {
192
193 $appr_id = "";
194
195 // always start with current user
196 if ($_REQUEST["appr_id"] == "") {
197 $req_appr_id = $ilUser->getId();
198 } else {
199 $req_appr_id = (int) $_REQUEST["appr_id"];
200 }
201
202 // write access? allow selection
203 if ($req_appr_id > 0 && $this->object->get360Mode()) {
204 $all_appr = ($this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL);
205
206 $valid = array();
207 foreach ($this->object->getAppraiseesData() as $item) {
208 if ($item["closed"] &&
209 ($item["user_id"] == $ilUser->getId() ||
210 $rbacsystem->checkAccess("write", $this->object->getRefId()) ||
211 $all_appr)) {
212 $valid[] = $item["user_id"];
213 }
214 }
215 if (in_array($req_appr_id, $valid)) {
216 $appr_id = $req_appr_id;
217 } else {
218 // current selection / user is not valid, use 1st valid instead
219 $appr_id = array_shift($valid);
220 }
221 } else { // SVY SELF EVALUATION MODE
222 $appr_id = $req_appr_id;
223 }
224
225 $this->ctrl->setParameter($this, "appr_id", $appr_id);
226 $this->setAppraiseeId($appr_id);
227 }
228
229
238 {
240
241 if ($this->object->getAnonymize() == 1 &&
242 $_SESSION["anon_evaluation_access"] == $_GET["ref_id"]) {
243 return true;
244 }
245
246 include_once "Modules/Survey/classes/class.ilObjSurveyAccess.php";
248 if ($this->object->getAnonymize() == 1) {
249 $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
250 }
251 return true;
252 }
253
254 if ($this->object->getAnonymize() == 1) {
255 // autocode
256 $surveycode = $this->object->getUserAccessCode($ilUser->getId());
257 if ($this->object->isAnonymizedParticipant($surveycode)) {
258 $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
259 return true;
260 }
261
262 /* try to find code for current (registered) user from existing run
263 if($this->object->findCodeForUser($ilUser->getId()))
264 {
265 $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
266 return true;
267 }
268 */
269
270 // code needed
271 $this->tpl->setVariable("TABS", "");
272 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation_checkaccess.html", "Modules/Survey");
273 $this->tpl->setCurrentBlock("adm_content");
274 $this->tpl->setVariable("AUTHENTICATION_NEEDED", $this->lng->txt("svy_check_evaluation_authentication_needed"));
275 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "checkEvaluationAccess"));
276 $this->tpl->setVariable("EVALUATION_CHECKACCESS_INTRODUCTION", $this->lng->txt("svy_check_evaluation_access_introduction"));
277 $this->tpl->setVariable("VALUE_CHECK", $this->lng->txt("ok"));
278 $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
279 $this->tpl->setVariable("TEXT_SURVEY_CODE", $this->lng->txt("survey_code"));
280 $this->tpl->parseCurrentBlock();
281 }
282
283 $_SESSION["anon_evaluation_access"] = null;
284 return false;
285 }
286
294 public function checkEvaluationAccess()
295 {
296 $surveycode = $_POST["surveycode"];
297 if ($this->object->isAnonymizedParticipant($surveycode)) {
298 $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
299 $this->evaluation();
300 } else {
301 ilUtil::sendFailure($this->lng->txt("svy_check_evaluation_wrong_key", true));
302 $this->cancelEvaluationAccess();
303 }
304 }
305
313 public function cancelEvaluationAccess()
314 {
317 $path = $tree->getPathFull($this->object->getRefID());
318 $ilCtrl->setParameterByClass(
319 "ilrepositorygui",
320 "ref_id",
321 $path[count($path) - 2]["child"]
322 );
323 $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
324 }
325
333 public function evaluationdetails()
334 {
335 $this->evaluation(1);
336 }
337
338 public function exportCumulatedResults($details = 0)
339 {
340 $finished_ids = null;
341 if ($this->object->get360Mode()) {
342 $appr_id = $_REQUEST["appr_id"];
343 if (!$appr_id) {
344 $this->ctrl->redirect($this, $details ? "evaluationdetails" : "evaluation");
345 }
346 $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
347 if (!sizeof($finished_ids)) {
348 $finished_ids = array(-1);
349 }
350 }
351
352 // titles
353 $title_row = array();
354 $do_title = $do_label = true;
355 switch ($_POST['export_label']) {
356 case 'label_only':
357 $title_row[] = $this->lng->txt("label");
358 $do_title = false;
359 break;
360
361 case 'title_only':
362 $title_row[] = $this->lng->txt("title");
363 $do_label = false;
364 break;
365
366 default:
367 $title_row[] = $this->lng->txt("title");
368 $title_row[] = $this->lng->txt("label");
369 break;
370 }
371 $title_row[] = $this->lng->txt("question");
372 $title_row[] = $this->lng->txt("question_type");
373 $title_row[] = $this->lng->txt("users_answered");
374 $title_row[] = $this->lng->txt("users_skipped");
375 $title_row[] = $this->lng->txt("mode");
376 $title_row[] = $this->lng->txt("mode_text");
377 $title_row[] = $this->lng->txt("mode_nr_of_selections");
378 $title_row[] = $this->lng->txt("median");
379 $title_row[] = $this->lng->txt("arithmetic_mean");
380
381 // creating container
382 switch ($_POST["export_format"]) {
383 case self::TYPE_XLS:
384 include_once "Services/Excel/classes/class.ilExcel.php";
385 $excel = new ilExcel();
386 $excel->addSheet($this->lng->txt("svy_eval_cumulated"));
387 $excel->setCellArray(array($title_row), "A1");
388 $excel->setBold("A1:" . $excel->getColumnCoord(sizeof($title_row) - 1) . "1");
389 break;
390
391 case self::TYPE_SPSS:
392 $csvfile = array($title_row);
393 break;
394 }
395
396
397 // parse answer data in evaluation results
398 $ov_row = 2;
399 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
400 foreach ($this->object->getSurveyQuestions() as $qdata) {
401 $q_eval = SurveyQuestion::_instanciateQuestionEvaluation($qdata["question_id"], $finished_ids);
402 $q_res = $q_eval->getResults();
403 $ov_rows = $q_eval->exportResults($q_res, $do_title, $do_label);
404
405 switch ($_POST["export_format"]) {
406 case self::TYPE_XLS:
407 $excel->setActiveSheet(0);
408 foreach ($ov_rows as $row) {
409 foreach ($row as $col => $value) {
410 $excel->setCell($ov_row, $col, $value);
411 }
412 $ov_row++;
413 }
414 break;
415
416 case self::TYPE_SPSS:
417 foreach ($ov_rows as $row) {
418 $csvfile[] = $row;
419 }
420 break;
421 }
422
423 if ($details) {
424 switch ($_POST["export_format"]) {
425 case self::TYPE_XLS:
426 $this->exportResultsDetailsExcel($excel, $q_eval, $q_res, $do_title, $do_label);
427 break;
428 }
429 }
430 }
431
432 // #11179
433 $type = !$details
434 ? $this->lng->txt("svy_eval_cumulated")
435 : $this->lng->txt("svy_eval_detail");
436
437 $surveyname = $this->object->getTitle() . " " . $type . " " . date("Y-m-d");
438 $surveyname = preg_replace("/\s/", "_", trim($surveyname));
439 $surveyname = ilUtil::getASCIIFilename($surveyname);
440
441 // send to client
442 switch ($_POST["export_format"]) {
443 case self::TYPE_XLS:
444 $excel->sendToClient($surveyname);
445 break;
446
447 case self::TYPE_SPSS:
448 $csv = "";
449 $separator = ";";
450 foreach ($csvfile as $csvrow) {
451 $csvrow = $this->processCSVRow($csvrow, true, $separator);
452 $csv .= join($separator, $csvrow) . "\n";
453 }
454 ilUtil::deliverData($csv, $surveyname . ".csv");
455 exit();
456 break;
457 }
458 }
459
469 protected function exportResultsDetailsExcel(ilExcel $a_excel, SurveyQuestionEvaluation $a_eval, $a_results, $a_do_title, $a_do_label)
470 {
471 $question_res = $a_results;
472 $matrix = false;
473 if (is_array($question_res)) {
474 $question_res = $question_res[0][1];
475 $matrix = true;
476 }
477 $question = $question_res->getQuestion();
478
479 $a_excel->addSheet($question->getTitle());
480
481
482 // question "overview"
483
484 $kv = array();
485
486 if ($a_do_title) {
487 $kv[$this->lng->txt("title")] = $question->getTitle();
488 }
489 if ($a_do_label) {
490 $kv[$this->lng->txt("label")] = $question->label;
491 }
492
493 // question
494 $kv[$this->lng->txt("question")] = $question->getQuestiontext();
495
496 // question type
497 $kv[$this->lng->txt("question_type")] = SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
498
499 // :TODO: present subtypes (hrz/vrt, mc/sc mtx, metric scale)?
500
501 // answered and skipped users
502 $kv[$this->lng->txt("users_answered")] = (int) $question_res->getUsersAnswered();
503 $kv[$this->lng->txt("users_skipped")] = (int) $question_res->getUsersSkipped(); // #0021671
504
505 $excel_row = 1;
506
507 foreach ($kv as $key => $value) {
508 $a_excel->setCell($excel_row, 0, $key);
509 $a_excel->setCell($excel_row++, 1, $value);
510 }
511
512 if (!$matrix) {
513 $this->parseResultsToExcel(
514 $a_excel,
515 $question_res,
516 $excel_row,
517 $a_eval->getExportGrid($a_results),
518 $a_eval->getTextAnswers($a_results)
519 );
520 } else {
521 // question
522 $this->parseResultsToExcel(
523 $a_excel,
524 $question_res,
525 $excel_row,
526 null,
527 null,
528 false
529 );
530
531 $texts = $a_eval->getTextAnswers($a_results);
532
533 // "rows"
534 foreach ($a_results as $row_results) {
535 $row_title = $row_results[0];
536
537 $a_excel->setCell($excel_row, 0, $this->lng->txt("row"));
538 $a_excel->setCell($excel_row++, 1, $row_title);
539
540 $this->parseResultsToExcel(
541 $a_excel,
542 $row_results[1],
543 $excel_row,
544 $a_eval->getExportGrid($row_results[1]),
545 is_array($texts[$row_title])
546 ? array("" => $texts[$row_title])
547 : null
548 );
549 }
550 }
551
552 // matrix question: overview #21438
553 if ($matrix) {
554 $a_excel->setCell($excel_row++, 0, $this->lng->txt("overview"));
555
556 // title row with variables
557 $counter = 0;
558 $cats = $question->getColumns();
559 foreach ($cats->getCategories() as $cat) {
560 $a_excel->setColors($a_excel->getCoordByColumnAndRow(1 + $counter, $excel_row), ilSurveyEvaluationGUI::EXCEL_SUBTITLE);
561 $a_excel->setCell($excel_row, 1 + $counter, $cat->title);
562 $counter++;
563 }
564 $excel_row++;
565
566 foreach ($a_results as $row_results) {
567 $row_title = $row_results[0];
568 $counter = 0;
569 $a_excel->setCell($excel_row, 0, $row_title);
570
571 $vars = $row_results[1]->getVariables();
572 if ($vars) {
573 foreach ($vars as $var) {
574 $a_excel->setCell($excel_row, ++$counter, $var->abs);
575 }
576 }
577 $excel_row++;
578 }
579 }
580
581 // 1st column is bold
582 $a_excel->setBold("A1:A" . $excel_row);
583 }
584
585 protected function parseResultsToExcel(ilExcel $a_excel, ilSurveyEvaluationResults $a_results, &$a_excel_row, array $a_grid = null, array $a_text_answers = null, $a_include_mode = true)
586 {
587 $kv = array();
588
589 if ($a_include_mode) {
590 if ($a_results->getModeValue() !== null) {
591 // :TODO:
592 $kv[$this->lng->txt("mode")] = is_array($a_results->getModeValue())
593 ? implode(", ", $a_results->getModeValue())
594 : $a_results->getModeValue();
595
596 $kv[$this->lng->txt("mode_text")] = $a_results->getModeValueAsText();
597 $kv[$this->lng->txt("mode_nr_of_selections")] = (int) $a_results->getModeNrOfSelections();
598 }
599
600 if ($a_results->getMedian() !== null) {
601 $kv[$this->lng->txt("median")] = $a_results->getMedianAsText();
602 }
603
604 if ($a_results->getMean() !== null) {
605 $kv[$this->lng->txt("arithmetic_mean")] = $a_results->getMean();
606 }
607 }
608
609 foreach ($kv as $key => $value) {
610 $a_excel->setCell($a_excel_row, 0, $key);
611 $a_excel->setCell($a_excel_row++, 1, $value);
612 }
613
614 // grid
615 if ($a_grid) {
616 // header
617 $a_excel->setColors("B" . $a_excel_row . ":E" . $a_excel_row, ilSurveyEvaluationGUI::EXCEL_SUBTITLE);
618 $a_excel->setCell($a_excel_row, 0, $this->lng->txt("categories"));
619 foreach ($a_grid["cols"] as $col_idx => $col) {
620 $a_excel->setCell($a_excel_row, $col_idx + 1, $col);
621 }
622 $a_excel_row++;
623
624 // rows
625 foreach ($a_grid["rows"] as $cols) {
626 foreach ($cols as $col_idx => $col) {
627 $a_excel->setCell($a_excel_row, $col_idx + 1, $col);
628 }
629 $a_excel_row++;
630 }
631 }
632
633 // text answers
634 if ($a_text_answers) {
635 // "given_answers" ?
636 $a_excel->setCell($a_excel_row, 0, $this->lng->txt("freetext_answers"));
637
638 // mc/sc
639 if (!is_array($a_text_answers[""])) {
640 $a_excel->setColors("B" . $a_excel_row . ":C" . $a_excel_row, ilSurveyEvaluationGUI::EXCEL_SUBTITLE);
641 $a_excel->setCell($a_excel_row, 1, $this->lng->txt("title"));
642 $a_excel->setCell($a_excel_row++, 2, $this->lng->txt("answer"));
643 }
644 // mtx (row), txt
645 else {
646 $a_excel->setColors("B" . $a_excel_row . ":B" . $a_excel_row, ilSurveyEvaluationGUI::EXCEL_SUBTITLE);
647 $a_excel->setCell($a_excel_row++, 1, $this->lng->txt("answer"));
648 }
649
650 foreach ($a_text_answers as $var => $items) {
651 foreach ($items as $item) {
652 if (!is_array($a_text_answers[""])) {
653 $a_excel->setCell($a_excel_row, 1, $var);
654 $a_excel->setCell($a_excel_row++, 2, $item);
655 } else {
656 $a_excel->setCell($a_excel_row++, 1, $item);
657 }
658 }
659 }
660 }
661 }
662
663 public function exportData()
664 {
665 if (strlen($_POST["export_format"])) {
666 $this->exportCumulatedResults(0);
667 return;
668 } else {
669 $this->ctrl->redirect($this, 'evaluation');
670 }
671 }
672
673 public function exportDetailData()
674 {
675 if (strlen($_POST["export_format"])) {
676 $this->exportCumulatedResults(1);
677 return;
678 } else {
679 $this->ctrl->redirect($this, 'evaluation');
680 }
681 }
682
683 public function printEvaluation()
684 {
685 ilUtil::sendInfo($this->lng->txt('use_browser_print_function'), true);
686 $this->ctrl->redirect($this, 'evaluation');
687 }
688
689 protected function buildExportModal($a_id, $a_cmd)
690 {
692
693 $form_id = "svymdfrm";
694
695 // hide modal on form submit
696 $tpl->addOnLoadCode('$("#form_' . $form_id . '").submit(function() { $("#' . $a_id . '").modal("hide"); });');
697
698 include_once "Services/UIComponent/Modal/classes/class.ilModalGUI.php";
699 $modal = ilModalGUI::getInstance();
700 $modal->setId($a_id);
701 $modal->setHeading(($this->lng->txt("svy_export_format")));
702
703 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
704 $form = new ilPropertyFormGUI();
705 $form->setId($form_id);
706 $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
707
708 $format = new ilSelectInputGUI($this->lng->txt("filetype"), "export_format");
709 $format->setOptions(array(
710 self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
711 self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
712 ));
713 $form->addItem($format, true);
714
715 $label = new ilSelectInputGUI($this->lng->txt("title"), "export_label");
716 $label->setOptions(array(
717 'label_only' => $this->lng->txt('export_label_only'),
718 'title_only' => $this->lng->txt('export_title_only'),
719 'title_label' => $this->lng->txt('export_title_label')
720 ));
721 $form->addItem($label);
722
723 $form->addCommandButton($a_cmd, $this->lng->txt("export"));
724 $form->setPreventDoubleSubmission(false);
725
726 $modal->setBody($form->getHTML());
727
728 return $modal->getHTML();
729 }
730
731 public function evaluation($details = 0)
732 {
734 $ilToolbar = $this->toolbar;
736 $ui = $this->ui;
737
738 $ui_factory = $ui->factory();
739 $ui_renderer = $ui->renderer();
740
741 // auth
742 if (!$this->hasResultsAccess()) {
743 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
744 ilUtil::sendFailure($this->lng->txt("permission_denied"));
745 return;
746 }
747
748 switch ($this->object->getEvaluationAccess()) {
750 ilUtil::sendFailure($this->lng->txt("permission_denied"));
751 return;
752
755 if (!$this->checkAnonymizedEvaluationAccess()) {
756 ilUtil::sendFailure($this->lng->txt("permission_denied"));
757 return;
758 }
759 break;
760 }
761 }
762
763 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
764 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
765
766 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation.html", "Modules/Survey");
767
768 if ($this->object->get360Mode()) {
769 $appr_id = $this->getAppraiseeId();
771 }
772
773 $results = array();
774 if (!$this->object->get360Mode() || $appr_id) {
775 if ($details) {
776 $captions = new ilSelectInputGUI($this->lng->txt("svy_eval_captions"), "cp");
777 $captions->setOptions(array(
778 "ap" => $this->lng->txt("svy_eval_captions_abs_perc"),
779 "a" => $this->lng->txt("svy_eval_captions_abs"),
780 "p" => $this->lng->txt("svy_eval_captions_perc")
781 ));
782 $captions->setValue($_POST["cp"]);
783 $ilToolbar->addInputItem($captions, true);
784
785 $view = new ilSelectInputGUI($this->lng->txt("svy_eval_view"), "vw");
786 $view->setOptions(array(
787 "tc" => $this->lng->txt("svy_eval_view_tables_charts"),
788 "t" => $this->lng->txt("svy_eval_view_tables"),
789 "c" => $this->lng->txt("svy_eval_view_charts")
790 ));
791 $view->setValue($_POST["vw"]);
792 $ilToolbar->addInputItem($view, true);
793
794 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
795 $button = ilSubmitButton::getInstance();
796 $button->setCaption("ok");
797 $button->setCommand("evaluationdetails");
798 $button->setOmitPreventDoubleSubmission(true);
799 $ilToolbar->addButtonInstance($button);
800
801 $ilToolbar->addSeparator();
802
803 //templates: results, table of contents
804 $dtmpl = new ilTemplate("tpl.il_svy_svy_results_details.html", true, true, "Modules/Survey");
805 $toc_tpl = new ilTemplate("tpl.svy_results_table_contents.html", true, true, "Modules/Survey");
806 $this->lng->loadLanguageModule("content");
807 $toc_tpl->setVariable("TITLE_TOC", $this->lng->txt('cont_toc'));
808 }
809
810 $modal_id = "svy_ev_exp";
811 $modal = $this->buildExportModal($modal_id, $details
812 ? 'exportDetailData'
813 : 'exportData');
814
815 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
816 $button = ilLinkButton::getInstance();
817 $button->setCaption("export");
818 $button->setOnClick('$(\'#' . $modal_id . '\').modal(\'show\')');
819 $ilToolbar->addButtonInstance($button);
820
821 $ilToolbar->addSeparator();
822
823 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
824 $button = ilLinkButton::getInstance();
825 $button->setCaption("print");
826 $button->setOnClick("if(il.Accordion) { il.Accordion.preparePrint(); } window.print(); return false;");
827 $button->setOmitPreventDoubleSubmission(true);
828 $ilToolbar->addButtonInstance($button);
829
830 $finished_ids = null;
831 if ($appr_id) {
832 $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
833 if (!sizeof($finished_ids)) {
834 $finished_ids = array(-1);
835 }
836 }
837
838 $details_figure = $_POST["cp"]
839 ? $_POST["cp"]
840 : "ap";
841 $details_view = $_POST["vw"]
842 ? $_POST["vw"]
843 : "tc";
844
845 // @todo
846 // filter finished ids
847 $finished_ids2 = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
848 'read_results',
849 'access_results',
850 $this->object->getRefId(),
851 (array) $finished_ids
852 );
853
854 // parse answer data in evaluation results
855 include_once("./Services/UIComponent/NestedList/classes/class.ilNestedList.php");
856 $list = new ilNestedList();
857
858 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
859 foreach ($this->object->getSurveyQuestions() as $qdata) {
860 $q_eval = SurveyQuestion::_instanciateQuestionEvaluation($qdata["question_id"], $finished_ids);
861 $q_res = $q_eval->getResults();
862 $results[] = $q_res;
863
864 if ($details) {
865 //$this->renderDetails($details_view, $details_figure, $dtmpl, $qdata, $q_eval, $q_res);
866 $this->renderDetails($details_view, $details_figure, $qdata, $q_eval, $q_res);
867
868 // TABLE OF CONTENTS
869 if ($qdata["questionblock_id"] &&
870 $qdata["questionblock_id"] != $this->last_questionblock_id) {
871 $qblock = ilObjSurvey::_getQuestionblock($qdata["questionblock_id"]);
872 if ($qblock["show_blocktitle"]) {
873 $list->addListNode($qdata["questionblock_title"], "q" . $qdata["questionblock_id"]);
874 }
875 $this->last_questionblock_id = $qdata["questionblock_id"];
876 }
877 $anchor_id = "svyrdq" . $qdata["question_id"];
878 $list->addListNode("<a href='#" . $anchor_id . "'>" . $qdata["title"] . "</a>", $qdata["question_id"], $qdata["questionblock_id"] ?
879 "q" . $qdata["questionblock_id"] : 0);
880 }
881 }
882
883 if ($details) {
884 $list->setListClass("il_Explorer");
885 $toc_tpl->setVariable("LIST", $list->getHTML());
886
887 //TABLE OF CONTENTS
888 $panel_toc = $ui_factory->panel()->standard("", $ui_factory->legacy($toc_tpl->get()));
889 $render_toc = $ui_renderer->render($panel_toc);
890 $dtmpl->setVariable("PANEL_TOC", $render_toc);
891
892 //REPORT
893 $report_title = "";
894 $panel_report = $ui_factory->panel()->report($report_title, $this->array_panels);
895 $render_report = $ui_renderer->render($panel_report);
896 $dtmpl->setVariable("PANEL_REPORT", $render_report);
897
898 //print the main template
899 $this->tpl->setVariable('DETAIL', $dtmpl->get());
900 }
901 }
902
903 $this->tpl->setVariable('MODAL', $modal);
904 if (!$details) {
905 include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsCumulatedTableGUI.php";
906 $table_gui = new ilSurveyResultsCumulatedTableGUI($this, $details ? 'evaluationdetails' : 'evaluation', $results);
907 $this->tpl->setVariable('CUMULATED', $table_gui->getHTML());
908 }
909 unset($dtmpl);
910 unset($table_gui);
911 unset($modal);
912
913
914 // print header
915
916 $path = "";
917 $path_full = $tree->getPathFull($this->object->getRefId());
918 foreach ($path_full as $data) {
919 $path .= " &raquo; ";
920 $path .= $data['title'];
921 }
922
924 include_once "Services/Link/classes/class.ilLink.php";
925
926 $props = array(
927 $this->lng->txt("link") => ilLink::_getStaticLink($this->object->getRefId()),
928 $this->lng->txt("path") => $path,
929 $this->lng->txt("svy_results") => !$details
930 ? $this->lng->txt("svy_eval_cumulated")
931 : $this->lng->txt("svy_eval_detail"),
932 $this->lng->txt("date") => ilDatePresentation::formatDate(new ilDateTime(time(), IL_CAL_UNIX)),
933 );
934
935 $this->tpl->setCurrentBlock("print_header_bl");
936 foreach ($props as $key => $value) {
937 $this->tpl->setVariable("HEADER_PROP_KEY", $key);
938 $this->tpl->setVariable("HEADER_PROP_VALUE", $value);
939 $this->tpl->parseCurrentBlock();
940 }
941
942 // $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
943 }
944
955 //protected function renderDetails($a_details_parts, $a_details_figure, ilTemplate $a_tpl, array $a_qdata, SurveyQuestionEvaluation $a_eval, $a_results)
956 protected function renderDetails($a_details_parts, $a_details_figure, array $a_qdata, SurveyQuestionEvaluation $a_eval, $a_results)
957 {
958 $ui_factory = $this->ui->factory();
959 $a_tpl = new ilTemplate("tpl.svy_results_details_panel.html", true, true, "Modules/Survey");
960
961 $question_res = $a_results;
962 $matrix = false;
963 if (is_array($question_res)) {
964 $question_res = $question_res[0][1];
965 $matrix = true;
966 }
967
968 // see #28507 (matrix question without a row)
969 if (!is_object($question_res)) {
970 return;
971 }
972
973 $question = $question_res->getQuestion();
974
975 // question "overview"
976
977 // :TODO: present subtypes (hrz/vrt, mc/sc mtx)?
978
979 $a_tpl->setVariable("QTYPE", SurveyQuestion::_getQuestionTypeName($question->getQuestionType()));
980
981 $kv = array();
982 $kv["users_answered"] = $question_res->getUsersAnswered();
983 $kv["users_skipped"] = $question_res->getUsersSkipped();
984
985 if (!$matrix) {
986 if ($question_res->getModeValue() !== null) {
987 $kv["mode"] = wordwrap($question_res->getModeValueAsText(), 50, "<br />");
988 $kv["mode_nr_of_selections"] = $question_res->getModeNrOfSelections();
989 }
990 if ($question_res->getMedian() !== null) {
991 $kv["median"] = $question_res->getMedianAsText();
992 }
993 if ($question_res->getMean() !== null) {
994 $kv["arithmetic_mean"] = $question_res->getMean();
995 }
996 }
997
998 $svy_type_title = SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
999 $qst_title = $question->getTitle();
1000 $svy_text = nl2br($question->getQuestiontext());
1001 $card_table_tpl = new ilTemplate("tpl.svy_results_details_card.html", true, true, "Modules/Survey");
1002 foreach ($kv as $key => $value) {
1003 $card_table_tpl->setCurrentBlock("question_statistics_card");
1004 $card_table_tpl->setVariable("QUESTION_STATISTIC_KEY", $this->lng->txt($key));
1005 $card_table_tpl->setVariable("QUESTION_STATISTIC_VALUE", $value);
1006 $card_table_tpl->parseCurrentBlock();
1007 }
1008 //anchor in title. Used in TOC
1009 $anchor_id = "svyrdq" . $question->getId();
1010 $title = "<span id='$anchor_id'>$qst_title</span>";
1011 $panel_qst_card = $ui_factory->panel()->sub($title, $ui_factory->legacy($svy_text))
1012 ->withCard($ui_factory->card()->standard($svy_type_title)->withSections(array($ui_factory->legacy($card_table_tpl->get()))));
1013 array_push($this->array_panels, $panel_qst_card);
1014
1015 // grid
1016 if ($a_details_parts == "t" ||
1017 $a_details_parts == "tc") {
1018 $grid = $a_eval->getGrid(
1019 $a_results,
1020 ($a_details_figure == "ap" || $a_details_figure == "a"),
1021 ($a_details_figure == "ap" || $a_details_figure == "p")
1022 );
1023 if ($grid) {
1024 foreach ($grid["cols"] as $col) {
1025 $a_tpl->setCurrentBlock("grid_col_header_bl");
1026 $a_tpl->setVariable("COL_HEADER", $col);
1027 $a_tpl->parseCurrentBlock();
1028 }
1029 foreach ($grid["rows"] as $cols) {
1030 foreach ($cols as $idx => $col) {
1031 if ($idx > 0) {
1032 $a_tpl->touchBlock("grid_col_nowrap_bl");
1033 }
1034
1035 $a_tpl->setCurrentBlock("grid_col_bl");
1036 $a_tpl->setVariable("COL_CAPTION", trim($col));
1037 $a_tpl->parseCurrentBlock();
1038 }
1039
1040 $a_tpl->touchBlock("grid_row_bl");
1041 }
1042 }
1043 }
1044
1045 // text answers
1046 $texts = $a_eval->getTextAnswers($a_results);
1047 if ($texts) {
1048 if (array_key_exists("", $texts)) {
1049 $a_tpl->setVariable("TEXT_HEADING", $this->lng->txt("given_answers"));
1050 foreach ($texts[""] as $item) {
1051 $a_tpl->setCurrentBlock("text_direct_item_bl");
1052 $a_tpl->setVariable("TEXT_DIRECT", nl2br(htmlentities($item)));
1053 $a_tpl->parseCurrentBlock();
1054 }
1055 } else {
1056 include_once "Services/Accordion/classes/class.ilAccordionGUI.php";
1057 $acc = new ilAccordionGUI();
1058 $acc->setId("svyevaltxt" . $question->getId());
1059
1060 $a_tpl->setVariable("TEXT_HEADING", $this->lng->txt("freetext_answers"));
1061
1062 foreach ($texts as $var => $items) {
1063 $list = array("<ul class=\"small\">");
1064 foreach ($items as $item) {
1065 $list[] = "<li>" . nl2br(htmlentities($item)) . "</li>";
1066 }
1067 $list[] = "</ul>";
1068 $acc->addItem($var, implode("\n", $list));
1069 }
1070
1071 $a_tpl->setVariable("TEXT_ACC", $acc->getHTML());
1072 }
1073 }
1074
1075 // chart
1076 if ($a_details_parts == "c" ||
1077 $a_details_parts == "tc") {
1078 $chart = $a_eval->getChart($a_results);
1079 if ($chart) {
1080 if (is_array($chart)) {
1081 // legend
1082 if (is_array($chart[1])) {
1083 foreach ($chart[1] as $legend_item) {
1084 $r = hexdec(substr($legend_item[1], 1, 2));
1085 $g = hexdec(substr($legend_item[1], 3, 2));
1086 $b = hexdec(substr($legend_item[1], 5, 2));
1087
1088 $a_tpl->setCurrentBlock("legend_bl");
1089 $a_tpl->setVariable("LEGEND_CAPTION", $legend_item[0]);
1090 $a_tpl->setVariable("LEGEND_COLOR", $legend_item[1]);
1091 $a_tpl->setVariable("LEGEND_COLOR_SVG", $r . "," . $g . "," . $b);
1092 $a_tpl->parseCurrentBlock();
1093 }
1094 }
1095
1096 $chart = $chart[0];
1097 }
1098 $a_tpl->setVariable("CHART", $chart);
1099 }
1100 }
1101 $panel = $ui_factory->panel()->sub("", $ui_factory->legacy($a_tpl->get()));
1102 array_push($this->array_panels, $panel);
1103 }
1104
1112 {
1113 $ilToolbar = $this->toolbar;
1115
1116 $svy_mode = $this->object->getMode();
1117 if ($svy_mode == ilObjSurvey::MODE_360 || $svy_mode == ilObjSurvey::MODE_SELF_EVAL) {
1118 $appr_id = $this->getAppraiseeId();
1119
1120 $options = array();
1121 if (!$appr_id) {
1122 $options[""] = $this->lng->txt("please_select");
1123 }
1124
1125 $no_appr = true;
1126 if ($this->object->get360Mode()) {
1127 foreach ($this->object->getAppraiseesData() as $item) {
1128 if ($item["closed"]) {
1129 $options[$item["user_id"]] = $item["login"];
1130 $no_appr = false;
1131 }
1132 }
1133 } else { //self evaluation mode
1134 foreach ($this->object->getSurveyParticipants() as $item) {
1135 $options[ilObjUser::_lookupId($item['login'])] = $item['login'];
1136 $no_appr = false;
1137 }
1138 }
1139
1140 if (!$no_appr) {
1141 if ($rbacsystem->checkAccess("write", $this->object->getRefId()) ||
1142 $this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL ||
1143 $this->object->getSelfEvaluationResults() == ilObjSurvey::RESULTS_SELF_EVAL_ALL) {
1144 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1145 $appr = new ilSelectInputGUI($this->lng->txt("svy_participant"), "appr_id");
1146 $appr->setOptions($options);
1147 $appr->setValue($this->getAppraiseeId());
1148 $ilToolbar->addInputItem($appr, true);
1149
1150 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
1151 $button = ilSubmitButton::getInstance();
1152 $button->setCaption("survey_360_select_appraisee");
1153 $button->setCommand($this->ctrl->getCmd());
1154 $ilToolbar->addButtonInstance($button);
1155
1156 if ($appr_id) {
1157 $ilToolbar->addSeparator();
1158 }
1159 }
1160 } else {
1161 ilUtil::sendFailure($this->lng->txt("survey_360_no_closed_appraisees"));
1162 }
1163 }
1164 }
1165
1176 public function processCSVRow($row, $quoteAll = false, $separator = ";")
1177 {
1178 $resultarray = array();
1179 foreach ($row as $rowindex => $entry) {
1180 if (is_array($entry)) {
1181 $entry = implode("/", $entry);
1182 }
1183 $surround = false;
1184 if ($quoteAll) {
1185 $surround = true;
1186 }
1187 if (strpos($entry, "\"") !== false) {
1188 $entry = str_replace("\"", "\"\"", $entry);
1189 $surround = true;
1190 }
1191 if (strpos($entry, $separator) !== false) {
1192 $surround = true;
1193 }
1194 // replace all CR LF with LF (for Excel for Windows compatibility
1195 $entry = str_replace(chr(13) . chr(10), chr(10), $entry);
1196 if ($surround) {
1197 $resultarray[$rowindex] = utf8_decode("\"" . $entry . "\"");
1198 } else {
1199 $resultarray[$rowindex] = utf8_decode($entry);
1200 }
1201 }
1202 return $resultarray;
1203 }
1204
1205
1206 public function exportEvaluationUser()
1207 {
1208 // build title row(s)
1209
1210 $title_row = $title_row2 = array();
1211 $title_row[] = $this->lng->txt("lastname"); // #12756
1212 $title_row[] = $this->lng->txt("firstname");
1213 $title_row[] = $this->lng->txt("login");
1214 $title_row[] = $this->lng->txt('workingtime'); // #13622
1215 $title_row[] = $this->lng->txt('survey_results_finished');
1216 $title_row2[] = "";
1217 $title_row2[] = "";
1218 $title_row2[] = "";
1219 $title_row2[] = "";
1220 $title_row2[] = "";
1221 if ($this->object->canExportSurveyCode()) {
1222 $title_row[] = $this->lng->txt("codes");
1223 $title_row2[] = "";
1224 }
1225
1226 $questions = array();
1227
1228 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1229 foreach ($this->object->getSurveyQuestions() as $qdata) {
1230 $q_eval = SurveyQuestion::_instanciateQuestionEvaluation($qdata["question_id"], $finished_ids);
1231 $q_res = $q_eval->getResults();
1232
1233 $questions[$qdata["question_id"]] = array($q_eval, $q_res);
1234
1235 $question = is_array($q_res)
1236 ? $q_res[0][1]->getQuestion()
1237 : $q_res->getQuestion();
1238
1239 $do_title = $do_label = true;
1240 switch ($_POST['export_label']) {
1241 case "label_only":
1242 $title_row[] = $question->label;
1243 $title_row2[] = "";
1244 $do_title = false;
1245 break;
1246
1247 case "title_only":
1248 $title_row[] = $question->getTitle();
1249 $title_row2[] = "";
1250 $do_label = false;
1251 break;
1252
1253 default:
1254 $title_row[] = $question->getTitle();
1255 $title_row2[] = $question->label;
1256 break;
1257 }
1258
1259 $q_eval->getUserSpecificVariableTitles($title_row, $title_row2, $do_title, $do_label);
1260 }
1261
1262 $rows = array();
1263
1264 // add title row(s)
1265 $rows[] = $title_row;
1266 if (implode("", $title_row2)) {
1267 $rows[] = $title_row2;
1268 }
1269
1270 // #13620
1272
1273 $finished_ids = null;
1274 if ($this->object->get360Mode()) {
1275 $appr_id = $_REQUEST["appr_id"];
1276 if (!$appr_id) {
1277 $this->ctrl->redirect($this, "evaluationuser");
1278 }
1279 $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1280 if (!sizeof($finished_ids)) {
1281 $finished_ids = array(-1);
1282 }
1283 }
1284
1285 //$participants = $this->object->getSurveyParticipants($finished_ids);
1286 $participants = $this->filterSurveyParticipantsByAccess($finished_ids);
1287
1288 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1289 foreach ($participants as $user) {
1290 $user_id = $user["active_id"];
1291
1292 $row = array();
1293 $row[] = trim($user["lastname"])
1294 ? $user["lastname"]
1295 : $user["name"]; // anonymous
1296 $row[] = $user["firstname"];
1297 $row[] = $user["login"]; // #10579
1298
1299 if ($this->object->canExportSurveyCode()) {
1300 $row[] = $user_id;
1301 }
1302
1303 $row[] = $this->object->getWorkingtimeForParticipant($user_id);
1304
1305 if ((bool) $user["finished"]) {
1306 $dt = new ilDateTime($user["finished_tstamp"], IL_CAL_UNIX);
1307 $row[] = ($_POST["export_format"] == self::TYPE_XLS)
1308 ? $dt
1310 } else {
1311 $row[] = "-"; // :TODO:
1312 }
1313
1314 foreach ($questions as $item) {
1315 $q_eval = $item[0];
1316 $q_res = $item[1];
1317
1318 $q_eval->addUserSpecificResults($row, $user_id, $q_res);
1319 }
1320
1321 $rows[] = $row;
1322 }
1323
1324 // #11179
1325 $surveyname = $this->object->getTitle() . " " . $this->lng->txt("svy_eval_user") . " " . date("Y-m-d");
1326 $surveyname = preg_replace("/\s/", "_", trim($surveyname));
1327 $surveyname = ilUtil::getASCIIFilename($surveyname);
1328
1329 switch ($_POST["export_format"]) {
1330 case self::TYPE_XLS:
1331 include_once "Services/Excel/classes/class.ilExcel.php";
1332 $excel = new ilExcel();
1333 $excel->addSheet($this->lng->txt("svy_eval_user"));
1334
1335 foreach ($rows as $row_idx => $row) {
1336 foreach ($row as $col_idx => $col) {
1337 $excel->setCell($row_idx + 1, $col_idx, $col);
1338 }
1339 if (!$row_idx) {
1340 $excel->setBold("A1:" . $excel->getColumnCoord(sizeof($row) - 1) . "1");
1341 }
1342 }
1343 $excel->sendToClient($surveyname);
1344
1345 // no break
1346 case self::TYPE_SPSS:
1347 $csv = "";
1348 $separator = ";";
1349 foreach ($rows as $csvrow) {
1350 $csvrow = str_replace("\n", " ", $this->processCSVRow($csvrow, true, $separator));
1351 $csv .= join($separator, $csvrow) . "\n";
1352 }
1353 ilUtil::deliverData($csv, "$surveyname.csv");
1354 exit();
1355 }
1356 }
1357
1365 public function evaluationuser()
1366 {
1367 $ilAccess = $this->access;
1368 $ilToolbar = $this->toolbar;
1369
1370 if (!$this->hasResultsAccess() &&
1371 $this->object->getMode() != ilObjSurvey::MODE_SELF_EVAL) {
1372 ilUtil::sendFailure($this->lng->txt("no_permission"), true);
1373 $this->ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
1374 }
1375
1376 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1377 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "evaluationuser"));
1378
1379 if ($this->object->get360Mode()) {
1380 $appr_id = $this->getAppraiseeId();
1382 }
1383
1384 $tabledata = null;
1385 if (!$this->object->get360Mode() || $appr_id) {
1386 $modal_id = "svy_ev_exp";
1387 $modal = $this->buildExportModal($modal_id, "exportevaluationuser");
1388
1389 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1390 $button = ilLinkButton::getInstance();
1391 $button->setCaption("export");
1392 $button->setOnClick('$(\'#' . $modal_id . '\').modal(\'show\')');
1393 $ilToolbar->addButtonInstance($button);
1394
1395 $ilToolbar->addSeparator();
1396
1397 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1398 $button = ilLinkButton::getInstance();
1399 $button->setCaption("print");
1400 $button->setOnClick("window.print(); return false;");
1401 $button->setOmitPreventDoubleSubmission(true);
1402 $ilToolbar->addButtonInstance($button);
1403
1404 $finished_ids = null;
1405 if ($appr_id) {
1406 $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1407 if (!sizeof($finished_ids)) {
1408 $finished_ids = array(-1);
1409 }
1410 }
1411
1412 $data = $this->parseUserSpecificResults($finished_ids);
1413 }
1414
1415 /*
1416 $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
1417 $this->tpl->setCurrentBlock("generic_css");
1418 $this->tpl->setVariable("LOCATION_GENERIC_STYLESHEET", "./Modules/Survey/templates/default/evaluation_print.css");
1419 $this->tpl->setVariable("MEDIA_GENERIC_STYLESHEET", "print");
1420 $this->tpl->parseCurrentBlock();
1421 */
1422
1423 include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsUserTableGUI.php";
1424 $table_gui = new ilSurveyResultsUserTableGUI($this, 'evaluationuser', $this->object->hasAnonymizedResults());
1425 $table_gui->setData($data);
1426 $this->tpl->setContent($table_gui->getHTML() . $modal);
1427 }
1428
1429 protected function filterSurveyParticipantsByAccess($a_finished_ids)
1430 {
1431 $all_participants = $this->object->getSurveyParticipants($a_finished_ids);
1432 $participant_ids = [];
1433 foreach ($all_participants as $participant) {
1434 $participant_ids[] = $participant['usr_id'];
1435 }
1436
1437
1438 $filtered_participant_ids = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
1439 'read_results',
1440 'access_results',
1441 $this->object->getRefId(),
1442 $participant_ids
1443 );
1444 $participants = [];
1445 foreach ($all_participants as $username => $user_data) {
1446 if (!$user_data['usr_id']) {
1447 $participants[$username] = $user_data;
1448 }
1449 if (in_array($user_data['usr_id'], $filtered_participant_ids)) {
1450 $participants[$username] = $user_data;
1451 }
1452 }
1453 return $participants;
1454 }
1455
1456
1457
1458 protected function parseUserSpecificResults(array $a_finished_ids = null)
1459 {
1460 $data = array();
1461
1462 $participants = $this->filterSurveyParticipantsByAccess($a_finished_ids);
1463
1464 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1465 foreach ($this->object->getSurveyQuestions() as $qdata) {
1466 $q_eval = SurveyQuestion::_instanciateQuestionEvaluation($qdata["question_id"], $a_finished_ids);
1467 $q_res = $q_eval->getResults();
1468
1469 // see #28507 (matrix question without a row)
1470 if (is_array($q_res) && !is_object($q_res[0][1])) {
1471 continue;
1472 }
1473
1474 $question = is_array($q_res)
1475 ? $q_res[0][1]->getQuestion()
1476 : $q_res->getQuestion();
1477
1478 foreach ($participants as $user) {
1479 $user_id = $user["active_id"];
1480
1481 $parsed_results = $q_eval->parseUserSpecificResults($q_res, $user_id);
1482
1483 if (!array_key_exists($user_id, $data)) {
1484 $wt = $this->object->getWorkingtimeForParticipant($user_id);
1485
1486 $finished = $user["finished"]
1487 ? $user["finished_tstamp"]
1488 : false;
1489
1490 $data[$user_id] = array(
1491 "username" => $user["sortname"],
1492 "question" => $question->getTitle(),
1493 "results" => $parsed_results,
1494 "workingtime" => $wt,
1495 "finished" => $finished,
1496 "subitems" => array()
1497 );
1498 } else {
1499 $data[$user_id]["subitems"][] = array(
1500 "username" => " ",
1501 "question" => $question->getTitle(),
1502 "results" => $parsed_results,
1503 "workingtime" => null,
1504 "finished" => null
1505 );
1506 }
1507 }
1508 }
1509
1510 return $data;
1511 }
1512
1519 public function competenceEval()
1520 {
1522 $lng = $this->lng;
1524 $ilToolbar = $this->toolbar;
1525 $tpl = $this->tpl;
1526 $ilTabs = $this->tabs;
1527
1528 $survey = $this->object;
1529
1530 $ilTabs->activateSubtab("svy_eval_competences");
1531 $ilTabs->activateTab("svy_results");
1532
1533 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "competenceEval"));
1534
1535 if ($this->object->get360Mode() || $survey->getMode() == ilObjSurvey::MODE_SELF_EVAL) {
1536 $appr_id = $this->getAppraiseeId();
1538 }
1539
1540 if ($appr_id == 0) {
1541 return;
1542 }
1543
1544 // evaluation modes
1545 $eval_modes = array();
1546
1547 // get all competences of survey
1548 include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1549 $sskill = new ilSurveySkill($survey);
1550 $opts = $sskill->getAllAssignedSkillsAsOptions();
1551 $skills = array();
1552 foreach ($opts as $id => $o) {
1553 $idarr = explode(":", $id);
1554 $skills[$id] = array("id" => $id, "title" => $o, "profiles" => array(),
1555 "base_skill" => $idarr[0], "tref_id" => $idarr[1]);
1556 }
1557 //var_dump($opts);
1558
1559 // get matching user competence profiles
1560 // -> add gap analysis to profile
1561 include_once("./Services/Skill/classes/class.ilSkillProfile.php");
1563 foreach ($profiles as $p) {
1564 $prof = new ilSkillProfile($p["id"]);
1565 $prof_levels = $prof->getSkillLevels();
1566 foreach ($prof_levels as $pl) {
1567 if (isset($skills[$pl["base_skill_id"] . ":" . $pl["tref_id"]])) {
1568 $skills[$pl["base_skill_id"] . ":" . $pl["tref_id"]]["profiles"][] =
1569 $p["id"];
1570
1571 $eval_modes["gap_" . $p["id"]] =
1572 $lng->txt("svy_gap_analysis") . ": " . $prof->getTitle();
1573 }
1574 }
1575 }
1576 //var_dump($skills);
1577 //var_dump($eval_modes);
1578
1579 // if one competence does not match any profiles
1580 // -> add "competences of survey" alternative
1581 reset($skills);
1582 foreach ($skills as $sk) {
1583 if (count($sk["profiles"]) == 0) {
1584 $eval_modes["skills_of_survey"] = $lng->txt("svy_all_survey_competences");
1585 }
1586 }
1587
1588 // final determination of current evaluation mode
1589 $comp_eval_mode = $_GET["comp_eval_mode"];
1590 if ($_POST["comp_eval_mode"] != "") {
1591 $comp_eval_mode = $_POST["comp_eval_mode"];
1592 }
1593
1594 if (!isset($eval_modes[$comp_eval_mode])) {
1595 reset($eval_modes);
1596 $comp_eval_mode = key($eval_modes);
1597 $ilCtrl->setParameter($this, "comp_eval_mode", $comp_eval_mode);
1598 }
1599
1600 $ilCtrl->saveParameter($this, "comp_eval_mode");
1601
1602 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1603 $mode_sel = new ilSelectInputGUI($lng->txt("svy_analysis"), "comp_eval_mode");
1604 $mode_sel->setOptions($eval_modes);
1605 $mode_sel->setValue($comp_eval_mode);
1606 $ilToolbar->addInputItem($mode_sel, true);
1607
1608 $ilToolbar->addFormButton($lng->txt("select"), "competenceEval");
1609
1610 if (substr($comp_eval_mode, 0, 4) == "gap_") {
1611 // gap analysis
1612 $profile_id = (int) substr($comp_eval_mode, 4);
1613
1614 include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1615 $pskills_gui = new ilPersonalSkillsGUI();
1616 $pskills_gui->setProfileId($profile_id);
1617 $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("skmg_eval_type_1"));
1618 if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0) {
1619 $sskill = new ilSurveySkill($survey);
1620 $self_levels = array();
1621 foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl) {
1622 $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1623 }
1624 $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1625 }
1626 $html = $pskills_gui->getGapAnalysisHTML($appr_id);
1627
1628 $tpl->setContent($html);
1629 } else { // must be all survey competences
1630 include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1631 $pskills_gui = new ilPersonalSkillsGUI();
1632 #23743
1633 if ($survey->getMode() != ilObjSurvey::MODE_SELF_EVAL) {
1634 $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("skmg_eval_type_1"));
1635 }
1636 if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0) {
1637 $sskill = new ilSurveySkill($survey);
1638 $self_levels = array();
1639 foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl) {
1640 $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1641 }
1642 $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1643 }
1644 $sk = array();
1645 foreach ($skills as $skill) {
1646 $sk[] = array(
1647 "base_skill_id" => (int) $skill["base_skill"],
1648 "tref_id" => (int) $skill["tref_id"]
1649 );
1650 }
1651 $html = $pskills_gui->getGapAnalysisHTML($appr_id, $sk);
1652
1653 $tpl->setContent($html);
1654 }
1655 }
1656
1660 protected function hasResultsAccess()
1661 {
1662 return $this->access->checkRbacOrPositionPermissionAccess('read_results', 'access_results', $this->object->getRefId());
1663 }
1664}
user()
Definition: user.php:4
$path
Definition: aliased.php:25
exit
Definition: backend.php:16
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
getExportGrid($a_results)
Get grid data.
getGrid($a_results, $a_abs=true, $a_perc=true)
Get grid data.
getTextAnswers($a_results)
Get text answers.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
static _instanciateQuestionEvaluation($question_id, array $a_finished_ids=null)
Creates an instance of a question evaluation with a given question id.
const IL_CAL_UNIX
Accordion user interface class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
@classDescription Date and time handling
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setColors($a_coords, $a_background, $a_font=null)
Set cell(s) colors.
setBold($a_coords)
Set cell(s) to bold.
addSheet($a_name, $a_activate=true)
Add sheet.
getCoordByColumnAndRow($pColumn=1, $pRow=1)
Get cell coordinate (e.g.
static getInstance()
Factory.
static getLogger($a_component_id)
Get component logger.
static getInstance()
Get instance.
static _hasEvaluationAccess($a_obj_id, $user_id)
const EVALUATION_ACCESS_PARTICIPANTS
const RESULTS_SELF_EVAL_ALL
const EVALUATION_ACCESS_ALL
static _getQuestionblock($questionblock_id)
Returns the database row for a given question block.
const EVALUATION_ACCESS_OFF
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjId($a_id)
Personal skills GUI class.
This class represents a property form user interface.
This class represents a selection list property in a property form.
static getProfilesOfUser($a_user_id)
Get profiles of a user.
static getInstance()
Factory.
Survey evaluation graphical output.
exportResultsDetailsExcel(ilExcel $a_excel, SurveyQuestionEvaluation $a_eval, $a_results, $a_do_title, $a_do_label)
Export details (excel only)
setEvalSubtabs()
Set the tabs for the evaluation output.
filterSurveyParticipantsByAccess($a_finished_ids)
__construct($a_object)
ilSurveyEvaluationGUI constructor
cancelEvaluationAccess()
Cancels the input of the survey access code for evaluation access.
addApprSelectionToToolbar()
Add appraisee selection to toolbar.
checkAnonymizedEvaluationAccess()
Show the detailed evaluation.
renderDetails($a_details_parts, $a_details_figure, array $a_qdata, SurveyQuestionEvaluation $a_eval, $a_results)
Render details.
setAppraiseeId($a_val)
Set appraisee id.
processCSVRow($row, $quoteAll=false, $separator=";")
Processes an array as a CSV row and converts the array values to correct CSV values.
evaluationdetails()
Show the detailed evaluation.
hasResultsAccess()
Check if user can view results granted by rbac or positions.
determineAppraiseeId()
Determine appraisee id.
parseResultsToExcel(ilExcel $a_excel, ilSurveyEvaluationResults $a_results, &$a_excel_row, array $a_grid=null, array $a_text_answers=null, $a_include_mode=true)
checkEvaluationAccess()
Checks the evaluation access after entering the survey access code.
competenceEval()
Competence Evaluation.
parseUserSpecificResults(array $a_finished_ids=null)
evaluationuser()
Print the survey evaluation for a selected user.
Skill/Competence handling in surveys.
special template class to simplify handling of ITX/PEAR
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$key
Definition: croninfo.php:18
$valid
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
const TYPE_SPSS
$format
Definition: metadata.php:141
$grid
Definition: test.php:8
$matrix
Definition: test.php:18
$row
$ret
Definition: parser.php:6
$type
if(isset($_POST['submit'])) $form
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
global $DIC
Definition: saml.php:7
$results
Definition: svg-scanner.php:47
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6
$cols
Definition: xhr_table.php:11
$rows
Definition: xhr_table.php:10