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