ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
SettingsResultSummary.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{
32 protected ScoreReportingTypes $score_reporting = ScoreReportingTypes::SCORE_REPORTING_DISABLED;
33 protected ?\DateTimeImmutable $reporting_date = null;
34 protected bool $pass_deletion_allowed = false;
39 protected bool $show_pass_details = false;
40 protected bool $show_grading_status = false;
41 protected bool $show_grading_mark = false;
42
43 public function toForm(
45 FieldFactory $f,
47 ?array $environment = null
48 ): FormInput {
49 $trafo = $refinery->custom()->transformation(
50 function ($v) {
51 list($mode, $date) = $v;
52 if (count($date) < 1) {
53 $date = null;
54 } else {
55 $date = array_shift($date);
56 }
57 return [(int) $mode, $date];
58 }
59 );
60
61 $results_time_group = $f->switchableGroup(
62 [
63 ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY->value => $f->group([], $lng->txt('tst_results_access_always'), $lng->txt('tst_results_access_always_desc')),
64 ScoreReportingTypes::SCORE_REPORTING_FINISHED->value => $f->group([], $lng->txt('tst_results_access_finished'), $lng->txt('tst_results_access_finished_desc')),
65 ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED->value => $f->group([], $lng->txt('tst_results_access_passed'), $lng->txt('tst_results_access_passed_desc')),
66 ScoreReportingTypes::SCORE_REPORTING_DATE->value => $f->group(
67 [
68 $f->dateTime($lng->txt('tst_reporting_date'), "")
69 ->withTimezone($environment['user_time_zone'])
70 ->withFormat($environment['user_date_format'])
71 ->withUseTime(true)
72 ->withValue(
73 $this->getReportingDate()?->setTimezone(
74 new \DateTimeZone($environment['user_time_zone'])
75 )
76 )
77 ->withRequired(true)
78 ],
79 $lng->txt('tst_results_access_date'),
80 $lng->txt('tst_results_access_date_desc')
81 )
82 ],
83 $lng->txt('tst_results_access_setting'),
84 ""
85 )
86 ->withRequired(true)
87 ->withAdditionalTransformation($trafo);
88
89 if ($this->getScoreReporting() !== ScoreReportingTypes::SCORE_REPORTING_DISABLED) {
90 $results_time_group = $results_time_group->withValue($this->getScoreReporting()->value);
91 }
92
93
94 $optional_group = $f->optionalGroup(
95 [
96 'score_reporting_mode' => $results_time_group,
97 'show_grading_status' => $f->checkbox(
98 $lng->txt('tst_results_grading_opt_show_status'),
99 $lng->txt('tst_results_grading_opt_show_status_desc')
100 ),
101 'show_grading_mark' => $f->checkbox(
102 $lng->txt('tst_results_grading_opt_show_mark'),
103 $lng->txt('tst_results_grading_opt_show_mark_desc')
104 ),
105 'show_pass_details' => $f->checkbox(
106 $lng->txt('tst_results_grading_opt_show_details'),
107 $lng->txt('tst_results_grading_opt_show_details_desc')
108 ),
109 'pass_deletion_allowed' => $f->checkbox(
110 $lng->txt('tst_pass_deletion'),
111 $lng->txt('tst_pass_deletion_allowed')
112 )
113 ],
114 $lng->txt('tst_results_access_enabled'),
115 $lng->txt('tst_results_access_enabled_desc')
116 );
117
118 if ($this->getScoreReporting()->isReportingEnabled()) {
119 $optional_group = $optional_group->withValue(
120 [
121 "score_reporting_mode" => $this->getScoreReporting()->value,
122 "show_grading_status" => $this->getShowGradingStatusEnabled(),
123 "show_grading_mark" => $this->getShowGradingMarkEnabled(),
124 "show_pass_details" => $this->getShowPassDetails(),
125 "pass_deletion_allowed" => $this->getPassDeletionAllowed()
126 ]
127 );
128 } else {
129 $optional_group = $optional_group->withValue(null);
130 }
131
132 $fields = ['score_reporting' => $optional_group];
133 return $f->section($fields, $lng->txt('test_results'))
135 $refinery->custom()->transformation(
136 function ($v) {
137 $settings = clone $this;
138 $mode = 0;
139 $date = null;
140 if ($v['score_reporting']) {
141 list($mode, $date) = $v['score_reporting']['score_reporting_mode'];
142 $settings = $settings
143 ->withShowGradingStatusEnabled($v['score_reporting']['show_grading_status'])
144 ->withShowGradingMarkEnabled($v['score_reporting']['show_grading_mark'])
145 ->withShowPassDetails($v['score_reporting']['show_pass_details'])
146 ->withPassDeletionAllowed($v['score_reporting']['pass_deletion_allowed'])
147 ;
148 }
149 return $settings
150 ->withScoreReporting(ScoreReportingTypes::from($mode))
151 ->withReportingDate($date);
152 }
153 )
154 );
155 }
156
157 public function toStorage(): array
158 {
159 return [
160 'pass_deletion_allowed' => [\ilDBConstants::T_INTEGER, (int) $this->getPassDeletionAllowed()],
161 'score_reporting' => [\ilDBConstants::T_INTEGER, $this->getScoreReporting()->value],
162 'reporting_date' => [\ilDBConstants::T_INTEGER, $this->getReportingDate() !== null ? $this->getReportingDate()->getTimestamp() : 0],
163 'show_grading_status' => [\ilDBConstants::T_INTEGER, (int) $this->getShowGradingStatusEnabled()],
164 'show_grading_mark' => [\ilDBConstants::T_INTEGER, (int) $this->getShowGradingMarkEnabled()]
165 ];
166 }
167
168 public function toLog(AdditionalInformationGenerator $additional_info): array
169 {
170 switch ($this->getScoreReporting()) {
171 case ScoreReportingTypes::SCORE_REPORTING_DISABLED:
172 $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
174 break;
175 case ScoreReportingTypes::SCORE_REPORTING_FINISHED:
176 $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
177 ->getTagForLangVar('tst_results_access_finished');
178 $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
179 break;
180 case ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY:
181 $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
182 ->getTagForLangVar('tst_results_access_always');
183 $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
184 break;
185 case ScoreReportingTypes::SCORE_REPORTING_DATE:
186 $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $this->getReportingDate()
187 ->setTimezone(new \DateTimeZone('UTC'))->format(AdditionalInformationGenerator::DATE_STORAGE_FORMAT);
188 $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
189 break;
190 case ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED:
191 $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
192 ->getTagForLangVar('tst_results_access_passed');
193 $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
194 break;
195 }
196 return $log_array;
197 }
198
200 AdditionalInformationGenerator $additional_info
201 ): array {
202 return [
203 AdditionalInformationGenerator::KEY_SCORING_REPORTING_SHOW_STATUS => $additional_info
204 ->getEnabledDisabledTagForBool($this->getShowGradingStatusEnabled()),
205 AdditionalInformationGenerator::KEY_SCORING_REPORTING_SHOW_MARK => $additional_info
206 ->getEnabledDisabledTagForBool($this->getShowGradingMarkEnabled()),
207 AdditionalInformationGenerator::KEY_SCORING_REPORTING_SHOW_DETAILS => $additional_info
208 ->getEnabledDisabledTagForBool($this->getShowPassDetails()),
209 AdditionalInformationGenerator::KEY_SCORING_DELETION_ALLOWED => $additional_info
210 ->getEnabledDisabledTagForBool($this->getPassDeletionAllowed())
211 ];
212 }
213
215 {
216 return $this->score_reporting;
217 }
218 public function withScoreReporting(ScoreReportingTypes $score_reporting): self
219 {
220 $clone = clone $this;
221 $clone->score_reporting = $score_reporting;
222 return $clone;
223 }
224
225 public function getReportingDate(): ?\DateTimeImmutable
226 {
227 return $this->reporting_date;
228 }
229 public function withReportingDate(?\DateTimeImmutable $reporting_date): self
230 {
231 $clone = clone $this;
232 $clone->reporting_date = $reporting_date;
233 return $clone;
234 }
235
236 public function getShowGradingStatusEnabled(): bool
237 {
238 return $this->show_grading_status;
239 }
240 public function withShowGradingStatusEnabled(bool $show_grading_status): self
241 {
242 $clone = clone $this;
243 $clone->show_grading_status = $show_grading_status;
244 return $clone;
245 }
246
247 public function getShowGradingMarkEnabled(): bool
248 {
249 return $this->show_grading_mark;
250 }
251 public function withShowGradingMarkEnabled(bool $show_grading_mark): self
252 {
253 $clone = clone $this;
254 $clone->show_grading_mark = $show_grading_mark;
255 return $clone;
256 }
257
258 public function getPassDeletionAllowed(): bool
259 {
260 return $this->pass_deletion_allowed;
261 }
262 public function withPassDeletionAllowed(bool $pass_deletion_allowed): self
263 {
264 $clone = clone $this;
265 $clone->pass_deletion_allowed = $pass_deletion_allowed;
266 return $clone;
267 }
268
269 public function getShowPassDetails(): bool
270 {
271 return $this->show_pass_details;
272 }
273 public function withShowPassDetails(bool $flag): self
274 {
275 $clone = clone $this;
276 $clone->show_pass_details = $flag;
277 return $clone;
278 }
279
280 public function toExport(): array
281 {
282 return [
283 'score_reporting' => $this->getScoreReporting()->value,
284 'reporting_date' => $this->getReportingDate()?->format(\DateTimeInterface::ATOM),
285 'show_grading_status' => $this->getShowGradingStatusEnabled(),
286 'show_grading_mark' => $this->getShowGradingMarkEnabled(),
287 'show_pass_details' => $this->getShowPassDetails(),
288 'pass_deletion_allowed' => $this->getPassDeletionAllowed()
289 ];
290 }
291
292 public static function fromExport(array $data): static
293 {
294 return (new self())
295 ->withScoreReporting(ScoreReportingTypes::from($data['score_reporting']))
296 ->withReportingDate($data['reporting_date'] !== 0 ? new \DateTimeImmutable($data['reporting_date']) : null)
297 ->withShowGradingStatusEnabled((bool) $data['show_grading_status'])
298 ->withShowGradingMarkEnabled((bool) $data['show_grading_mark'])
299 ->withShowPassDetails((bool) $data['show_pass_details'])
300 ->withPassDeletionAllowed((bool) $data['pass_deletion_allowed']);
301 }
302}
Builds data types.
Definition: Factory.php:36
bool $show_pass_details
this is derived from results_presentation with RESULTPRES_BIT_PASS_DETAILS; see ilObjTestSettingsResu...
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
toLog(AdditionalInformationGenerator $additional_info)
toExport()
Transform the object into a simple, associative array.
static fromExport(array $data)
Creates an instance of the object from an array.
getLogEntriesForScoreReportingEnabled(AdditionalInformationGenerator $additional_info)
language handling
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
global $lng
Definition: privfeed.php:31