ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.AbstractUIModifier.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
26 
30 abstract class AbstractUIModifier implements UIModifier
31 {
33  protected ?InternalService $service = null;
34 
35  public function __construct(InternalGUIService $gui)
36  {
37  $this->gui = $gui;
38  }
39 
40  public function setInternalService(InternalService $internal_service): void
41  {
42  $this->service = $internal_service;
43  }
44 
46  {
47  return $this->service;
48  }
49 
50  public function getSurveySettingsGeneral(
51  \ilObjSurvey $survey
52  ): array {
53  return [];
54  }
55 
57  \ilObjSurvey $survey,
58  InternalGUIService $ui_service
59  ): array {
60  return [];
61  }
62 
63  public function getSurveySettingsResults(
64  \ilObjSurvey $survey,
65  InternalGUIService $ui_service
66  ): array {
67  return [];
68  }
69 
70  public function setValuesFromForm(
71  \ilObjSurvey $survey,
72  \ilPropertyFormGUI $form
73  ): void {
74  }
75 
76  public function setResultsOverviewToolbar(
77  \ilObjSurvey $survey,
78  \ilToolbarGUI $toolbar,
79  int $user_id
80  ): void {
81  $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
82  if ($config->usesAppraisees()) {
84  $survey,
85  $toolbar,
86  $user_id
87  );
88  }
89 
91  $survey,
92  $toolbar,
93  false
94  );
95  }
96 
97  public function setResultsCompetenceToolbar(
98  \ilObjSurvey $survey,
99  \ilToolbarGUI $toolbar,
100  int $user_id
101  ): void {
103  $survey,
104  $toolbar,
105  $user_id
106  );
107  }
108 
109 
110  public function setResultsDetailToolbar(
111  \ilObjSurvey $survey,
112  \ilToolbarGUI $toolbar,
113  int $user_id
114  ): void {
115  $request = $this->service
116  ->gui()
117  ->evaluation($survey)
118  ->request();
119 
120  $gui = $this->service->gui();
121  $lng = $gui->lng();
122 
123  $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
124  if ($config->usesAppraisees()) {
126  $survey,
127  $toolbar,
128  $user_id
129  );
130  }
131 
132  $captions = new \ilSelectInputGUI($lng->txt("svy_eval_captions"), "cp");
133  $captions->setOptions(array(
134  "ap" => $lng->txt("svy_eval_captions_abs_perc"),
135  "a" => $lng->txt("svy_eval_captions_abs"),
136  "p" => $lng->txt("svy_eval_captions_perc")
137  ));
138  $captions->setValue($request->getCP());
139  $toolbar->addInputItem($captions, true);
140 
141  $view = new \ilSelectInputGUI($lng->txt("svy_eval_view"), "vw");
142  $view->setOptions(array(
143  "tc" => $lng->txt("svy_eval_view_tables_charts"),
144  "t" => $lng->txt("svy_eval_view_tables"),
145  "c" => $lng->txt("svy_eval_view_charts")
146  ));
147  $view->setValue($request->getVW());
148  $toolbar->addInputItem($view, true);
149 
150  $this->gui->button(
151  $this->gui->lng()->txt("ok"),
152  "evaluationdetails"
153  )->submit()->toToolbar(false, $toolbar);
154 
155  $toolbar->addSeparator();
156 
158  $survey,
159  $toolbar,
160  true
161  );
162  }
163 
164  protected function addExportAndPrintButton(
165  \ilObjSurvey $survey,
166  \ilToolbarGUI $toolbar,
167  bool $details
168  ): void {
169  $modal_id = "svy_ev_exp";
170  $modal = $this->buildExportModal($modal_id, $details
171  ? 'exportDetailData'
172  : 'exportData');
173 
174  $this->gui->button(
175  $this->gui->lng()->txt("export"),
176  "#"
177  )->onClick('$(\'#' . $modal_id . '\').modal(\'show\')')->toToolbar(false, $toolbar);
178 
179  $toolbar->addSeparator();
180 
181  if ($details) {
182  $pv = $this->service->gui()->print()->resultsDetails($survey->getRefId());
183  $this->service->gui()->ctrl()->setParameterByClass(
184  "ilSurveyEvaluationGUI",
185  "vw",
186  $this->service->gui()->evaluation($survey)->request()->getVW()
187  );
188  $this->service->gui()->ctrl()->setParameterByClass(
189  "ilSurveyEvaluationGUI",
190  "cp",
191  $this->service->gui()->evaluation($survey)->request()->getCP()
192  );
193  $modal_elements = $pv->getModalElements(
194  $this->service->gui()->ctrl()->getLinkTargetByClass(
195  "ilSurveyEvaluationGUI",
196  "printResultsDetailsSelection"
197  )
198  );
199  } else {
200  $pv = $this->service->gui()->print()->resultsOverview($survey->getRefId());
201  $modal_elements = $pv->getModalElements(
202  $this->service->gui()->ctrl()->getLinkTargetByClass(
203  "ilSurveyEvaluationGUI",
204  "printResultsOverviewSelection"
205  )
206  );
207  }
208 
209  $toolbar->addComponent($modal_elements->button);
210  $toolbar->addComponent($modal_elements->modal);
211 
212  /*
213  $button = \ilLinkButton::getInstance();
214  $button->setCaption("print");
215  $button->setOnClick("if(il.Accordion) { il.Accordion.preparePrint(); } window.print(); return false;");
216  $button->setOmitPreventDoubleSubmission(true);
217  $toolbar->addButtonInstance($button);*/
218 
219  $toolbar->addText($modal);
220  }
221 
222  protected function buildExportModal(
223  string $a_id,
224  string $a_cmd
225  ): string {
226  $tpl = $this->service->gui()->mainTemplate();
227  $lng = $this->service->gui()->lng();
228  $ctrl = $this->service->gui()->ctrl();
229 
230  $form_id = "svymdfrm";
231 
232  // hide modal on form submit
233  $tpl->addOnLoadCode('$("#form_' . $form_id . '").submit(function() { $("#' . $a_id . '").modal("hide"); });');
234 
235  $modal = \ilModalGUI::getInstance();
236  $modal->setId($a_id);
237  $modal->setHeading(($lng->txt("svy_export_format")));
238 
239  $form = new \ilPropertyFormGUI();
240  $form->setId($form_id);
241  $form->setFormAction($ctrl->getFormActionByClass("ilsurveyevaluationgui", $a_cmd));
242 
243  $format = new \ilSelectInputGUI($lng->txt("filetype"), "export_format");
244  $format->setOptions(array(
245  \ilSurveyEvaluationGUI::TYPE_XLS => $lng->txt('exp_type_excel'),
246  \ilSurveyEvaluationGUI::TYPE_SPSS => $lng->txt('exp_type_csv')
247  ));
248  $form->addItem($format);
249 
250  $label = new \ilSelectInputGUI($lng->txt("title"), "export_label");
251  $label->setOptions(array(
252  'label_only' => $lng->txt('export_label_only'),
253  'title_only' => $lng->txt('export_title_only'),
254  'title_label' => $lng->txt('export_title_label')
255  ));
256  $form->addItem($label);
257 
258  $form->addCommandButton($a_cmd, $lng->txt("export"));
259  $form->setPreventDoubleSubmission(false);
260 
261  $modal->setBody($form->getHTML());
262 
263  return $modal->getHTML();
264  }
265 
266  public function addApprSelectionToToolbar(
267  \ilObjSurvey $survey,
268  \ilToolbarGUI $toolbar,
269  int $user_id
270  ): void {
271  $lng = $this->service->gui()->lng();
272  $ctrl = $this->service->gui()->ctrl();
273  $req = $this->service->gui()->evaluation($survey)->request();
274 
275  $evaluation_manager = $this->service->domain()->evaluation(
276  $survey,
277  $user_id,
278  $req->getAppraiseeId(),
279  $req->getRaterId()
280  );
281 
282  if ($evaluation_manager->isMultiParticipantsView()) {
283  $appr_id = $evaluation_manager->getCurrentAppraisee();
284  $options = array();
285  if (!$appr_id) {
286  $options[""] = $lng->txt("please_select");
287  }
288 
289  foreach ($evaluation_manager->getSelectableAppraisees() as $appraisee_usr_id) {
290  $options[$appraisee_usr_id] = \ilUserUtil::getNamePresentation(
291  $appraisee_usr_id,
292  false,
293  false,
294  "",
295  true
296  );
297  }
298 
299  $appr = new \ilSelectInputGUI($lng->txt("survey_360_appraisee"), "appr_id");
300  $appr->setOptions($options);
301  $appr->setValue($appr_id);
302  $toolbar->addInputItem($appr, true);
303 
304  $this->gui->button(
305  $lng->txt("survey_360_select_appraisee"),
306  $ctrl->getCmd()
307  )->submit()->toToolbar(false, $toolbar);
308 
309  if ($appr_id) {
310  $toolbar->addSeparator();
311  }
312  }
313  }
314 
315 
316  public function getDetailPanels(
317  array $participants,
318  \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
319  \SurveyQuestionEvaluation $a_eval
320  ): array {
321  $a_results = $a_eval->getResults();
322  $panels = [];
323  $ui_factory = $this->service->gui()->ui()->factory();
324 
325  $a_tpl = new \ilTemplate("tpl.svy_results_details_panel.html", true, true, "Modules/Survey/Evaluation");
326 
327  $question_res = $a_results;
328  $matrix = false;
329  if (is_array($question_res)) {
330  $question_res = $question_res[0][1];
331  $matrix = true;
332  }
333 
334  // see #28507 (matrix question without a row)
335  if (!is_object($question_res)) {
336  return [];
337  }
338 
339  $question = $question_res->getQuestion();
340 
341  // question "overview"
342  $qst_title = $question->getTitle();
343  $svy_text = nl2br($question->getQuestiontext());
344 
345  // Question title anchor
346  $anchor_id = "svyrdq" . $question->getId();
347  $title = "<span id='$anchor_id'>$qst_title</span>";
348  $panel_qst_card = $ui_factory->panel()->sub($title, $ui_factory->legacy($svy_text))
349  ->withFurtherInformation($this->getPanelCard($question_res));
350 
351  $panels[] = $panel_qst_card;
352 
353  $a_tpl->setVariable("TABLE", $this->getPanelTable(
354  $participants,
355  $request,
356  $a_eval
357  ));
358 
359  $a_tpl->setVariable("TEXT", $this->getPanelText(
360  $request,
361  $a_eval,
362  $question_res
363  ));
364 
365  $a_tpl->setVariable("CHART", $this->getPanelChart(
366  $request,
367  $a_eval
368  ));
369 
370 
371  $panels[] = $ui_factory->panel()->sub("", $ui_factory->legacy($a_tpl->get()));
372  return $panels;
373  }
374 
375  protected function getPanelTable(
376  array $participants,
377  \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
378  \SurveyQuestionEvaluation $a_eval
379  ): string {
380  $a_results = $a_eval->getResults();
381 
382  $a_tpl = new \ilTemplate("tpl.svy_results_details_table.html", true, true, "Modules/Survey/Evaluation");
383 
384  // grid
385  if ($request->getShowTable()) {
386  $grid = $a_eval->getGrid(
387  $a_results,
388  $request->getShowAbsolute(),
389  $request->getShowPercentage()
390  );
391  if ($grid) {
392  foreach ($grid["cols"] as $col) {
393  $a_tpl->setCurrentBlock("grid_col_header_bl");
394  $a_tpl->setVariable("COL_HEADER", $col);
395  $a_tpl->parseCurrentBlock();
396  }
397  foreach ($grid["rows"] as $cols) {
398  foreach ($cols as $idx => $col) {
399  if ($idx > 0) {
400  $a_tpl->touchBlock("grid_col_nowrap_bl");
401  }
402 
403  $a_tpl->setCurrentBlock("grid_col_bl");
404  $a_tpl->setVariable("COL_CAPTION", trim((string) ($col ?? "")));
405  $a_tpl->parseCurrentBlock();
406  }
407 
408  $a_tpl->touchBlock("grid_row_bl");
409  }
410  }
411  }
412  return $a_tpl->get();
413  }
414 
415  protected function getPanelChart(
416  \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
417  \SurveyQuestionEvaluation $a_eval
418  ): string {
419  $a_results = $a_eval->getResults();
420 
421  $a_tpl = new \ilTemplate("tpl.svy_results_details_chart.html", true, true, "Modules/Survey/Evaluation");
422  // chart
423  if ($request->getShowChart()) {
424  $chart = $a_eval->getChart($a_results);
425  if ($chart) {
426  if (is_array($chart)) {
427  // legend
428  if (is_array($chart[1])) {
429  foreach ($chart[1] as $legend_item) {
430  $r = hexdec(substr($legend_item[1], 1, 2));
431  $g = hexdec(substr($legend_item[1], 3, 2));
432  $b = hexdec(substr($legend_item[1], 5, 2));
433 
434  $a_tpl->setCurrentBlock("legend_bl");
435  $a_tpl->setVariable("LEGEND_CAPTION", $legend_item[0]);
436  $a_tpl->setVariable("LEGEND_COLOR", $legend_item[1]);
437  $a_tpl->setVariable("LEGEND_COLOR_SVG", $r . "," . $g . "," . $b);
438  $a_tpl->parseCurrentBlock();
439  }
440  }
441 
442  $chart = $chart[0];
443  }
444 
445  $a_tpl->setVariable("CHART", $chart);
446  }
447  }
448 
449  return $a_tpl->get();
450  }
451 
452  protected function getPanelText(
453  \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
454  \SurveyQuestionEvaluation $a_eval,
455  \ilSurveyEvaluationResults $question_res
456  ): string {
457  $a_results = $a_eval->getResults();
458  $question = $question_res->getQuestion();
459  $lng = $this->service->gui()->lng();
460 
461  $a_tpl = new \ilTemplate("tpl.svy_results_details_text.html", true, true, "Modules/Survey/Evaluation");
462 
463  // text answers
464  $texts = $a_eval->getTextAnswers($a_results);
465  if ($texts) {
466  if (array_key_exists("", $texts)) {
467  $a_tpl->setVariable("TEXT_HEADING", $lng->txt("given_answers"));
468  foreach ($texts[""] as $item) {
469  $a_tpl->setCurrentBlock("text_direct_item_bl");
470  $a_tpl->setVariable("TEXT_DIRECT", nl2br(htmlentities($item)));
471  $a_tpl->parseCurrentBlock();
472  }
473  } else {
474  $acc = new \ilAccordionGUI();
475  $acc->setId("svyevaltxt" . $question->getId());
476 
477  $a_tpl->setVariable("TEXT_HEADING", $lng->txt("freetext_answers"));
478 
479  foreach ($texts as $var => $items) {
480  $list = array("<ul class=\"small\">");
481  foreach ($items as $item) {
482  $list[] = "<li>" . nl2br(htmlentities($item)) . "</li>";
483  }
484  $list[] = "</ul>";
485  $acc->addItem((string) $var, implode("\n", $list));
486  }
487 
488  $a_tpl->setVariable("TEXT_ACC", $acc->getHTML());
489  }
490  }
491  return $a_tpl->get();
492  }
493 
494  // in fact we want a \ILIAS\UI\Component\Card\Standard
495  // see #31743
496  protected function getPanelCard(
497  \ilSurveyEvaluationResults $question_res
498  ): \ILIAS\UI\Component\Card\Card {
499  $ui_factory = $this->service->gui()->ui()->factory();
500  $lng = $this->service->gui()->lng();
501 
502  $question = $question_res->getQuestion();
503  $kv = array();
504  $kv["users_answered"] = $question_res->getUsersAnswered();
505  $kv["users_skipped"] = $question_res->getUsersSkipped();
506 
507  $card_table_tpl = new \ilTemplate(
508  "tpl.svy_results_details_card.html",
509  true,
510  true,
511  "Modules/Survey/Evaluation"
512  );
513 
514  if (true) { // formerly check for matrix type, shouldnt be needed
515  if ($question_res->getModeValue() !== null) {
516  $kv["mode"] = wordwrap($question_res->getModeValueAsText(), 50, "<br />");
517  $kv["mode_nr_of_selections"] = $question_res->getModeNrOfSelections();
518  }
519  if ($question_res->getMedian() !== null) {
520  $kv["median"] = $question_res->getMedianAsText();
521  }
522  if ($question_res->getMean() !== null) {
523  $kv["arithmetic_mean"] = $question_res->getMean();
524  }
525  }
526 
527  foreach ($kv as $key => $value) {
528  $card_table_tpl->setCurrentBlock("question_statistics_card");
529  $card_table_tpl->setVariable("QUESTION_STATISTIC_KEY", $lng->txt($key));
530  $card_table_tpl->setVariable("QUESTION_STATISTIC_VALUE", $value);
531  $card_table_tpl->parseCurrentBlock();
532  }
533 
534  $svy_type_title = \SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
535 
536  return $ui_factory->card()
537  ->standard($svy_type_title)
538  ->withSections(
539  array($ui_factory->legacy($card_table_tpl->get()))
540  );
541  }
542 }
buildExportModal(string $a_id, string $a_cmd)
addText(string $a_text)
setResultsCompetenceToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
setValuesFromForm(\ilObjSurvey $survey, \ilPropertyFormGUI $form)
Class ChatMainBarProvider .
getPanelTable(array $participants, \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
addComponent(\ILIAS\UI\Component\Component $a_comp)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSurveySettingsReminderTargets(\ilObjSurvey $survey, InternalGUIService $ui_service)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
catch(\Exception $e) $req
Definition: xapiproxy.php:93
getDetailPanels(array $participants, \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
array $details
Details for error message relating to last request processed.
Definition: System.php:109
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
addApprSelectionToToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
$lng
setResultsOverviewToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
getPanelCard(\ilSurveyEvaluationResults $question_res)
string $key
Consumer key/client ID value.
Definition: System.php:193
addExportAndPrintButton(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, bool $details)
getPanelChart(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
setInternalService(InternalService $internal_service)
setResultsDetailToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
static getInstance()
getSurveySettingsResults(\ilObjSurvey $survey, InternalGUIService $ui_service)
getGrid( $a_results, bool $a_abs=true, bool $a_perc=true)
Get grid data.
addInputItem(ilToolbarItem $a_item, bool $a_output_label=false)
getPanelText(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval, \ilSurveyEvaluationResults $question_res)
getTextAnswers($a_results)
Get text answers.
$r