ILIAS  release_8 Revision v8.24
ilObjTestSettingsResultSummary.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as Refinery;
24
26{
27 public const SCORE_REPORTING_DISABLED = 0;
28 public const SCORE_REPORTING_FINISHED = 1;
30 public const SCORE_REPORTING_DATE = 3;
32
33 protected int $score_reporting = 0;
34 protected ?\DateTimeImmutable $reporting_date = null;
35 protected bool $pass_deletion_allowed = false;
40 protected bool $show_pass_details = false;
41
42 public function __construct(int $test_id)
43 {
45 }
46
47 public function toForm(
49 FieldFactory $f,
50 Refinery $refinery,
51 array $environment = null
52 ): FormInput {
53 $trafo = $refinery->custom()->transformation(
54 function ($v) {
55 list($mode, $date) = $v;
56 if (count($date) < 1) {
57 $date = null;
58 } else {
59 $date = array_shift($date);
60 }
61 return [(int) $mode, $date];
62 }
63 );
64
66 if ($reporting_date !== null) {
67 $reporting_date = $reporting_date->setTimezone(
68 new DateTimeZone($environment['user_time_zone'])
69 )->format($environment['user_date_format']->toString() . ' H:i');
70 }
71
72 $results_time_group = $f->switchableGroup(
73 [
74 self::SCORE_REPORTING_IMMIDIATLY => $f->group([], $lng->txt('tst_results_access_always'), $lng->txt('tst_results_access_always_desc')),
75 self::SCORE_REPORTING_FINISHED => $f->group([], $lng->txt('tst_results_access_finished'), $lng->txt('tst_results_access_finished_desc')),
76 self::SCORE_REPORTING_AFTER_PASSED => $f->group([], $lng->txt('tst_results_access_passed'), $lng->txt('tst_results_access_passed_desc')),
77 self::SCORE_REPORTING_DATE => $f->group(
78 [
79 $f->dateTime($lng->txt('tst_reporting_date'), "")
80 ->withTimezone($environment['user_time_zone'])
81 ->withUseTime(true)
82 ->withFormat($environment['user_date_format'])
83 ->withValue(
85 )
86 ->withRequired(true)
87 ],
88 $lng->txt('tst_results_access_date'),
89 $lng->txt('tst_results_access_date_desc')
90 )
91 ],
92 $lng->txt('tst_results_access_setting'),
93 ""
94 )
95 ->withRequired(true)
96 ->withAdditionalTransformation($trafo);
97
98 if ($this->getScoreReporting() > 0) {
99 $results_time_group = $results_time_group->withValue($this->getScoreReporting());
100 }
101
102 $optional_group = $f->optionalGroup(
103 [
104 'score_reporting_mode' => $results_time_group,
105 'show_grading_status' => $f->checkbox(
106 $lng->txt('tst_results_grading_opt_show_status'),
107 $lng->txt('tst_results_grading_opt_show_status_desc')
108 ),
109 'show_grading_mark' => $f->checkbox(
110 $lng->txt('tst_results_grading_opt_show_mark'),
111 $lng->txt('tst_results_grading_opt_show_mark_desc')
112 ),
113 'show_pass_details' => $f->checkbox(
114 $lng->txt('tst_results_grading_opt_show_details'),
115 $lng->txt('tst_results_grading_opt_show_details_desc')
116 ),
117 'pass_deletion_allowed' => $f->checkbox(
118 $lng->txt('tst_pass_deletion'),
119 $lng->txt('tst_pass_deletion_allowed')
120 )
121 ],
122 $lng->txt('tst_results_access_enabled'),
123 $lng->txt('tst_results_access_enabled_desc')
124 );
125
126 if ($this->getScoreReportingEnabled()) {
127 $optional_group = $optional_group->withValue(
128 [
129 "score_reporting_mode" => $this->getScoreReporting(),
130 "show_grading_status" => $this->getShowGradingStatusEnabled(),
131 "show_grading_mark" => $this->getShowGradingMarkEnabled(),
132 "show_pass_details" => $this->getShowPassDetails(),
133 "pass_deletion_allowed" => $this->getPassDeletionAllowed()
134 ]
135 );
136 } else {
137 $optional_group = $optional_group->withValue(null);
138 }
139
140 $fields = ['score_reporting' => $optional_group];
141 return $f->section($fields, $lng->txt('test_results'))
142 ->withAdditionalTransformation(
143 $refinery->custom()->transformation(
144 function ($v) {
145 $settings = clone $this;
146 $mode = 0;
147 $date = null;
148 if ($v['score_reporting']) {
149 list($mode, $date) = $v['score_reporting']['score_reporting_mode'];
151 ->withShowGradingStatusEnabled($v['score_reporting']['show_grading_status'])
152 ->withShowGradingMarkEnabled($v['score_reporting']['show_grading_mark'])
153 ->withShowPassDetails($v['score_reporting']['show_pass_details'])
154 ->withPassDeletionAllowed($v['score_reporting']['pass_deletion_allowed'])
155 ;
156 }
157 return $settings
158 ->withScoreReporting((int) $mode)
159 ->withReportingDate($date);
160 }
161 )
162 );
163 }
164
165 public function toStorage(): array
166 {
167 $dat = $this->getReportingDate();
168 if ($dat) {
169 $dat = $dat->setTimezone(new DateTimeZone('UTC'))
171 }
172 return [
173 'pass_deletion_allowed' => ['integer', (int) $this->getPassDeletionAllowed()],
174 'score_reporting' => ['integer', $this->getScoreReporting()],
175 'reporting_date' => ['text', (string) $dat],
176 'show_grading_status' => ['integer', (int) $this->getShowGradingStatusEnabled()],
177 'show_grading_mark' => ['integer', (int) $this->getShowGradingMarkEnabled()]
178 //show_pass_details
179 ];
180 }
181
182
183 public function getScoreReporting(): int
184 {
185 return $this->score_reporting;
186 }
187 public function withScoreReporting(int $score_reporting): self
188 {
189 $clone = clone $this;
190 $clone->score_reporting = $score_reporting;
191 return $clone;
192 }
193
194 public function getScoreReportingEnabled(): bool
195 {
196 return $this->score_reporting !== self::SCORE_REPORTING_DISABLED;
197 }
198
199 public function getReportingDate(): ?\DateTimeImmutable
200 {
201 return $this->reporting_date;
202 }
203 public function withReportingDate(?\DateTimeImmutable $reporting_date): self
204 {
205 $clone = clone $this;
206 $clone->reporting_date = $reporting_date;
207 return $clone;
208 }
209
210 public function getShowGradingStatusEnabled(): bool
211 {
212 return $this->show_grading_status;
213 }
214 public function withShowGradingStatusEnabled(bool $show_grading_status): self
215 {
216 $clone = clone $this;
217 $clone->show_grading_status = $show_grading_status;
218 return $clone;
219 }
220
221 public function getShowGradingMarkEnabled(): bool
222 {
223 return $this->show_grading_mark;
224 }
225 public function withShowGradingMarkEnabled(bool $show_grading_mark): self
226 {
227 $clone = clone $this;
228 $clone->show_grading_mark = $show_grading_mark;
229 return $clone;
230 }
231
232 public function getPassDeletionAllowed(): bool
233 {
234 return $this->pass_deletion_allowed;
235 }
236 public function withPassDeletionAllowed(bool $pass_deletion_allowed): self
237 {
238 $clone = clone $this;
239 $clone->pass_deletion_allowed = $pass_deletion_allowed;
240 return $clone;
241 }
242
243 public function getShowPassDetails(): bool
244 {
245 return $this->show_pass_details;
246 }
247 public function withShowPassDetails(bool $flag): self
248 {
249 $clone = clone $this;
250 $clone->show_pass_details = $flag;
251 return $clone;
252 }
253}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
language handling
withShowGradingStatusEnabled(bool $show_grading_status)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
withPassDeletionAllowed(bool $pass_deletion_allowed)
withReportingDate(?\DateTimeImmutable $reporting_date)
bool $show_pass_details
this is derived from results_presentation with RESULTPRES_BIT_PASS_DETAILS; see ilObjTestSettingsResu...
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
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Refinery Factory $refinery
$lng