ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestSettingsParticipantFunctionality.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
27 {
28  public function __construct(
29  int $test_id,
30  protected bool $use_previous_answers_allowed = false,
31  protected bool $suspend_test_allowed = false,
32  protected bool $postponed_questions_move_to_end = false,
33  protected int $usrpass_overview_mode = 0,
34  protected bool $question_marking_enabled = false,
35  protected bool $question_list_enabled = false
36  ) {
37  parent::__construct($test_id);
38  }
39 
44  public function toForm(
48  array $environment = null
49  ): FormInput {
50  $inputs['use_previous_answers'] = $f->checkbox(
51  $lng->txt('tst_use_previous_answers'),
52  $lng->txt('tst_use_previous_answers_description')
54 
55  $inputs['allow_suspend_test'] = $f->checkbox(
56  $lng->txt('tst_show_cancel'),
57  $lng->txt('tst_show_cancel_description')
58  )->withValue($this->getSuspendTestAllowed());
59 
60  $inputs['postponed_questions_behaviour'] = $f->radio(
61  $lng->txt('tst_postpone')
62  )->withOption(
63  '0',
64  $lng->txt('tst_postpone_off'),
65  $lng->txt('tst_postpone_off_desc'),
66  )->withOption(
67  '1',
68  $lng->txt('tst_postpone_on'),
69  $lng->txt('tst_postpone_on_desc'),
70  )->withValue($this->getPostponedQuestionsMoveToEnd() ? '1' : '0')
71  ->withAdditionalTransformation($refinery->kindlyTo()->bool());
72 
73  $inputs['enable_question_list'] = $f->checkbox(
74  $lng->txt('tst_enable_questionlist'),
75  $lng->txt('tst_enable_questionlist_description')
76  )->withValue($this->getQuestionListEnabled());
77 
78  $inputs['usr_pass_overview'] = $this->getInputUsrPassOverview(
79  $lng,
80  $f,
81  $refinery
82  );
83 
84  $inputs['enable_question_marking'] = $f->checkbox(
85  $lng->txt('question_marking'),
86  $lng->txt('question_marking_description')
88 
89  return $f->section($inputs, $lng->txt('tst_sequence_properties'));
90  }
91 
92  private function getInputUsrPassOverview(
96  ): OptionalGroup {
97  $trafo = $refinery->custom()->transformation(
98  static function (?array $vs): int {
99  if ($vs === null) {
100  return 0;
101  }
102 
103  $usrpass_overview_mode = 1;
104 
105  if ($vs['show_at_beginning'] === true) {
106  $usrpass_overview_mode += 2;
107  }
108 
109  if ($vs['show_at_end'] === true) {
110  $usrpass_overview_mode += 4;
111  }
112 
113  if ($vs['show_description'] === true) {
114  $usrpass_overview_mode += 8;
115  }
116 
117  return $usrpass_overview_mode;
118  }
119  );
120 
121  $sub_inputs_usrpass_questionlist['show_at_beginning'] = $f->checkbox(
122  $lng->txt('tst_list_of_questions_start')
123  );
124  $sub_inputs_usrpass_questionlist['show_at_end'] = $f->checkbox(
125  $lng->txt('tst_list_of_questions_end')
126  );
127  $sub_inputs_usrpass_questionlist['show_description'] = $f->checkbox(
128  $lng->txt('tst_list_of_questions_with_description')
129  );
130 
131  $enable_usrpass_questionlist = $f->optionalGroup(
132  $sub_inputs_usrpass_questionlist,
133  $lng->txt('tst_show_summary'),
134  $lng->txt('tst_show_summary_description')
135  )->withValue(null)
136  ->withAdditionalTransformation($trafo);
137 
138  if ($this->getUsrPassOverviewEnabled() === false) {
139  return $enable_usrpass_questionlist;
140  }
141 
142  return $enable_usrpass_questionlist->withValue(
143  [
144  'show_at_beginning' => $this->getShownQuestionListAtBeginning(),
145  'show_at_end' => $this->getShownQuestionListAtEnd(),
146  'show_description' => $this->getShowDescriptionInQuestionList()
147  ]
148  );
149  }
150 
151  public function toStorage(): array
152  {
153  return [
154  'use_previous_answers' => ['integer', (int) $this->getUsePreviousAnswerAllowed()],
155  'suspend_test_allowed' => ['integer', (int) $this->getSuspendTestAllowed()],
156  'sequence_settings' => ['integer', (int) $this->getPostponedQuestionsMoveToEnd()],
157  'usr_pass_overview_mode' => ['integer', $this->getUsrPassOverviewMode()],
158  'show_marker' => ['integer', (int) $this->getQuestionMarkingEnabled()],
159  'show_questionlist' => ['integer', $this->getQuestionListEnabled()]
160  ];
161  }
162 
163  public function getUsePreviousAnswerAllowed(): bool
164  {
165  return $this->use_previous_answers_allowed;
166  }
167  public function withUsePreviousAnswerAllowed(bool $use_previous_answers_allowed): self
168  {
169  $clone = clone $this;
170  $clone->use_previous_answers_allowed = $use_previous_answers_allowed;
171  return $clone;
172  }
173 
174  public function getSuspendTestAllowed(): bool
175  {
176  return $this->suspend_test_allowed;
177  }
178  public function withSuspendTestAllowed(bool $suspend_test_allowed): self
179  {
180  $clone = clone $this;
181  $clone->suspend_test_allowed = $suspend_test_allowed;
182  return $clone;
183  }
184 
185  public function getPostponedQuestionsMoveToEnd(): bool
186  {
187  return $this->postponed_questions_move_to_end;
188  }
189  public function withPostponedQuestionsMoveToEnd(bool $postponed_questions_move_to_end): self
190  {
191  $clone = clone $this;
192  $clone->postponed_questions_move_to_end = $postponed_questions_move_to_end;
193  return $clone;
194  }
195 
196  public function getQuestionListEnabled(): bool
197  {
198  return $this->question_list_enabled;
199  }
200  public function withQuestionListEnabled(bool $question_list_enabled): self
201  {
202  $clone = clone $this;
203  $clone->question_list_enabled = $question_list_enabled;
204  return $clone;
205  }
206 
207  public function getUsrPassOverviewMode(): int
208  {
209  return $this->usrpass_overview_mode;
210  }
211  public function getUsrPassOverviewEnabled(): bool
212  {
213  if (($this->usrpass_overview_mode & 1) > 0) {
214  return true;
215  }
216 
217  return false;
218  }
219  public function getShownQuestionListAtBeginning(): bool
220  {
221  if (($this->usrpass_overview_mode & 2) > 0) {
222  return true;
223  }
224 
225  return false;
226  }
227  public function getShownQuestionListAtEnd(): bool
228  {
229  if (($this->usrpass_overview_mode & 4) > 0) {
230  return true;
231  }
232 
233  return false;
234  }
235  public function getShowDescriptionInQuestionList(): bool
236  {
237  if (($this->usrpass_overview_mode & 8) > 0) {
238  return true;
239  }
240 
241  return false;
242  }
243  public function withUsrPassOverviewMode(int $usrpass_overview_mode): self
244  {
245  $clone = clone $this;
246  $clone->usrpass_overview_mode = $usrpass_overview_mode;
247  return $clone;
248  }
249 
250  public function getQuestionMarkingEnabled(): bool
251  {
252  return $this->question_marking_enabled;
253  }
254  public function withQuestionMarkingEnabled(bool $question_marking_enabled): self
255  {
256  $clone = clone $this;
257  $clone->question_marking_enabled = $question_marking_enabled;
258  return $clone;
259  }
260 }
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...
This describes optional group inputs.
__construct(VocabulariesInterface $vocabularies)
$lng
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
__construct(int $test_id, protected bool $use_previous_answers_allowed=false, protected bool $suspend_test_allowed=false, protected bool $postponed_questions_move_to_end=false, protected int $usrpass_overview_mode=0, protected bool $question_marking_enabled=false, protected bool $question_list_enabled=false)
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
withPostponedQuestionsMoveToEnd(bool $postponed_questions_move_to_end)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Refinery Factory $refinery
getInputUsrPassOverview(\ilLanguage $lng, FieldFactory $f, Refinery $refinery)