ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
SettingsParticipantFunctionality.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Refinery\Factory as Refinery;
30
32{
33 public function __construct(
34 protected bool $use_previous_answers_allowed = false,
35 protected bool $suspend_test_allowed = false,
36 protected bool $postponed_questions_move_to_end = false,
37 protected int $usrpass_overview_mode = 0,
38 protected bool $question_marking_enabled = false,
39 protected bool $question_list_enabled = false
40 ) {
42 }
43
44 public function toForm(
46 FieldFactory $f,
48 ?array $environment = null
49 ): FormInput {
50 $inputs['use_previous_answers'] = $f->checkbox(
51 $lng->txt('tst_use_previous_answers'),
52 $lng->txt('tst_use_previous_answers_description')
54
55 $inputs['allow_suspend_test'] = $f->checkbox(
56 $lng->txt('tst_show_cancel'),
57 $lng->txt('tst_show_cancel_description')
58 )->withValue($this->getSuspendTestAllowed());
59
60 $inputs['postponed_questions_behaviour'] = $f->radio(
61 $lng->txt('tst_postpone')
62 )->withOption(
63 '0',
64 $lng->txt('tst_postpone_off'),
65 $lng->txt('tst_postpone_off_desc')
66 )->withOption(
67 '1',
68 $lng->txt('tst_postpone_on'),
69 $lng->txt('tst_postpone_on_desc')
70 )->withValue($this->getPostponedQuestionsMoveToEnd() ? '1' : '0')
71 ->withAdditionalTransformation($refinery->kindlyTo()->bool());
72
73 $inputs['enable_question_list'] = $f->checkbox(
74 $lng->txt('tst_enable_questionlist'),
75 $lng->txt('tst_enable_questionlist_description')
76 )->withValue($this->getQuestionListEnabled());
77
78 $inputs['usr_pass_overview'] = $this->getInputUsrPassOverview($lng, $f, $refinery);
79
80 $inputs['enable_question_marking'] = $f->checkbox(
81 $lng->txt('question_marking'),
82 $lng->txt('question_marking_description')
83 )->withValue($this->getQuestionMarkingEnabled());
84
85 return $f->section($inputs, $lng->txt('tst_sequence_properties'));
86 }
87
88 private function getInputUsrPassOverview(
90 FieldFactory $f,
92 ): OptionalGroup {
93 $trafo = $refinery->custom()->transformation(
94 static function (?array $vs): int {
95 if ($vs === null) {
96 return 0;
97 }
98
99 $usrpass_overview_mode = 1;
100
101 if ($vs['show_at_beginning'] === true) {
102 $usrpass_overview_mode += 2;
103 }
104
105 if ($vs['show_at_end'] === true) {
106 $usrpass_overview_mode += 4;
107 }
108
109 if ($vs['show_description'] === true) {
110 $usrpass_overview_mode += 8;
111 }
112
113 return $usrpass_overview_mode;
114 }
115 );
116
117 $sub_inputs_usrpass_questionlist['show_at_beginning'] = $f->checkbox($lng->txt('tst_list_of_questions_start'));
118 $sub_inputs_usrpass_questionlist['show_at_end'] = $f->checkbox($lng->txt('tst_list_of_questions_end'));
119 $sub_inputs_usrpass_questionlist['show_description'] = $f->checkbox($lng->txt('tst_list_of_questions_with_description'));
120
121 $enable_usrpass_questionlist = $f->optionalGroup(
122 $sub_inputs_usrpass_questionlist,
123 $lng->txt('tst_show_summary'),
124 $lng->txt('tst_show_summary_description')
125 )->withValue(null)
126 ->withAdditionalTransformation($trafo);
127
128 if ($this->getUsrPassOverviewEnabled() === false) {
129 return $enable_usrpass_questionlist;
130 }
131
132 return $enable_usrpass_questionlist->withValue(
133 [
134 'show_at_beginning' => $this->getShownQuestionListAtBeginning(),
135 'show_at_end' => $this->getShownQuestionListAtEnd(),
136 'show_description' => $this->getShowDescriptionInQuestionList()
137 ]
138 );
139 }
140
141 public function toStorage(): array
142 {
143 return [
144 'use_previous_answers' => ['integer', (int) $this->getUsePreviousAnswerAllowed()],
145 'suspend_test_allowed' => ['integer', (int) $this->getSuspendTestAllowed()],
146 'sequence_settings' => ['integer', (int) $this->getPostponedQuestionsMoveToEnd()],
147 'usr_pass_overview_mode' => ['integer', $this->getUsrPassOverviewMode()],
148 'show_marker' => ['integer', (int) $this->getQuestionMarkingEnabled()],
149 'show_questionlist' => ['integer', $this->getQuestionListEnabled()]
150 ];
151 }
152
153 public function toLog(AdditionalInformationGenerator $additional_info): array
154 {
155 $log_array = [
156 AdditionalInformationGenerator::KEY_TEST_USE_PREVIOUS_ANSWERS_ENABELD => $additional_info
157 ->getEnabledDisabledTagForBool($this->getUsePreviousAnswerAllowed()),
158 AdditionalInformationGenerator::KEY_TEST_SUSPEND_ALLOWED => $additional_info
159 ->getEnabledDisabledTagForBool($this->getSuspendTestAllowed()),
160 AdditionalInformationGenerator::KEY_TEST_POSTPONED_MOVE_TO_END => $additional_info
161 ->getEnabledDisabledTagForBool($this->getPostponedQuestionsMoveToEnd())
162 ];
163
164 $log_array[AdditionalInformationGenerator::KEY_TEST_OVERVIEW_ENABLED] = $additional_info
165 ->getEnabledDisabledTagForBool($this->getUsrPassOverviewEnabled());
166 if ($this->getUsrPassOverviewEnabled()) {
167 $log_array[AdditionalInformationGenerator::KEY_TEST_OVERVIEW_SHOW_START] = $additional_info
168 ->getEnabledDisabledTagForBool($this->getShownQuestionListAtBeginning());
169 $log_array[AdditionalInformationGenerator::KEY_TEST_OVERVIEW_SHOW_END] = $additional_info
170 ->getEnabledDisabledTagForBool($this->getShownQuestionListAtEnd());
171 $log_array[AdditionalInformationGenerator::KEY_TEST_OVERVIEW_SHOW_DESCRIPTION] = $additional_info
172 ->getEnabledDisabledTagForBool($this->getShowDescriptionInQuestionList());
173 }
174
175 $log_array[AdditionalInformationGenerator::KEY_TEST_QUESTION_MARKING_ENABLED] = $additional_info
176 ->getEnabledDisabledTagForBool($this->getQuestionMarkingEnabled());
177 $log_array[AdditionalInformationGenerator::KEY_TEST_QUESTION_LIST_ENABLED] = $additional_info
178 ->getEnabledDisabledTagForBool($this->getQuestionListEnabled());
179 return $log_array;
180 }
181
182 public function getUsePreviousAnswerAllowed(): bool
183 {
184 return $this->use_previous_answers_allowed;
185 }
186 public function withUsePreviousAnswerAllowed(bool $use_previous_answers_allowed): self
187 {
188 $clone = clone $this;
189 $clone->use_previous_answers_allowed = $use_previous_answers_allowed;
190 return $clone;
191 }
192
193 public function getSuspendTestAllowed(): bool
194 {
195 return $this->suspend_test_allowed;
196 }
197 public function withSuspendTestAllowed(bool $suspend_test_allowed): self
198 {
199 $clone = clone $this;
200 $clone->suspend_test_allowed = $suspend_test_allowed;
201 return $clone;
202 }
203
204 public function getPostponedQuestionsMoveToEnd(): bool
205 {
206 return $this->postponed_questions_move_to_end;
207 }
208 public function withPostponedQuestionsMoveToEnd(bool $postponed_questions_move_to_end): self
209 {
210 $clone = clone $this;
211 $clone->postponed_questions_move_to_end = $postponed_questions_move_to_end;
212 return $clone;
213 }
214
215 public function getQuestionListEnabled(): bool
216 {
217 return $this->question_list_enabled;
218 }
219 public function withQuestionListEnabled(bool $question_list_enabled): self
220 {
221 $clone = clone $this;
222 $clone->question_list_enabled = $question_list_enabled;
223 return $clone;
224 }
225
226 public function getUsrPassOverviewMode(): int
227 {
228 return $this->usrpass_overview_mode;
229 }
230
231 public function withUsrPassOverviewMode(int $usrpass_overview_mode): self
232 {
233 $clone = clone $this;
234 $clone->usrpass_overview_mode = $usrpass_overview_mode;
235 return $clone;
236 }
237
238 public function getUsrPassOverviewEnabled(): bool
239 {
240 return ($this->usrpass_overview_mode & 1) > 0;
241 }
242 public function getShownQuestionListAtBeginning(): bool
243 {
244 return ($this->usrpass_overview_mode & 2) > 0;
245 }
246 public function getShownQuestionListAtEnd(): bool
247 {
248 return ($this->usrpass_overview_mode & 4) > 0;
249 }
250
251 public function getShowDescriptionInQuestionList(): bool
252 {
253 return ($this->usrpass_overview_mode & 8) > 0;
254 }
255
256 public function getQuestionMarkingEnabled(): bool
257 {
258 return $this->question_marking_enabled;
259 }
260
261 public function withQuestionMarkingEnabled(bool $question_marking_enabled): self
262 {
263 $clone = clone $this;
264 $clone->question_marking_enabled = $question_marking_enabled;
265 return $clone;
266 }
267
268 public function toExport(): array
269 {
270 return [
271 'use_previous_answers' => $this->getUsePreviousAnswerAllowed(),
272 'suspend_test_allowed' => $this->getSuspendTestAllowed(),
273 'postponed_questions_move_to_end' => $this->getPostponedQuestionsMoveToEnd(),
274 'usr_pass_overview_mode' => $this->getUsrPassOverviewMode(),
275 'question_marking_enabled' => $this->getQuestionMarkingEnabled(),
276 'show_questionlist' => $this->getQuestionListEnabled()
277 ];
278 }
279
280 public static function fromExport(array $data): static
281 {
282 return new self(
283 (bool) $data['use_previous_answers'],
284 (bool) $data['suspend_test_allowed'],
285 (bool) $data['postponed_questions_move_to_end'],
286 (int) $data['usr_pass_overview_mode'],
287 (bool) $data['question_marking_enabled'],
288 (bool) $data['show_questionlist']
289 );
290 }
291}
Builds data types.
Definition: Factory.php:36
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
__construct(protected bool $use_previous_answers_allowed=false, protected bool $suspend_test_allowed=false, protected bool $postponed_questions_move_to_end=false, protected int $usrpass_overview_mode=0, protected bool $question_marking_enabled=false, protected bool $question_list_enabled=false)
static fromExport(array $data)
Creates an instance of the object from an array.
getInputUsrPassOverview(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)
toExport()
Transform the object into a simple, associative array.
language handling
This interface allows an object to define its own transformation into a language-neutral,...
Definition: Exportable.php:40
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
This describes optional group inputs.
__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
if(!file_exists('../ilias.ini.php'))