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