ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
SettingsResultDetails.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\Refinery\Factory as Refinery;
29
31{
41
42 protected bool $examid_in_test_res = true;
43 protected int $exportsettings = 0;
44 protected int $results_presentation = 0;
45
46 public function toForm(
48 FieldFactory $f,
50 ?array $environment = null
51 ): FormInput {
52 $fields = [
53 'solution_best_solution' =>
54 $f->checkbox(
55 $lng->txt('tst_results_print_best_solution'),
56 $lng->txt('tst_results_print_best_solution_info')
58 'solution_feedback' => $f->checkbox(
59 $lng->txt('tst_show_solution_feedback'),
60 $lng->txt('tst_show_solution_feedback_desc')
62 'solution_suggested' => $f->checkbox(
63 $lng->txt('tst_show_solution_suggested'),
64 $lng->txt('tst_show_solution_suggested_desc')
66 'solution_printview' => $f->checkbox(
67 $lng->txt('tst_show_solution_printview'),
68 $lng->txt('tst_show_solution_printview_desc')
70 'solution_hide_page' => $f->checkbox(
71 $lng->txt('tst_hide_pagecontents'),
72 $lng->txt('tst_hide_pagecontents_desc')
74
75 'solution_signature' => $f->checkbox(
76 $lng->txt('tst_show_solution_signature'),
77 $lng->txt('tst_show_solution_signature_desc')
78 )
80 //TODO ?->withDisabled($anonymity)
81 ,
82 'examid_in_test_res' => $f->checkbox(
83 $lng->txt('examid_in_test_res'),
84 $lng->txt('examid_in_test_res_desc')
86 ];
87
88 return $f->section($fields, $lng->txt('tst_results_details_options'))
89 ->withAdditionalTransformation(
90 $refinery->custom()->transformation(
91 function ($v) {
92 return (clone $this)
93 ->withShowSolutionListComparison($v['solution_best_solution'])
94 ->withShowSolutionFeedback($v['solution_feedback'])
95 ->withShowSolutionSuggested($v['solution_suggested'])
96 ->withShowSolutionPrintview($v['solution_printview'])
97 ->withShowSolutionAnswersOnly($v['solution_hide_page'])
98 ->withShowSolutionSignature($v['solution_signature'])
99 ->withShowExamIdInTestResults($v["examid_in_test_res"]);
100 }
101 )
102 );
103 }
104
105 public function toStorage(): array
106 {
107 return [
108 'results_presentation' => ['integer', $this->getResultsPresentation()],
109 'examid_in_test_res' => ['integer', (int) $this->getShowExamIdInTestResults()],
110 'exportsettings' => ['integer', $this->getExportSettings()]
111 ];
112 }
113
114 public function toLog(AdditionalInformationGenerator $additional_info): array
115 {
116 return [
118 ->getEnabledDisabledTagForBool($this->getShowSolutionListComparison()),
120 ->getEnabledDisabledTagForBool($this->getShowSolutionFeedback()),
122 ->getEnabledDisabledTagForBool($this->getShowSolutionSuggested()),
124 ->getEnabledDisabledTagForBool($this->getShowSolutionPrintview()),
126 ->getEnabledDisabledTagForBool($this->getShowSolutionAnswersOnly()),
128 ->getEnabledDisabledTagForBool($this->getShowSolutionSignature()),
130 ->getEnabledDisabledTagForBool($this->getShowExamIdInTestResults())
131 ];
132 }
133
134 public function getResultsPresentation(): int
135 {
136 return $this->results_presentation;
137 }
138 public function withResultsPresentation(int $results_presentation): self
139 {
140 $clone = clone $this;
141 $clone->results_presentation = $results_presentation;
142 return $clone;
143 }
144
145 public function getShowExamIdInTestResults(): bool
146 {
147 return $this->examid_in_test_res;
148 }
149 public function withShowExamIdInTestResults(bool $examid_in_test_res): self
150 {
151 $clone = clone $this;
152 $clone->examid_in_test_res = $examid_in_test_res;
153 return $clone;
154 }
155
156 protected function compareResultPresentation(int $bit): bool
157 {
158 return ($this->results_presentation & $bit) > 0;
159 }
160 protected function modifyResultPresentation(int $bit, bool $flag): self
161 {
162 $clone = clone $this;
163 $v = $clone->results_presentation;
164
165 if ($flag) {
166 $v = $v | $bit;
167 } else {
168 if ($this->compareResultPresentation($bit)) {
169 $v = $v ^ $bit;
170 }
171 }
172 $clone->results_presentation = $v;
173 return $clone;
174 }
175
176 public function getShowPassDetails(): bool
177 {
178 return $this->compareResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS);
179 }
180 public function withShowPassDetails(bool $flag): self
181 {
182 return $this->modifyResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS, $flag);
183 }
184
185 public function getShowSolutionPrintview(): bool
186 {
187 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW);
188 }
189 public function withShowSolutionPrintview(bool $flag): self
190 {
191 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW, $flag);
192 }
193
194 public function getShowSolutionFeedback(): bool
195 {
196 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK);
197 }
198 public function withShowSolutionFeedback(bool $flag): self
199 {
200 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK, $flag);
201 }
202
203 public function getShowSolutionAnswersOnly(): bool
204 {
205 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY);
206 }
207 public function withShowSolutionAnswersOnly(bool $flag): self
208 {
209 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY, $flag);
210 }
211
212 public function getShowSolutionSignature(): bool
213 {
214 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE);
215 }
216 public function withShowSolutionSignature(bool $flag): self
217 {
218 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE, $flag);
219 }
220
221 public function getShowSolutionSuggested(): bool
222 {
223 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED);
224 }
225 public function withShowSolutionSuggested(bool $flag): self
226 {
227 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED, $flag);
228 }
229
230 public function getShowSolutionListComparison(): bool
231 {
232 return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE);
233 }
234 public function withShowSolutionListComparison(bool $flag): self
235 {
236 return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE, $flag);
237 }
238
239 public function getExportSettings(): int
240 {
241 return $this->exportsettings;
242 }
243 public function withExportSettings(int $exportsettings): self
244 {
245 $clone = clone $this;
246 $clone->exportsettings = $exportsettings;
247 return $clone;
248 }
249 protected function compareExportSetting(int $bit): bool
250 {
251 return ($this->exportsettings & $bit) > 0;
252 }
253 protected function modifyExportSetting(int $bit, bool $flag): self
254 {
255 $clone = clone $this;
256 $v = $clone->exportsettings;
257
258 if ($flag) {
259 $v = $v | $bit;
260 } else {
261 if ($this->compareExportSetting($bit)) {
262 $v = $v ^ $bit;
263 }
264 }
265 $clone->exportsettings = $v;
266 return $clone;
267 }
268
269 public function toExport(): array
270 {
271 return [
272 'results_presentation' => $this->getResultsPresentation(),
273 'examid_in_test_res' => $this->getShowExamIdInTestResults(),
274 'exportsettings' => $this->getExportSettings()
275 ];
276 }
277
278 public static function fromExport(array $data): static
279 {
280 return (new self())
281 ->withResultsPresentation((int) $data['results_presentation'])
282 ->withShowExamIdInTestResults((bool) $data['examid_in_test_res'])
283 ->withExportSettings((int) $data['exportsettings']);
284 }
285}
Builds data types.
Definition: Factory.php:36
toLog(AdditionalInformationGenerator $additional_info)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
static fromExport(array $data)
Creates an instance of the object from an array.
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
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