ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestSettingsResultDetails.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  public const RESULTPRES_BIT_PASS_DETAILS = 1;
36 
37  protected bool $examid_in_test_res = true;
38  protected int $exportsettings = 0;
39  protected int $results_presentation = 0;
40 
41 
42  public function __construct(int $test_id)
43  {
44  parent::__construct($test_id);
45  }
46 
47  public function toForm(
51  array $environment = null
52  ): FormInput {
53  $fields = [
54  'solution_best_solution' =>
55  $f->checkbox(
56  $lng->txt('tst_results_print_best_solution'),
57  $lng->txt('tst_results_print_best_solution_info')
59  'solution_feedback' => $f->checkbox(
60  $lng->txt('tst_show_solution_feedback'),
61  $lng->txt('tst_show_solution_feedback_desc')
63  'solution_suggested' => $f->checkbox(
64  $lng->txt('tst_show_solution_suggested'),
65  $lng->txt('tst_show_solution_suggested_desc')
67  'solution_printview' => $f->checkbox(
68  $lng->txt('tst_show_solution_printview'),
69  $lng->txt('tst_show_solution_printview_desc')
71  'solution_hide_page' => $f->checkbox(
72  $lng->txt('tst_hide_pagecontents'),
73  $lng->txt('tst_hide_pagecontents_desc')
75 
76  'solution_signature' => $f->checkbox(
77  $lng->txt('tst_show_solution_signature'),
78  $lng->txt('tst_show_solution_signature_desc')
79  )
81  //TODO ?->withDisabled($anonymity)
82  ,
83  'examid_in_test_res' => $f->checkbox(
84  $lng->txt('examid_in_test_res'),
85  $lng->txt('examid_in_test_res_desc')
87  ];
88 
89  return $f->section($fields, $lng->txt('tst_results_details_options'))
91  $refinery->custom()->transformation(
92  function ($v) {
93  return (clone $this)
94  ->withShowSolutionListComparison($v['solution_best_solution'])
95  ->withShowSolutionFeedback($v['solution_feedback'])
96  ->withShowSolutionSuggested($v['solution_suggested'])
97  ->withShowSolutionPrintview($v['solution_printview'])
98  ->withShowSolutionAnswersOnly($v['solution_hide_page'])
99  ->withShowSolutionSignature($v['solution_signature'])
100  ->withShowExamIdInTestResults($v["examid_in_test_res"]);
101  }
102  )
103  );
104  }
105 
106  public function toStorage(): array
107  {
108  return [
109  'results_presentation' => ['integer', $this->getResultsPresentation()],
110  'examid_in_test_res' => ['integer', (int) $this->getShowExamIdInTestResults()],
111  'exportsettings' => ['integer', (int) $this->getExportSettings()],
112  'results_presentation' => ['integer', (int) $this->getResultsPresentation()]
113  ];
114  }
115 
116  public function getResultsPresentation(): int
117  {
119  }
120  public function withResultsPresentation(int $results_presentation): self
121  {
122  $clone = clone $this;
123  $clone->results_presentation = $results_presentation;
124  return $clone;
125  }
126 
127  public function getShowExamIdInTestResults(): bool
128  {
130  }
131  public function withShowExamIdInTestResults(bool $examid_in_test_res): self
132  {
133  $clone = clone $this;
134  $clone->examid_in_test_res = $examid_in_test_res;
135  return $clone;
136  }
137 
138  protected function compareResultPresentation(int $bit): bool
139  {
140  return ($this->results_presentation & $bit) > 0;
141  }
142  protected function modifyResultPresentation(int $bit, bool $flag): self
143  {
144  $clone = clone $this;
145  $v = $clone->results_presentation;
146 
147  if ($flag) {
148  $v = $v | $bit;
149  } else {
150  if ($this->compareResultPresentation($bit)) {
151  $v = $v ^ $bit;
152  }
153  }
154  $clone->results_presentation = $v;
155  return $clone;
156  }
157 
158  public function getShowPassDetails(): bool
159  {
160  return $this->compareResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS);
161  }
162  public function withShowPassDetails(bool $flag): self
163  {
164  return $this->modifyResultPresentation(self::RESULTPRES_BIT_PASS_DETAILS, $flag);
165  }
166 
167  public function getShowSolutionPrintview(): bool
168  {
169  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW);
170  }
171  public function withShowSolutionPrintview(bool $flag): self
172  {
173  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_PRINTVIEW, $flag);
174  }
175 
176  public function getShowSolutionFeedback(): bool
177  {
178  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK);
179  }
180  public function withShowSolutionFeedback(bool $flag): self
181  {
182  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_FEEDBACK, $flag);
183  }
184 
185  public function getShowSolutionAnswersOnly(): bool
186  {
187  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY);
188  }
189  public function withShowSolutionAnswersOnly(bool $flag): self
190  {
191  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_ANSWERS_ONLY, $flag);
192  }
193 
194  public function getShowSolutionSignature(): bool
195  {
196  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE);
197  }
198  public function withShowSolutionSignature(bool $flag): self
199  {
200  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SIGNATURE, $flag);
201  }
202 
203  public function getShowSolutionSuggested(): bool
204  {
205  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED);
206  }
207  public function withShowSolutionSuggested(bool $flag): self
208  {
209  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_SUGGESTED, $flag);
210  }
211 
212  public function getShowSolutionListComparison(): bool
213  {
214  return $this->compareResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE);
215  }
216  public function withShowSolutionListComparison(bool $flag): self
217  {
218  return $this->modifyResultPresentation(self::RESULTPRES_BIT_SOLUTION_LISTCOMPARE, $flag);
219  }
220 
221  public function getExportSettings(): int
222  {
223  return $this->exportsettings;
224  }
225  public function withExportSettings(int $exportsettings): self
226  {
227  $clone = clone $this;
228  $clone->exportsettings = $exportsettings;
229  return $clone;
230  }
231  protected function compareExportSetting(int $bit): bool
232  {
233  return ($this->exportsettings & $bit) > 0;
234  }
235  protected function modifyExportSetting(int $bit, bool $flag): self
236  {
237  $clone = clone $this;
238  $v = $clone->exportsettings;
239 
240  if ($flag) {
241  $v = $v | $bit;
242  } else {
243  if ($this->compareExportSetting($bit)) {
244  $v = $v ^ $bit;
245  }
246  }
247  $clone->exportsettings = $v;
248  return $clone;
249  }
250 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
withShowExamIdInTestResults(bool $examid_in_test_res)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
__construct(VocabulariesInterface $vocabularies)
$lng
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
This describes inputs that can be used in forms.
Definition: FormInput.php:31
withResultsPresentation(int $results_presentation)
Refinery Factory $refinery