ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SettingsGeneral.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
28use ILIAS\Refinery\Factory as Refinery;
29
31{
32 public function __construct(
33 int $test_id,
34 protected string $question_set_type = \ilObjTest::QUESTION_SET_TYPE_FIXED,
35 protected bool $anonymous_test = false
36 ) {
38 }
39
44 public function toForm(
46 FieldFactory $f,
48 ?array $environment = null
49 ): FormInput | array {
50 $inputs['question_set_type'] = $f->radio(
51 $lng->txt('test_question_set_type')
52 )->withOption(
53 \ilObjTest::QUESTION_SET_TYPE_FIXED,
54 $lng->txt('test_question_set_type_fixed'),
55 $lng->txt('test_question_set_type_fixed_info')
56 )->withOption(
57 \ilObjTest::QUESTION_SET_TYPE_RANDOM,
58 $lng->txt('test_question_set_type_random'),
59 $lng->txt('test_question_set_type_random_info')
60 )->withValue($this->getQuestionSetType());
61
62 $trafo = $refinery->custom()->transformation(
63 static function (string $v): bool {
64 if ($v === '1') {
65 return true;
66 }
67
68 return false;
69 }
70 );
71
72 $inputs['anonymity'] = $f->radio(
73 $lng->txt('tst_anonymity')
74 )->withOption(
75 '0',
76 $lng->txt('tst_anonymity_no_anonymization')
77 )->withOption(
78 '1',
79 $lng->txt('tst_anonymity_anonymous_test')
80 )->withValue($this->getAnonymity() ? '1' : '0')
81 ->withAdditionalTransformation($trafo);
82
83 if ($environment['participant_data_exists']) {
84 $inputs['question_set_type'] = $inputs['question_set_type']->withDisabled(true);
85 $inputs['anonymity'] = $inputs['anonymity']->withDisabled(true);
86 }
87
88 return $inputs;
89 }
90
91 public function toStorage(): array
92 {
93 return [
94 'question_set_type' => ['text', $this->getQuestionSetType()],
95 'anonymity' => ['integer', (int) $this->getAnonymity()]
96 ];
97 }
98
99 public function toLog(AdditionalInformationGenerator $additional_info): array
100 {
101 switch ($this->getQuestionSetType()) {
102 case \ilObjTest::QUESTION_SET_TYPE_FIXED:
104 ->getTagForLangVar('test_question_set_type_fixed');
105 break;
106 case \ilObjTest::QUESTION_SET_TYPE_RANDOM:
108 ->getTagForLangVar('test_question_set_type_random') ;
109 break;
110 }
111
112 $log_array[AdditionalInformationGenerator::KEY_TEST_ANONYMITY] = $additional_info
113 ->getEnabledDisabledTagForBool($this->getAnonymity());
114 return $log_array;
115 }
116
117 public function getQuestionSetType(): string
118 {
119 return $this->question_set_type;
120 }
121
122 public function withQuestionSetType(string $question_set_type): self
123 {
124 $clone = clone $this;
125 $clone->question_set_type = $question_set_type;
126 return $clone;
127 }
128
129 public function getAnonymity(): bool
130 {
131 return $this->anonymous_test;
132 }
133
134 public function withAnonymity(bool $anonymous_test): self
135 {
136 $clone = clone $this;
137 $clone->anonymous_test = $anonymous_test;
138 return $clone;
139 }
140}
Builds data types.
Definition: Factory.php:36
__construct(int $test_id, protected string $question_set_type=\ilObjTest::QUESTION_SET_TYPE_FIXED, protected bool $anonymous_test=false)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
toLog(AdditionalInformationGenerator $additional_info)
language handling
const QUESTION_SET_TYPE_FIXED
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31