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