ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAddAnswerFormBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\Refinery\Factory as RefineryFactory;
23use ILIAS\UI\Component\Modal\RoundTrip as RoundTripModal;
24
26{
27 public function __construct(
28 private readonly UIFactory $ui_factory,
29 private readonly RefineryFactory $refinery,
30 private readonly ilLanguage $language,
31 private readonly ilCtrl $ctrl
32 ) {
33 }
34
35 public function buildAddAnswerModal(string $title, array $data = []): RoundTripModal
36 {
37 return $this->ui_factory->modal()->roundtrip(
38 $title,
39 null,
40 $this->buildInputs($data),
41 $this->ctrl->getFormActionByClass([ilObjTestGUI::class, ilTestCorrectionsGUI::class], 'addAnswer')
42 );
43 }
44
45 protected function buildInputs(array $data): array
46 {
47 $to_int_trafo = $this->refinery->kindlyTo()->int();
48 $fix_points_trafo = $this->refinery->custom()->transformation(
49 function ($v) {
50 $v = str_replace(',', '.', $v);
51
52 if (is_numeric($v)) {
53 return (float) $v;
54 }
55
56 return false;
57 }
58 );
59
60 $inputs = [];
61 $inputs['question_id'] = $this->ui_factory->input()->field()->hidden()
62 ->withAdditionalTransformation($to_int_trafo)
63 ->withValue((string) ($data['question_id'] ?? ''));
64 $inputs['question_index'] = $this->ui_factory->input()->field()->hidden()
65 ->withAdditionalTransformation($to_int_trafo)
66 ->withValue((string) ($data['question_index'] ?? ''));
67 $inputs['answer_value'] = $this->ui_factory->input()->field()->hidden($this->language->txt('answer'))
68 ->withValue(($data['answer'] ?? ''));
69 $inputs['answer'] = $this->ui_factory->input()->field()->text($this->language->txt('answer'))
70 ->withValue(($data['answer'] ?? ''))
71 ->withDisabled(true);
72 $inputs['points'] = $this->ui_factory->input()->field()->text($this->language->txt('points'))
73 ->withAdditionalTransformation($fix_points_trafo);
74 return $inputs;
75 }
76}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
buildAddAnswerModal(string $title, array $data=[])
__construct(private readonly UIFactory $ui_factory, private readonly RefineryFactory $refinery, private readonly ilLanguage $language, private readonly ilCtrl $ctrl)
Class ilCtrl provides processing control methods.
language handling
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61