ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.AbstractUIModifier.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
32abstract class AbstractUIModifier implements UIModifier
33{
35 protected ?InternalService $service = null;
36
38 {
39 $this->gui = $gui;
40 }
41
42 public function setInternalService(InternalService $internal_service): void
43 {
44 $this->service = $internal_service;
45 }
46
48 {
49 return $this->service;
50 }
51
52 public function getSurveySettingsGeneral(
53 \ilObjSurvey $survey
54 ): array {
55 return [];
56 }
57
59 \ilObjSurvey $survey,
60 InternalGUIService $ui_service
61 ): array {
62 return [];
63 }
64
65 public function getSurveySettingsResults(
66 \ilObjSurvey $survey,
67 InternalGUIService $ui_service
68 ): array {
69 return [];
70 }
71
72 public function setValuesFromForm(
73 \ilObjSurvey $survey,
75 ): void {
76 }
77
78 public function setResultsOverviewToolbar(
79 \ilObjSurvey $survey,
81 \ilTemplate $eval_tpl
82 ): array {
83 $components = [];
84
85 $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
86 if ($config->usesAppraisees()) {
87 $components = array_merge(
89 $this->getApprSelectionComponents($survey, $user_id)
90 );
91 }
92
93 $components = array_merge(
95 $this->getExportAndPrintComponents($survey, false, $eval_tpl)
96 );
97
98 return $components;
99 }
100
102 \ilObjSurvey $survey,
103 int $user_id
104 ): array {
105 return $this->getApprSelectionComponents($survey, $user_id);
106 }
107
111 public function setResultsDetailToolbar(
112 \ilObjSurvey $survey,
113 int $user_id,
114 \ilTemplate $eval_tpl
115 ): array {
116 $components = [];
117
118 $request = $this->service
119 ->gui()
120 ->evaluation($survey)
121 ->request();
122
123 $gui = $this->service->gui();
124 $lng = $gui->lng();
125 $ctrl = $gui->ctrl();
126 $ui_fac = $gui->ui()->factory();
127
128 $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
129 if ($config->usesAppraisees()) {
130 $components = array_merge(
132 $this->getApprSelectionComponents($survey, $user_id)
133 );
134 }
135
136 $caption_options = [
137 "ap" => $lng->txt("svy_eval_captions_abs_perc"),
138 "a" => $lng->txt("svy_eval_captions_abs"),
139 "p" => $lng->txt("svy_eval_captions_perc"),
140 ];
141 $current_cp = $request->getCP();
142 $caption_items = [];
143 foreach ($caption_options as $key => $label) {
144 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "cp", $key);
145 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "vw", $request->getVW());
146 $caption_items[] = $ui_fac->button()->shy(
147 $label,
148 $ctrl->getLinkTargetByClass("ilSurveyEvaluationGUI", "evaluationdetails")
149 );
150 }
151 // reset parameter
152 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "cp", $current_cp);
153 $components[] = $ui_fac->dropdown()->standard($caption_items)
154 ->withLabel($caption_options[$current_cp] ?? $lng->txt("svy_eval_captions"));
155
156 // View dropdown (replaces ilSelectInputGUI "vw")
157 $view_options = [
158 "tc" => $lng->txt("svy_eval_view_tables_charts"),
159 "t" => $lng->txt("svy_eval_view_tables"),
160 "c" => $lng->txt("svy_eval_view_charts"),
161 ];
162 $current_vw = $request->getVW();
163 $view_items = [];
164 foreach ($view_options as $key => $label) {
165 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "vw", $key);
166 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "cp", $request->getCP());
167 $view_items[] = $ui_fac->button()->shy(
168 $label,
169 $ctrl->getLinkTargetByClass("ilSurveyEvaluationGUI", "evaluationdetails")
170 );
171 }
172 // reset parameter
173 $ctrl->setParameterByClass("ilSurveyEvaluationGUI", "vw", $current_vw);
174 $components[] = $ui_fac->dropdown()->standard($view_items)
175 ->withLabel($view_options[$current_vw] ?? $lng->txt("svy_eval_view"));
176
177 // Separator + export/print
178 $components = array_merge(
180 $this->getExportAndPrintComponents($survey, true, $eval_tpl)
181 );
182
183 return $components;
184 }
185
190 \ilObjSurvey $survey,
191 int $user_id
192 ): array {
193 $components = [];
194
195 $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
196 if ($config->usesAppraisees()) {
197 $components = array_merge(
199 $this->getApprSelectionComponents($survey, $user_id)
200 );
201 }
202
203 return $components;
204 }
205
206 protected function getExportAndPrintComponents(
207 \ilObjSurvey $survey,
208 bool $details,
209 \ilTemplate $eval_tpl
210 ): array {
211 $components = [];
212
213 // Export button + modal
214 $this->buildExportButtonAndModal($eval_tpl, $details ? "exportDetailData" : "exportData");
215
216 if ($details) {
217 $pv = $this->service->gui()->print()->resultsDetails($survey->getRefId());
218 $this->service->gui()->ctrl()->setParameterByClass(
219 "ilSurveyEvaluationGUI",
220 "vw",
221 $this->service->gui()->evaluation($survey)->request()->getVW()
222 );
223 $this->service->gui()->ctrl()->setParameterByClass(
224 "ilSurveyEvaluationGUI",
225 "cp",
226 $this->service->gui()->evaluation($survey)->request()->getCP()
227 );
228 $modal_elements = $pv->getModalElements(
229 $this->service->gui()->ctrl()->getLinkTargetByClass(
230 "ilSurveyEvaluationGUI",
231 "printResultsDetailsSelection"
232 )
233 );
234 } else {
235 $pv = $this->service->gui()->print()->resultsOverview($survey->getRefId());
236 $modal_elements = $pv->getModalElements(
237 $this->service->gui()->ctrl()->getLinkTargetByClass(
238 "ilSurveyEvaluationGUI",
239 "printResultsOverviewSelection"
240 )
241 );
242 }
243
244 $components[] = $modal_elements->button;
245 $components[] = $modal_elements->modal;
246
247 return $components;
248 }
249
250 protected function getApprSelectionComponents(
251 \ilObjSurvey $survey,
252 int $user_id
253 ): array {
254 $this->addApprSelectionToToolbar(
255 $survey,
256 $this->gui->toolbar(),
258 );
259 return [];
260 }
261
262 protected function buildExportButtonAndModal(
263 \ilTemplate $eval_tpl,
264 string $export_cmd
265 ): void {
266 $lng = $this->gui->lng();
267 $ctrl = $this->gui->ctrl();
268 $toolbar = $this->gui->toolbar();
269 $ui_fac = $this->gui->ui()->factory();
270 $ui_ren = $this->gui->ui()->renderer();
271 $ui_request = $this->gui->http()->request();
272
273 $ctrl->setParameterByClass("ilsurveyevaluationgui", "export_cmd", $export_cmd);
274 $modal = $this->getExportModal();
275 $button = $ui_fac->button()->standard(
276 $lng->txt("export"),
277 "#"
278 )->withOnClick($modal->getShowSignal());
279
280 $toolbar->addComponent($button);
281 if ("POST" === $ui_request->getMethod()
282 && isset($ui_request->getQueryParams()["fallbackCmd"])
283 && $ui_request->getQueryParams()["fallbackCmd"] === "validateAndSubmitExportForm") {
284 $modal = $modal->withRequest($ui_request);
285 $eval_tpl->setVariable("MODAL", $ui_ren->render($modal->withOnLoad($modal->getShowSignal())));
286 } else {
287 $eval_tpl->setVariable("MODAL", $ui_ren->render($modal));
288 }
289 }
290
292 {
293 $lng = $this->gui->lng();
294 $ctrl = $this->gui->ctrl();
295 $ui_fac = $this->gui->ui()->factory();
296
297 $post_url = $ctrl->getFormActionByClass("ilsurveyevaluationgui", "validateAndSubmitExportForm");
298
299 $inputs["export_format"] = $ui_fac->input()->field()->select(
300 $lng->txt("filetype"),
301 [
302 \ilSurveyEvaluationGUI::TYPE_XLS => $lng->txt("exp_type_excel"),
303 \ilSurveyEvaluationGUI::TYPE_SPSS => $lng->txt("exp_type_csv")
304 ]
305 )
306 //->withValue(\ilSurveyEvaluationGUI::TYPE_XLS)
307 ->withRequired(true);
308
309 $inputs["export_label"] = $ui_fac->input()->field()->select(
310 $lng->txt("title"),
311 [
312 "label_only" => $lng->txt("export_label_only"),
313 "title_only" => $lng->txt("export_title_only"),
314 "title_label" => $lng->txt("export_title_label")
315 ]
316 )
317 //->withValue("label_only")
318 ->withRequired(true);
319
320 $modal = $ui_fac->modal()->roundtrip(
321 $lng->txt("svy_export_format"),
322 null,
323 $inputs,
324 $post_url
325 )
326 ->withSubmitLabel($lng->txt("export"));
327
328 return $modal;
329 }
330
332 \ilObjSurvey $survey,
333 \ilToolbarGUI $toolbar,
334 int $user_id
335 ): void {
336 $lng = $this->service->gui()->lng();
337 $ctrl = $this->service->gui()->ctrl();
338 $req = $this->service->gui()->evaluation($survey)->request();
339
340 $evaluation_manager = $this->service->domain()->evaluation(
341 $survey,
342 $user_id,
343 $req->getAppraiseeId(),
344 $req->getRaterId()
345 );
346
347 if ($evaluation_manager->isMultiParticipantsView()) {
348 $appr_id = $evaluation_manager->getCurrentAppraisee();
349 $options = array();
350 if (!$appr_id) {
351 $options[""] = $lng->txt("please_select");
352 }
353
354 foreach ($evaluation_manager->getSelectableAppraisees() as $appraisee_usr_id) {
355 $options[$appraisee_usr_id] = \ilUserUtil::getNamePresentation(
356 $appraisee_usr_id,
357 false,
358 false,
359 "",
360 true
361 );
362 }
363
364 $appr = new \ilSelectInputGUI($lng->txt("survey_360_appraisee"), "appr_id");
365 $appr->setOptions($options);
366 $appr->setValue($appr_id);
367 $toolbar->addInputItem($appr, true);
368
369 $this->gui->button(
370 $lng->txt("survey_360_select_appraisee"),
371 $ctrl->getCmd()
372 )->submit()->toToolbar(false, $toolbar);
373
374 if ($appr_id) {
375 $toolbar->addSeparator();
376 }
377 }
378 }
379
380 public function getDetailPanels(
381 array $participants,
382 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
384 ): array {
385 $a_results = $a_eval->getResults();
386 $panels = [];
387 $ui_factory = $this->service->gui()->ui()->factory();
388
389 $a_tpl = new \ilTemplate(
390 "tpl.svy_results_details_panel.html",
391 true,
392 true,
393 "components/ILIAS/Survey/Evaluation"
394 );
395
396 $question_res = $a_results;
397 $matrix = false;
398 if (is_array($question_res)) {
399 $question_res = $question_res[0][1];
400 $matrix = true;
401 }
402
403 if (!is_object($question_res)) {
404 return [];
405 }
406
407 $question = $question_res->getQuestion();
408
409 $qst_title = $question->getTitle();
410 $svy_text = nl2br($question->getQuestiontext());
411
412 $anchor_id = "svyrdq" . $question->getId();
413 $title = "<span id='$anchor_id'>$qst_title</span>";
414 $panel_qst_card = $ui_factory->panel()->sub($title, $ui_factory->legacy()->content($svy_text))
415 ->withFurtherInformation($this->getPanelCard($question_res));
416
417 $panels[] = $panel_qst_card;
418
419 $a_tpl->setVariable(
420 "TABLE",
421 $this->getPanelTable(
422 $participants,
423 $request,
424 $a_eval
425 )
426 );
427
428 $a_tpl->setVariable(
429 "TEXT",
430 $this->getPanelText(
431 $request,
432 $a_eval,
433 $question_res
434 )
435 );
436
437 $a_tpl->setVariable(
438 "CHART",
439 $this->getPanelChart(
440 $request,
441 $a_eval
442 )
443 );
444
445 $panels[] = $ui_factory->panel()->sub("", $ui_factory->legacy()->content($a_tpl->get()));
446 return $panels;
447 }
448
449 protected function getPanelTable(
450 array $participants,
451 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
453 ): string {
454 $a_results = $a_eval->getResults();
455
456 $a_tpl = new \ilTemplate(
457 "tpl.svy_results_details_table.html",
458 true,
459 true,
460 "components/ILIAS/Survey/Evaluation"
461 );
462
463 if ($request->getShowTable()) {
464 $grid = $a_eval->getGrid(
465 $a_results,
466 $request->getShowAbsolute(),
467 $request->getShowPercentage()
468 );
469 if ($grid) {
470 foreach ($grid["cols"] as $col) {
471 $a_tpl->setCurrentBlock("grid_col_header_bl");
472 $a_tpl->setVariable("COL_HEADER", $col);
473 $a_tpl->parseCurrentBlock();
474 }
475 foreach ($grid["rows"] as $cols) {
476 foreach ($cols as $idx => $col) {
477 if ($idx > 0) {
478 $a_tpl->touchBlock("grid_col_nowrap_bl");
479 }
480
481 $a_tpl->setCurrentBlock("grid_col_bl");
482 $a_tpl->setVariable("COL_CAPTION", trim((string) ($col ?? "")));
483 $a_tpl->parseCurrentBlock();
484 }
485
486 $a_tpl->touchBlock("grid_row_bl");
487 }
488 }
489 }
490 return $a_tpl->get();
491 }
492
493 protected function getPanelChart(
494 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
496 ): string {
497 $a_results = $a_eval->getResults();
498
499 $a_tpl = new \ilTemplate(
500 "tpl.svy_results_details_chart.html",
501 true,
502 true,
503 "components/ILIAS/Survey/Evaluation"
504 );
505 if ($request->getShowChart()) {
506 $chart = $a_eval->getChart($a_results);
507 if ($chart) {
508 if (is_array($chart)) {
509 if (is_array($chart[1])) {
510 foreach ($chart[1] as $legend_item) {
511 $r = hexdec(substr($legend_item[1], 1, 2));
512 $g = hexdec(substr($legend_item[1], 3, 2));
513 $b = hexdec(substr($legend_item[1], 5, 2));
514
515 $a_tpl->setCurrentBlock("legend_bl");
516 $a_tpl->setVariable("LEGEND_CAPTION", $legend_item[0]);
517 $a_tpl->setVariable("LEGEND_COLOR", $legend_item[1]);
518 $a_tpl->setVariable("LEGEND_COLOR_SVG", $r . "," . $g . "," . $b);
519 $a_tpl->parseCurrentBlock();
520 }
521 }
522
523 $chart = $chart[0];
524 }
525
526 $a_tpl->setVariable("CHART", $chart);
527 }
528 }
529
530 return $a_tpl->get();
531 }
532
533 protected function getPanelText(
534 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
536 \ilSurveyEvaluationResults $question_res
537 ): string {
538 $a_results = $a_eval->getResults();
539 $question = $question_res->getQuestion();
540 $lng = $this->service->gui()->lng();
541
542 $a_tpl = new \ilTemplate("tpl.svy_results_details_text.html", true, true, "components/ILIAS/Survey/Evaluation");
543
544 $texts = $a_eval->getTextAnswers($a_results);
545 if ($texts) {
546 if (array_key_exists("", $texts)) {
547 $a_tpl->setVariable("TEXT_HEADING", $lng->txt("given_answers"));
548 foreach ($texts[""] as $item) {
549 $a_tpl->setCurrentBlock("text_direct_item_bl");
550 $a_tpl->setVariable("TEXT_DIRECT", nl2br(htmlentities($item)));
551 $a_tpl->parseCurrentBlock();
552 }
553 } else {
554 $acc = new \ilAccordionGUI();
555 $acc->setId("svyevaltxt" . $question->getId());
556
557 $a_tpl->setVariable("TEXT_HEADING", $lng->txt("freetext_answers"));
558
559 foreach ($texts as $var => $items) {
560 $list = array("<ul class=\"small\">");
561 foreach ($items as $item) {
562 $list[] = "<li>" . nl2br(htmlentities($item)) . "</li>";
563 }
564 $list[] = "</ul>";
565 $acc->addItem((string) $var, implode("\n", $list));
566 }
567
568 $a_tpl->setVariable("TEXT_ACC", $acc->getHTML());
569 }
570 }
571 return $a_tpl->get();
572 }
573
574 protected function getPanelCard(
575 \ilSurveyEvaluationResults $question_res
577 $ui_factory = $this->service->gui()->ui()->factory();
578 $lng = $this->service->gui()->lng();
579
580 $question = $question_res->getQuestion();
581 $kv = array();
582 $kv["users_answered"] = $question_res->getUsersAnswered();
583 $kv["users_skipped"] = $question_res->getUsersSkipped();
584
585 $card_table_tpl = new \ilTemplate(
586 "tpl.svy_results_details_card.html",
587 true,
588 true,
589 "components/ILIAS/Survey/Evaluation"
590 );
591
592 if (true) { // formerly check for matrix type, shouldnt be needed
593 if ($question_res->getModeValue() !== null) {
594 $kv["mode"] = wordwrap($question_res->getModeValueAsText(), 50, "<br />");
595 $kv["mode_nr_of_selections"] = $question_res->getModeNrOfSelections();
596 }
597 if ($question_res->getMedian() !== null) {
598 $kv["median"] = $question_res->getMedianAsText();
599 }
600 if ($question_res->getMean() !== null) {
601 $kv["arithmetic_mean"] = $question_res->getMean();
602 }
603 }
604
605 foreach ($kv as $key => $value) {
606 $card_table_tpl->setCurrentBlock("question_statistics_card");
607 $card_table_tpl->setVariable("QUESTION_STATISTIC_KEY", $lng->txt($key));
608 $card_table_tpl->setVariable("QUESTION_STATISTIC_VALUE", $value);
609 $card_table_tpl->parseCurrentBlock();
610 }
611
612 $svy_type_title = \SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
613
614 return $ui_factory->card()
615 ->standard($svy_type_title)
616 ->withSections(
617 array($ui_factory->legacy()->content($card_table_tpl->get()))
618 );
619 }
620}
factory()
$components
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
setInternalService(InternalService $internal_service)
getExportAndPrintComponents(\ilObjSurvey $survey, bool $details, \ilTemplate $eval_tpl)
setResultsCompetenceToolbar(\ilObjSurvey $survey, int $user_id)
getPanelChart(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
setResultsParticipantToolbar(\ilObjSurvey $survey, int $user_id)
addApprSelectionToToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
setResultsDetailToolbar(\ilObjSurvey $survey, int $user_id, \ilTemplate $eval_tpl)
setValuesFromForm(\ilObjSurvey $survey, \ilPropertyFormGUI $form)
getPanelTable(array $participants, \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
getSurveySettingsResults(\ilObjSurvey $survey, InternalGUIService $ui_service)
buildExportButtonAndModal(\ilTemplate $eval_tpl, string $export_cmd)
getPanelCard(\ilSurveyEvaluationResults $question_res)
getPanelText(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval, \ilSurveyEvaluationResults $question_res)
getApprSelectionComponents(\ilObjSurvey $survey, int $user_id)
getSurveySettingsReminderTargets(\ilObjSurvey $survey, InternalGUIService $ui_service)
getDetailPanels(array $participants, \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
Definition: UI.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getGrid( $a_results, bool $a_abs=true, bool $a_perc=true)
Get grid data.
getTextAnswers($a_results)
Get text answers.
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addInputItem(ilToolbarItem $a_item, bool $a_output_label=false)
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=null)
Default behaviour is:
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between all forms.
Definition: Form.php:34
This describes commonalities between the different modals.
Definition: Modal.php:35
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
catch(\Exception $e) $req
Definition: xapiproxy.php:78
global $lng
Definition: privfeed.php:31