ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SettingsResultSummary.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
31  protected ScoreReportingTypes $score_reporting = ScoreReportingTypes::SCORE_REPORTING_DISABLED;
32  protected ?\DateTimeImmutable $reporting_date = null;
33  protected bool $pass_deletion_allowed = false;
38  protected bool $show_pass_details = false;
39  protected bool $show_grading_status = false;
40  protected bool $show_grading_mark = false;
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  $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 
65  $results_time_group = $f->switchableGroup(
66  [
67  ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY->value => $f->group([], $lng->txt('tst_results_access_always'), $lng->txt('tst_results_access_always_desc')),
68  ScoreReportingTypes::SCORE_REPORTING_FINISHED->value => $f->group([], $lng->txt('tst_results_access_finished'), $lng->txt('tst_results_access_finished_desc')),
69  ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED->value => $f->group([], $lng->txt('tst_results_access_passed'), $lng->txt('tst_results_access_passed_desc')),
70  ScoreReportingTypes::SCORE_REPORTING_DATE->value => $f->group(
71  [
72  $f->dateTime($lng->txt('tst_reporting_date'), "")
73  ->withTimezone($environment['user_time_zone'])
74  ->withFormat($environment['user_date_format'])
75  ->withUseTime(true)
76  ->withValue(
77  $this->getReportingDate()?->setTimezone(
78  new \DateTimeZone($environment['user_time_zone'])
79  )
80  )
81  ->withRequired(true)
82  ],
83  $lng->txt('tst_results_access_date'),
84  $lng->txt('tst_results_access_date_desc')
85  )
86  ],
87  $lng->txt('tst_results_access_setting'),
88  ""
89  )
90  ->withRequired(true)
91  ->withAdditionalTransformation($trafo);
92 
93  if ($this->getScoreReporting() !== ScoreReportingTypes::SCORE_REPORTING_DISABLED) {
94  $results_time_group = $results_time_group->withValue($this->getScoreReporting()->value);
95  }
96 
97 
98  $optional_group = $f->optionalGroup(
99  [
100  'score_reporting_mode' => $results_time_group,
101  'show_grading_status' => $f->checkbox(
102  $lng->txt('tst_results_grading_opt_show_status'),
103  $lng->txt('tst_results_grading_opt_show_status_desc')
104  ),
105  'show_grading_mark' => $f->checkbox(
106  $lng->txt('tst_results_grading_opt_show_mark'),
107  $lng->txt('tst_results_grading_opt_show_mark_desc')
108  ),
109  'show_pass_details' => $f->checkbox(
110  $lng->txt('tst_results_grading_opt_show_details'),
111  $lng->txt('tst_results_grading_opt_show_details_desc')
112  ),
113  'pass_deletion_allowed' => $f->checkbox(
114  $lng->txt('tst_pass_deletion'),
115  $lng->txt('tst_pass_deletion_allowed')
116  )
117  ],
118  $lng->txt('tst_results_access_enabled'),
119  $lng->txt('tst_results_access_enabled_desc')
120  );
121 
122  if ($this->getScoreReporting()->isReportingEnabled()) {
123  $optional_group = $optional_group->withValue(
124  [
125  "score_reporting_mode" => $this->getScoreReporting()->value,
126  "show_grading_status" => $this->getShowGradingStatusEnabled(),
127  "show_grading_mark" => $this->getShowGradingMarkEnabled(),
128  "show_pass_details" => $this->getShowPassDetails(),
129  "pass_deletion_allowed" => $this->getPassDeletionAllowed()
130  ]
131  );
132  } else {
133  $optional_group = $optional_group->withValue(null);
134  }
135 
136  $fields = ['score_reporting' => $optional_group];
137  return $f->section($fields, $lng->txt('test_results'))
139  $refinery->custom()->transformation(
140  function ($v) {
141  $settings = clone $this;
142  $mode = 0;
143  $date = null;
144  if ($v['score_reporting']) {
145  list($mode, $date) = $v['score_reporting']['score_reporting_mode'];
146  $settings = $settings
147  ->withShowGradingStatusEnabled($v['score_reporting']['show_grading_status'])
148  ->withShowGradingMarkEnabled($v['score_reporting']['show_grading_mark'])
149  ->withShowPassDetails($v['score_reporting']['show_pass_details'])
150  ->withPassDeletionAllowed($v['score_reporting']['pass_deletion_allowed'])
151  ;
152  }
153  return $settings
154  ->withScoreReporting(ScoreReportingTypes::from($mode))
155  ->withReportingDate($date);
156  }
157  )
158  );
159  }
160 
161  public function toStorage(): array
162  {
163  $dat = $this->getReportingDate();
164  if ($dat) {
165  $dat = $dat->setTimezone(new \DateTimeZone('UTC'))
167  }
168  return [
169  'pass_deletion_allowed' => ['integer', (int) $this->getPassDeletionAllowed()],
170  'score_reporting' => ['integer', $this->getScoreReporting()->value],
171  'reporting_date' => ['text', (string) $dat],
172  'show_grading_status' => ['integer', (int) $this->getShowGradingStatusEnabled()],
173  'show_grading_mark' => ['integer', (int) $this->getShowGradingMarkEnabled()]
174  ];
175  }
176 
177  public function toLog(AdditionalInformationGenerator $additional_info): array
178  {
179  switch ($this->getScoreReporting()) {
180  case ScoreReportingTypes::SCORE_REPORTING_DISABLED:
181  $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
183  break;
184  case ScoreReportingTypes::SCORE_REPORTING_FINISHED:
185  $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
186  ->getTagForLangVar('tst_results_access_finished');
187  $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
188  break;
189  case ScoreReportingTypes::SCORE_REPORTING_IMMIDIATLY:
190  $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
191  ->getTagForLangVar('tst_results_access_always');
192  $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
193  break;
194  case ScoreReportingTypes::SCORE_REPORTING_DATE:
196  ->setTimezone(new \DateTimeZone('UTC'))->format(AdditionalInformationGenerator::DATE_STORAGE_FORMAT);
197  $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
198  break;
199  case ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED:
200  $log_array[AdditionalInformationGenerator::KEY_SCORING_REPORTING] = $additional_info
201  ->getTagForLangVar('tst_results_access_passed');
202  $log_array += $this->getLogEntriesForScoreReportingEnabled($additional_info);
203  break;
204  }
205  return $log_array;
206  }
207 
209  AdditionalInformationGenerator $additional_info
210  ): array {
211  return [
220  ];
221  }
222 
224  {
225  return $this->score_reporting;
226  }
227  public function withScoreReporting(ScoreReportingTypes $score_reporting): self
228  {
229  $clone = clone $this;
230  $clone->score_reporting = $score_reporting;
231  return $clone;
232  }
233 
234  public function getReportingDate(): ?\DateTimeImmutable
235  {
236  return $this->reporting_date;
237  }
238  public function withReportingDate(?\DateTimeImmutable $reporting_date): self
239  {
240  $clone = clone $this;
241  $clone->reporting_date = $reporting_date;
242  return $clone;
243  }
244 
245  public function getShowGradingStatusEnabled(): bool
246  {
248  }
249  public function withShowGradingStatusEnabled(bool $show_grading_status): self
250  {
251  $clone = clone $this;
252  $clone->show_grading_status = $show_grading_status;
253  return $clone;
254  }
255 
256  public function getShowGradingMarkEnabled(): bool
257  {
259  }
260  public function withShowGradingMarkEnabled(bool $show_grading_mark): self
261  {
262  $clone = clone $this;
263  $clone->show_grading_mark = $show_grading_mark;
264  return $clone;
265  }
266 
267  public function getPassDeletionAllowed(): bool
268  {
270  }
271  public function withPassDeletionAllowed(bool $pass_deletion_allowed): self
272  {
273  $clone = clone $this;
274  $clone->pass_deletion_allowed = $pass_deletion_allowed;
275  return $clone;
276  }
277 
278  public function getShowPassDetails(): bool
279  {
281  }
282  public function withShowPassDetails(bool $flag): self
283  {
284  $clone = clone $this;
285  $clone->show_pass_details = $flag;
286  return $clone;
287  }
288 }
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...
toLog(AdditionalInformationGenerator $additional_info)
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, ?array $environment=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
bool $show_pass_details
this is derived from results_presentation with RESULTPRES_BIT_PASS_DETAILS; see ilObjTestSettingsResu...
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
getLogEntriesForScoreReportingEnabled(AdditionalInformationGenerator $additional_info)
This describes inputs that can be used in forms.
Definition: FormInput.php:32