ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestSettingsGeneral.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  public function __construct(
28  int $test_id,
29  protected string $question_set_type = ilObjTest::QUESTION_SET_TYPE_FIXED,
30  protected bool $anonymous_test = false
31  ) {
32  parent::__construct($test_id);
33  }
34 
39  public function toForm(
43  array $environment = null
44  ): FormInput | array {
45  $inputs['question_set_type'] = $f->radio(
46  $lng->txt('test_question_set_type')
47  )->withOption(
49  $lng->txt('test_question_set_type_fixed'),
50  $lng->txt('test_question_set_type_fixed_info')
51  )->withOption(
53  $lng->txt('test_question_set_type_random'),
54  $lng->txt('test_question_set_type_random_info')
55  )->withValue($this->getQuestionSetType());
56 
57  $trafo = $refinery->custom()->transformation(
58  static function (string $v): bool {
59  if ($v === '1') {
60  return true;
61  }
62 
63  return false;
64  }
65  );
66 
67  $inputs['anonymity'] = $f->radio(
68  $lng->txt('tst_anonymity')
69  )->withOption(
70  '0',
71  $lng->txt('tst_anonymity_no_anonymization')
72  )->withOption(
73  '1',
74  $lng->txt('tst_anonymity_anonymous_test')
75  )->withValue($this->getAnonymity() ? '1' : '0')
77 
78  if ($environment['participant_data_exists']) {
79  $inputs['question_set_type'] = $inputs['question_set_type']->withDisabled(true);
80  $inputs['anonymity'] = $inputs['anonymity']->withDisabled(true);
81  }
82 
83  return $inputs;
84  }
85 
86  public function toStorage(): array
87  {
88  return [
89  'question_set_type' => ['text', $this->getQuestionSetType()],
90  'anonymity' => ['integer', (int) $this->getAnonymity()]
91  ];
92  }
93 
94  public function getQuestionSetType(): string
95  {
96  return $this->question_set_type;
97  }
98 
99  public function withQuestionSetType(string $question_set_type): self
100  {
101  $clone = clone $this;
102  $clone->question_set_type = $question_set_type;
103  return $clone;
104  }
105 
106  public function getAnonymity(): bool
107  {
108  return $this->anonymous_test;
109  }
110 
111  public function withAnonymity(bool $anonymous_test): self
112  {
113  $clone = clone $this;
114  $clone->anonymous_test = $anonymous_test;
115  return $clone;
116  }
117 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
withAnonymity(bool $anonymous_test)
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...
const QUESTION_SET_TYPE_RANDOM
__construct(VocabulariesInterface $vocabularies)
withQuestionSetType(string $question_set_type)
$lng
__construct(int $test_id, protected string $question_set_type=ilObjTest::QUESTION_SET_TYPE_FIXED, protected bool $anonymous_test=false)
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
const QUESTION_SET_TYPE_FIXED
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Refinery Factory $refinery