ILIAS  release_8 Revision v8.24
ilObjTestSettingsResultDetails.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as Refinery;
24
26{
36
38
39 protected bool $print_bs_with_res = true;
40 protected bool $examid_in_test_res = true;
41 protected int $exportsettings = 0;
42 protected int $results_presentation = 0;
43 protected array $taxonomy_filter_ids = [];
44
45
46 public function __construct(int $test_id)
47 {
49 }
50
51 public function toForm(
53 FieldFactory $f,
54 Refinery $refinery,
55 array $environment = null
56 ): FormInput {
57 $bool_with_optional_addition = $refinery->custom()->transformation(
58 function ($v) {
59 if (!$v) {
60 return [false, false]; //[enabled, show_best_solution]
61 }
62 return [true, array_shift($v)];
63 }
64 );
65
66 $optgroup_lists = $f->optionalGroup(
67 [
68 $f->checkbox(
69 $lng->txt('tst_results_print_best_solution'),
70 $lng->txt('tst_results_print_best_solution_info')
71 )->withValue($this->getShowSolutionListComparison())
72 ],
73 $lng->txt('tst_show_solution_details'),
74 $lng->txt('tst_show_solution_details_desc')
75 )->withAdditionalTransformation($bool_with_optional_addition);
76
77 if (!$this->getShowSolutionListOwnAnswers()) {
78 $optgroup_lists = $optgroup_lists->withValue(null);
79 }
80
81 $optgroup_singlepage = $f->optionalGroup(
82 [
83 $f->checkbox(
84 $lng->txt('tst_results_print_best_solution_singlepage'),
85 $lng->txt('tst_results_print_best_solution_singlepage_info')
86 )->withValue($this->getPrintBestSolutionWithResult())
87 ],
88 $lng->txt('tst_show_solution_details_singlepage'),
89 $lng->txt('tst_show_solution_details_singlepage_desc')
90 )->withAdditionalTransformation($bool_with_optional_addition);
91 if (!$this->getShowSolutionDetails()) {
92 $optgroup_singlepage = $optgroup_singlepage->withValue(null);
93 }
94
95
96 $taxonomy_options = $environment['taxonomy_options'];
97 $taxonomy_ids = $f->multiselect(
98 $lng->txt('tst_results_tax_filters'),
99 $taxonomy_options,
100 ''
101 );
102
103 $fields = [
104 'solution_details' => $optgroup_lists,
105 'solution_details_singlepage' => $optgroup_singlepage,
106
107 'solution_feedback' => $f->checkbox(
108 $lng->txt('tst_show_solution_feedback'),
109 $lng->txt('tst_show_solution_feedback_desc')
111 'solution_suggested' => $f->checkbox(
112 $lng->txt('tst_show_solution_suggested'),
113 $lng->txt('tst_show_solution_suggested_desc')
115 'solution_printview' => $f->checkbox(
116 $lng->txt('tst_show_solution_printview'),
117 $lng->txt('tst_show_solution_printview_desc')
119 'solution_hide_page' => $f->checkbox(
120 $lng->txt('tst_hide_pagecontents'),
121 $lng->txt('tst_hide_pagecontents_desc')
123
124 'solution_signature' => $f->checkbox(
125 $lng->txt('tst_show_solution_signature'),
126 $lng->txt('tst_show_solution_signature_desc')
127 )
129 //TODO ?->withDisabled($anonymity)
130 ,
131 'examid_in_test_res' => $f->checkbox(
132 $lng->txt('examid_in_test_res'),
133 $lng->txt('examid_in_test_res_desc')
135 'exp_sc_short' => $f->checkbox(
136 $lng->txt('tst_exp_sc_short'),
137 $lng->txt('tst_exp_sc_short_desc')
139 'result_tax_filters' => $taxonomy_ids
141 ];
142
143 return $f->section($fields, $lng->txt('tst_results_details_options'))
145 $refinery->custom()->transformation(
146 function ($v) {
147 list($solution_list_details, $solution_list_best_solution) = $v['solution_details'];
148 list($solution_sp_details, $solution_sp_best_solution) = $v['solution_details_singlepage'];
149 return (clone $this)
150 ->withShowSolutionListOwnAnswers($solution_list_details)
151 ->withShowSolutionListComparison($solution_list_best_solution)
152 ->withShowSolutionDetails($solution_sp_details)
153 ->withPrintBestSolutionWithResult($solution_sp_best_solution)
154 ->withShowSolutionFeedback($v['solution_feedback'])
155 ->withShowSolutionSuggested($v['solution_suggested'])
156 ->withShowSolutionPrintview($v['solution_printview'])
157 ->withShowSolutionAnswersOnly($v['solution_hide_page'])
158 ->withShowSolutionSignature($v['solution_signature'])
159 ->withShowExamIdInTestResults($v["examid_in_test_res"])
160 ->withExportSettingsSingleChoiceShort($v["exp_sc_short"])
161 ->withTaxonomyFilterIds($v["result_tax_filters"] ?? []);
162 }
163 )
164 );
165 }
166
167 public function toStorage(): array
168 {
169 return [
170 'print_bs_with_res' => ['integer', (int) $this->getPrintBestSolutionWithResult()],
171 'results_presentation' => ['integer', $this->getResultsPresentation()],
172 'examid_in_test_res' => ['integer', (int) $this->getShowExamIdInTestResults()],
173 'exportsettings' => ['integer', (int) $this->getExportSettings()],
174 'results_presentation' => ['integer', (int) $this->getResultsPresentation()],
175 'result_tax_filters' => ['string', serialize($this->getTaxonomyFilterIds())]
176 ];
177 }
178
179
180 public function getPrintBestSolutionWithResult(): bool
181 {
182 return $this->print_bs_with_res;
183 }
184 public function withPrintBestSolutionWithResult(bool $print_bs_with_res): self
185 {
186 $clone = clone $this;
187 $clone->print_bs_with_res = $print_bs_with_res;
188 return $clone;
189 }
190
191 public function getResultsPresentation(): int
192 {
193 return $this->results_presentation;
194 }
195 public function withResultsPresentation(int $results_presentation): self
196 {
197 $clone = clone $this;
198 $clone->results_presentation = $results_presentation;
199 return $clone;
200 }
201
202 public function getShowExamIdInTestResults(): bool
203 {
204 return $this->examid_in_test_res;
205 }
206 public function withShowExamIdInTestResults(bool $examid_in_test_res): self
207 {
208 $clone = clone $this;
209 $clone->examid_in_test_res = $examid_in_test_res;
210 return $clone;
211 }
212
213 protected function compareResultPresentation(int $bit): bool
214 {
215 return ($this->results_presentation & $bit) > 0;
216 }
217 protected function modifyResultPresentation(int $bit, bool $flag): self
218 {
219 $clone = clone $this;
220 $v = $clone->results_presentation;
221
222 if ($flag) {
223 $v = $v | $bit;
224 } else {
225 if ($this->compareResultPresentation($bit)) {
226 $v = $v ^ $bit;
227 }
228 }
229 $clone->results_presentation = $v;
230 return $clone;
231 }
232
233 public function getShowPassDetails(): bool
234 {
235 return $this->compareResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS);
236 }
237 public function withShowPassDetails(bool $flag): self
238 {
239 return $this->modifyResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS, $flag);
240 }
241
242 public function getShowSolutionDetails(): bool
243 {
244 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_DETAILS);
245 }
246 public function withShowSolutionDetails(bool $flag): self
247 {
248 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_DETAILS, $flag);
249 }
250
251 public function getShowSolutionPrintview(): bool
252 {
253 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW);
254 }
255 public function withShowSolutionPrintview(bool $flag): self
256 {
257 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW, $flag);
258 }
259
260 public function getShowSolutionFeedback(): bool
261 {
262 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK);
263 }
264 public function withShowSolutionFeedback(bool $flag): self
265 {
266 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK, $flag);
267 }
268
269 public function getShowSolutionAnswersOnly(): bool
270 {
271 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY);
272 }
273 public function withShowSolutionAnswersOnly(bool $flag): self
274 {
275 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY, $flag);
276 }
277
278 public function getShowSolutionSignature(): bool
279 {
280 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE);
281 }
282 public function withShowSolutionSignature(bool $flag): self
283 {
284 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE, $flag);
285 }
286
287 public function getShowSolutionSuggested(): bool
288 {
289 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED);
290 }
291 public function withShowSolutionSuggested(bool $flag): self
292 {
293 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED, $flag);
294 }
295
296 public function getShowSolutionListComparison(): bool
297 {
298 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE);
299 }
300 public function withShowSolutionListComparison(bool $flag): self
301 {
302 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE, $flag);
303 }
304
305 public function getShowSolutionListOwnAnswers(): bool
306 {
307 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTOWNANSWERS);
308 }
309 public function withShowSolutionListOwnAnswers(bool $flag): self
310 {
311 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTOWNANSWERS, $flag);
312 }
313
314 public function getExportSettings(): int
315 {
316 return $this->exportsettings;
317 }
318 public function withExportSettings(int $exportsettings): self
319 {
320 $clone = clone $this;
321 $clone->exportsettings = $exportsettings;
322 return $clone;
323 }
324 protected function compareExportSetting(int $bit): bool
325 {
326 return ($this->exportsettings & $bit) > 0;
327 }
328 protected function modifyExportSetting(int $bit, bool $flag): self
329 {
330 $clone = clone $this;
331 $v = $clone->exportsettings;
332
333 if ($flag) {
334 $v = $v | $bit;
335 } else {
336 if ($this->compareExportSetting($bit)) {
337 $v = $v ^ $bit;
338 }
339 }
340 $clone->exportsettings = $v;
341 return $clone;
342 }
344 {
345 return $this->compareExportSetting(self::EXPORT_BIT_SINGLECHOICE_SHORT);
346 }
347 public function withExportSettingsSingleChoiceShort(bool $flag): self
348 {
349 return $this->modifyExportSetting(self::EXPORT_BIT_SINGLECHOICE_SHORT, $flag);
350 }
351
352 public function getTaxonomyFilterIds(): array
353 {
354 return $this->taxonomy_filter_ids;
355 }
356 public function withTaxonomyFilterIds(array $taxonomy_filter_ids): self
357 {
358 $clone = clone $this;
359 $clone->taxonomy_filter_ids = $taxonomy_filter_ids;
360 return $clone;
361 }
362}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
language handling
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
withTaxonomyFilterIds(array $taxonomy_filter_ids)
withPrintBestSolutionWithResult(bool $print_bs_with_res)
withResultsPresentation(int $results_presentation)
withShowExamIdInTestResults(bool $examid_in_test_res)
This describes inputs that can be used in forms.
Definition: FormInput.php:32
This is what a factory for input fields looks like.
Definition: Factory.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
$lng