ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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,
80 \ilToolbarGUI $toolbar,
82 \ilTemplate $eval_tpl
83 ): void {
84 $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
85 if ($config->usesAppraisees()) {
86 $this->addApprSelectionToToolbar(
87 $survey,
88 $toolbar,
90 );
91 }
92
93 $this->addExportAndPrintButton(
94 $survey,
95 $toolbar,
96 false,
97 $eval_tpl
98 );
99 }
100
102 \ilObjSurvey $survey,
103 \ilToolbarGUI $toolbar,
104 int $user_id
105 ): void {
106 $this->addApprSelectionToToolbar(
107 $survey,
108 $toolbar,
110 );
111 }
112
113
114 public function setResultsDetailToolbar(
115 \ilObjSurvey $survey,
116 \ilToolbarGUI $toolbar,
117 int $user_id,
118 \ilTemplate $eval_tpl
119 ): void {
120 $request = $this->service
121 ->gui()
122 ->evaluation($survey)
123 ->request();
124
125 $gui = $this->service->gui();
126 $lng = $gui->lng();
127
128 $config = $this->getInternalService()->domain()->modeFeatureConfig($survey->getMode());
129 if ($config->usesAppraisees()) {
130 $this->addApprSelectionToToolbar(
131 $survey,
132 $toolbar,
134 );
135 }
136
137 $captions = new \ilSelectInputGUI($lng->txt("svy_eval_captions"), "cp");
138 $captions->setOptions(array(
139 "ap" => $lng->txt("svy_eval_captions_abs_perc"),
140 "a" => $lng->txt("svy_eval_captions_abs"),
141 "p" => $lng->txt("svy_eval_captions_perc")
142 ));
143 $captions->setValue($request->getCP());
144 $toolbar->addInputItem($captions, true);
145
146 $view = new \ilSelectInputGUI($lng->txt("svy_eval_view"), "vw");
147 $view->setOptions(array(
148 "tc" => $lng->txt("svy_eval_view_tables_charts"),
149 "t" => $lng->txt("svy_eval_view_tables"),
150 "c" => $lng->txt("svy_eval_view_charts")
151 ));
152 $view->setValue($request->getVW());
153 $toolbar->addInputItem($view, true);
154
155 $this->gui->button(
156 $this->gui->lng()->txt("ok"),
157 "evaluationdetails"
158 )->submit()->toToolbar(false, $toolbar);
159
160 $toolbar->addSeparator();
161
162 $this->addExportAndPrintButton(
163 $survey,
164 $toolbar,
165 true,
166 $eval_tpl
167 );
168 }
169
170 protected function addExportAndPrintButton(
171 \ilObjSurvey $survey,
172 \ilToolbarGUI $toolbar,
173 bool $details,
174 \ilTemplate $eval_tpl
175 ): void {
176 $this->buildExportButtonAndModal($eval_tpl, $details ? "exportDetailData" : "exportData");
177
178 $toolbar->addSeparator();
179
180 if ($details) {
181 $pv = $this->service->gui()->print()->resultsDetails($survey->getRefId());
182 $this->service->gui()->ctrl()->setParameterByClass(
183 "ilSurveyEvaluationGUI",
184 "vw",
185 $this->service->gui()->evaluation($survey)->request()->getVW()
186 );
187 $this->service->gui()->ctrl()->setParameterByClass(
188 "ilSurveyEvaluationGUI",
189 "cp",
190 $this->service->gui()->evaluation($survey)->request()->getCP()
191 );
192 $modal_elements = $pv->getModalElements(
193 $this->service->gui()->ctrl()->getLinkTargetByClass(
194 "ilSurveyEvaluationGUI",
195 "printResultsDetailsSelection"
196 )
197 );
198 } else {
199 $pv = $this->service->gui()->print()->resultsOverview($survey->getRefId());
200 $modal_elements = $pv->getModalElements(
201 $this->service->gui()->ctrl()->getLinkTargetByClass(
202 "ilSurveyEvaluationGUI",
203 "printResultsOverviewSelection"
204 )
205 );
206 }
207
208 $toolbar->addComponent($modal_elements->button);
209 $toolbar->addComponent($modal_elements->modal);
210
211 /*
212 $button = \ilLinkButton::getInstance();
213 $button->setCaption("print");
214 $button->setOnClick("if(il.Accordion) { il.Accordion.preparePrint(); } window.print(); return false;");
215 $button->setOmitPreventDoubleSubmission(true);
216 $toolbar->addButtonInstance($button);*/
217 }
218
219 protected function buildExportButtonAndModal(
220 \ilTemplate $eval_tpl,
221 string $export_cmd
222 ): void {
223 $lng = $this->gui->lng();
224 $ctrl = $this->gui->ctrl();
225 $toolbar = $this->gui->toolbar();
226 $ui_fac = $this->gui->ui()->factory();
227 $ui_ren = $this->gui->ui()->renderer();
228 $ui_request = $this->gui->http()->request();
229
230 $ctrl->setParameterByClass("ilsurveyevaluationgui", "export_cmd", $export_cmd);
231 $modal = $this->getExportModal();
232 $button = $ui_fac->button()->standard(
233 $lng->txt("export"),
234 "#"
235 )->withOnClick($modal->getShowSignal());
236
237 $toolbar->addComponent($button);
238 if ("POST" === $ui_request->getMethod()
239 && isset($ui_request->getQueryParams()["fallbackCmd"])
240 && $ui_request->getQueryParams()["fallbackCmd"] === "validateAndSubmitExportForm") {
241 $modal = $modal->withRequest($ui_request);
242 $eval_tpl->setVariable("MODAL", $ui_ren->render($modal->withOnLoad($modal->getShowSignal())));
243 } else {
244 $eval_tpl->setVariable("MODAL", $ui_ren->render($modal));
245 }
246 }
247
249 {
250 $lng = $this->gui->lng();
251 $ctrl = $this->gui->ctrl();
252 $ui_fac = $this->gui->ui()->factory();
253
254 $post_url = $ctrl->getFormActionByClass("ilsurveyevaluationgui", "validateAndSubmitExportForm");
255
256 $inputs["export_format"] = $ui_fac->input()->field()->select(
257 $lng->txt("filetype"),
258 [
259 \ilSurveyEvaluationGUI::TYPE_XLS => $lng->txt("exp_type_excel"),
260 \ilSurveyEvaluationGUI::TYPE_SPSS => $lng->txt("exp_type_csv")
261 ]
262 )
263 //->withValue(\ilSurveyEvaluationGUI::TYPE_XLS)
264 ->withRequired(true);
265
266 $inputs["export_label"] = $ui_fac->input()->field()->select(
267 $lng->txt("title"),
268 [
269 "label_only" => $lng->txt("export_label_only"),
270 "title_only" => $lng->txt("export_title_only"),
271 "title_label" => $lng->txt("export_title_label")
272 ]
273 )
274 //->withValue("label_only")
275 ->withRequired(true);
276
277 $modal = $ui_fac->modal()->roundtrip(
278 $lng->txt("svy_export_format"),
279 null,
280 $inputs,
281 $post_url
282 )
283 ->withSubmitLabel($lng->txt("export"));
284
285 return $modal;
286 }
287
289 \ilObjSurvey $survey,
290 \ilToolbarGUI $toolbar,
291 int $user_id
292 ): void {
293 $lng = $this->service->gui()->lng();
294 $ctrl = $this->service->gui()->ctrl();
295 $req = $this->service->gui()->evaluation($survey)->request();
296
297 $evaluation_manager = $this->service->domain()->evaluation(
298 $survey,
299 $user_id,
300 $req->getAppraiseeId(),
301 $req->getRaterId()
302 );
303
304 if ($evaluation_manager->isMultiParticipantsView()) {
305 $appr_id = $evaluation_manager->getCurrentAppraisee();
306 $options = array();
307 if (!$appr_id) {
308 $options[""] = $lng->txt("please_select");
309 }
310
311 foreach ($evaluation_manager->getSelectableAppraisees() as $appraisee_usr_id) {
312 $options[$appraisee_usr_id] = \ilUserUtil::getNamePresentation(
313 $appraisee_usr_id,
314 false,
315 false,
316 "",
317 true
318 );
319 }
320
321 $appr = new \ilSelectInputGUI($lng->txt("survey_360_appraisee"), "appr_id");
322 $appr->setOptions($options);
323 $appr->setValue($appr_id);
324 $toolbar->addInputItem($appr, true);
325
326 $this->gui->button(
327 $lng->txt("survey_360_select_appraisee"),
328 $ctrl->getCmd()
329 )->submit()->toToolbar(false, $toolbar);
330
331 if ($appr_id) {
332 $toolbar->addSeparator();
333 }
334 }
335 }
336
337
338 public function getDetailPanels(
339 array $participants,
340 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
342 ): array {
343 $a_results = $a_eval->getResults();
344 $panels = [];
345 $ui_factory = $this->service->gui()->ui()->factory();
346
347 $a_tpl = new \ilTemplate("tpl.svy_results_details_panel.html", true, true, "components/ILIAS/Survey/Evaluation");
348
349 $question_res = $a_results;
350 $matrix = false;
351 if (is_array($question_res)) {
352 $question_res = $question_res[0][1];
353 $matrix = true;
354 }
355
356 // see #28507 (matrix question without a row)
357 if (!is_object($question_res)) {
358 return [];
359 }
360
361 $question = $question_res->getQuestion();
362
363 // question "overview"
364 $qst_title = $question->getTitle();
365 $svy_text = nl2br($question->getQuestiontext());
366
367 // Question title anchor
368 $anchor_id = "svyrdq" . $question->getId();
369 $title = "<span id='$anchor_id'>$qst_title</span>";
370 $panel_qst_card = $ui_factory->panel()->sub($title, $ui_factory->legacy()->content($svy_text))
371 ->withFurtherInformation($this->getPanelCard($question_res));
372
373 $panels[] = $panel_qst_card;
374
375 $a_tpl->setVariable("TABLE", $this->getPanelTable(
376 $participants,
377 $request,
378 $a_eval
379 ));
380
381 $a_tpl->setVariable("TEXT", $this->getPanelText(
382 $request,
383 $a_eval,
384 $question_res
385 ));
386
387 $a_tpl->setVariable("CHART", $this->getPanelChart(
388 $request,
389 $a_eval
390 ));
391
392
393 $panels[] = $ui_factory->panel()->sub("", $ui_factory->legacy()->content($a_tpl->get()));
394 return $panels;
395 }
396
397 protected function getPanelTable(
398 array $participants,
399 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
401 ): string {
402 $a_results = $a_eval->getResults();
403
404 $a_tpl = new \ilTemplate("tpl.svy_results_details_table.html", true, true, "components/ILIAS/Survey/Evaluation");
405
406 // grid
407 if ($request->getShowTable()) {
408 $grid = $a_eval->getGrid(
409 $a_results,
410 $request->getShowAbsolute(),
411 $request->getShowPercentage()
412 );
413 if ($grid) {
414 foreach ($grid["cols"] as $col) {
415 $a_tpl->setCurrentBlock("grid_col_header_bl");
416 $a_tpl->setVariable("COL_HEADER", $col);
417 $a_tpl->parseCurrentBlock();
418 }
419 foreach ($grid["rows"] as $cols) {
420 foreach ($cols as $idx => $col) {
421 if ($idx > 0) {
422 $a_tpl->touchBlock("grid_col_nowrap_bl");
423 }
424
425 $a_tpl->setCurrentBlock("grid_col_bl");
426 $a_tpl->setVariable("COL_CAPTION", trim((string) ($col ?? "")));
427 $a_tpl->parseCurrentBlock();
428 }
429
430 $a_tpl->touchBlock("grid_row_bl");
431 }
432 }
433 }
434 return $a_tpl->get();
435 }
436
437 protected function getPanelChart(
438 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
440 ): string {
441 $a_results = $a_eval->getResults();
442
443 $a_tpl = new \ilTemplate("tpl.svy_results_details_chart.html", true, true, "components/ILIAS/Survey/Evaluation");
444 // chart
445 if ($request->getShowChart()) {
446 $chart = $a_eval->getChart($a_results);
447 if ($chart) {
448 if (is_array($chart)) {
449 // legend
450 if (is_array($chart[1])) {
451 foreach ($chart[1] as $legend_item) {
452 $r = hexdec(substr($legend_item[1], 1, 2));
453 $g = hexdec(substr($legend_item[1], 3, 2));
454 $b = hexdec(substr($legend_item[1], 5, 2));
455
456 $a_tpl->setCurrentBlock("legend_bl");
457 $a_tpl->setVariable("LEGEND_CAPTION", $legend_item[0]);
458 $a_tpl->setVariable("LEGEND_COLOR", $legend_item[1]);
459 $a_tpl->setVariable("LEGEND_COLOR_SVG", $r . "," . $g . "," . $b);
460 $a_tpl->parseCurrentBlock();
461 }
462 }
463
464 $chart = $chart[0];
465 }
466
467 $a_tpl->setVariable("CHART", $chart);
468 }
469 }
470
471 return $a_tpl->get();
472 }
473
474 protected function getPanelText(
475 \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request,
477 \ilSurveyEvaluationResults $question_res
478 ): string {
479 $a_results = $a_eval->getResults();
480 $question = $question_res->getQuestion();
481 $lng = $this->service->gui()->lng();
482
483 $a_tpl = new \ilTemplate("tpl.svy_results_details_text.html", true, true, "components/ILIAS/Survey/Evaluation");
484
485 // text answers
486 $texts = $a_eval->getTextAnswers($a_results);
487 if ($texts) {
488 if (array_key_exists("", $texts)) {
489 $a_tpl->setVariable("TEXT_HEADING", $lng->txt("given_answers"));
490 foreach ($texts[""] as $item) {
491 $a_tpl->setCurrentBlock("text_direct_item_bl");
492 $a_tpl->setVariable("TEXT_DIRECT", nl2br(htmlentities($item)));
493 $a_tpl->parseCurrentBlock();
494 }
495 } else {
496 $acc = new \ilAccordionGUI();
497 $acc->setId("svyevaltxt" . $question->getId());
498
499 $a_tpl->setVariable("TEXT_HEADING", $lng->txt("freetext_answers"));
500
501 foreach ($texts as $var => $items) {
502 $list = array("<ul class=\"small\">");
503 foreach ($items as $item) {
504 $list[] = "<li>" . nl2br(htmlentities($item)) . "</li>";
505 }
506 $list[] = "</ul>";
507 $acc->addItem((string) $var, implode("\n", $list));
508 }
509
510 $a_tpl->setVariable("TEXT_ACC", $acc->getHTML());
511 }
512 }
513 return $a_tpl->get();
514 }
515
516 // in fact we want a \ILIAS\UI\Component\Card\Standard
517 // see #31743
518 protected function getPanelCard(
519 \ilSurveyEvaluationResults $question_res
521 $ui_factory = $this->service->gui()->ui()->factory();
522 $lng = $this->service->gui()->lng();
523
524 $question = $question_res->getQuestion();
525 $kv = array();
526 $kv["users_answered"] = $question_res->getUsersAnswered();
527 $kv["users_skipped"] = $question_res->getUsersSkipped();
528
529 $card_table_tpl = new \ilTemplate(
530 "tpl.svy_results_details_card.html",
531 true,
532 true,
533 "components/ILIAS/Survey/Evaluation"
534 );
535
536 if (true) { // formerly check for matrix type, shouldnt be needed
537 if ($question_res->getModeValue() !== null) {
538 $kv["mode"] = wordwrap($question_res->getModeValueAsText(), 50, "<br />");
539 $kv["mode_nr_of_selections"] = $question_res->getModeNrOfSelections();
540 }
541 if ($question_res->getMedian() !== null) {
542 $kv["median"] = $question_res->getMedianAsText();
543 }
544 if ($question_res->getMean() !== null) {
545 $kv["arithmetic_mean"] = $question_res->getMean();
546 }
547 }
548
549 foreach ($kv as $key => $value) {
550 $card_table_tpl->setCurrentBlock("question_statistics_card");
551 $card_table_tpl->setVariable("QUESTION_STATISTIC_KEY", $lng->txt($key));
552 $card_table_tpl->setVariable("QUESTION_STATISTIC_VALUE", $value);
553 $card_table_tpl->parseCurrentBlock();
554 }
555
556 $svy_type_title = \SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
557
558 return $ui_factory->card()
559 ->standard($svy_type_title)
560 ->withSections(
561 array($ui_factory->legacy()->content($card_table_tpl->get()))
562 );
563 }
564}
factory()
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
setInternalService(InternalService $internal_service)
getPanelChart(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
addApprSelectionToToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
setValuesFromForm(\ilObjSurvey $survey, \ilPropertyFormGUI $form)
getPanelTable(array $participants, \ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval)
getSurveySettingsResults(\ilObjSurvey $survey, InternalGUIService $ui_service)
setResultsCompetenceToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id)
buildExportButtonAndModal(\ilTemplate $eval_tpl, string $export_cmd)
getPanelCard(\ilSurveyEvaluationResults $question_res)
addExportAndPrintButton(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, bool $details, \ilTemplate $eval_tpl)
setResultsDetailToolbar(\ilObjSurvey $survey, \ilToolbarGUI $toolbar, int $user_id, \ilTemplate $eval_tpl)
getPanelText(\ILIAS\Survey\Evaluation\EvaluationGUIRequest $request, \SurveyQuestionEvaluation $a_eval, \ilSurveyEvaluationResults $question_res)
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)
addComponent(\ILIAS\UI\Component\Component $a_comp)
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:33
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:91
global $lng
Definition: privfeed.php:31