ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestSettingsIntroduction.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 bool $introduction_enabled = false,
30  protected ?string $introduction_text = null,
31  protected ?int $introduction_page_id = null,
32  protected bool $conditions_checkbox_enabled = false,
33  ) {
34  parent::__construct($test_id);
35  }
36 
37  public function toForm(
41  array $environment = null
42  ): FormInput {
43  $inputs['introduction_enabled'] = $f->checkbox(
44  $lng->txt('tst_introduction'),
45  $lng->txt('tst_introduction_desc')
46  )->withValue($this->getIntroductionEnabled());
47 
48  $inputs['conditions_checkbox_enabled'] = $f->checkbox(
49  $lng->txt('tst_conditions_checkbox_enabled'),
50  $lng->txt('tst_conditions_checkbox_enabled_desc')
52 
53  return $f->section($inputs, $lng->txt('tst_settings_header_intro'));
54  }
55 
56  public function toStorage(): array
57  {
58  return [
59  'intro_enabled' => ['integer', (int) $this->getIntroductionEnabled()],
60  'introduction' => ['text', $this->getIntroductionText()],
61  'introduction_page_id' => ['integer', $this->getIntroductionPageId()],
62  'conditions_checkbox_enabled' => ['integer', (int) $this->getExamConditionsCheckboxEnabled()],
63  ];
64  }
65 
66  public function getIntroductionEnabled(): bool
67  {
68  return $this->introduction_enabled;
69  }
70  public function withIntroductionEnabled(bool $introduction_enabled): self
71  {
72  $clone = clone $this;
73  $clone->introduction_enabled = $introduction_enabled;
74  return $clone;
75  }
76 
77  public function getIntroductionText(): string
78  {
79  return $this->introduction_text ?? '';
80  }
81  public function withIntroductionText(?string $introduction_text): self
82  {
83  $clone = clone $this;
84  $clone->introduction_text = $introduction_text;
85  return $clone;
86  }
87 
88  public function getIntroductionPageId(): ?int
89  {
90  return $this->introduction_page_id;
91  }
92  public function withIntroductionPageId(?int $introduction_page_id): self
93  {
94  $clone = clone $this;
95  $clone->introduction_page_id = $introduction_page_id;
96  return $clone;
97  }
98 
99  public function getExamConditionsCheckboxEnabled(): bool
100  {
101  return $this->conditions_checkbox_enabled;
102  }
103  public function withExamConditionsCheckboxEnabled(bool $conditions_checkbox_enabled): self
104  {
105  $clone = clone $this;
106  $clone->conditions_checkbox_enabled = $conditions_checkbox_enabled;
107  return $clone;
108  }
109 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
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...
withExamConditionsCheckboxEnabled(bool $conditions_checkbox_enabled)
withIntroductionText(?string $introduction_text)
withIntroductionEnabled(bool $introduction_enabled)
__construct(VocabulariesInterface $vocabularies)
$lng
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
This describes inputs that can be used in forms.
Definition: FormInput.php:31
withIntroductionPageId(?int $introduction_page_id)
__construct(int $test_id, protected bool $introduction_enabled=false, protected ?string $introduction_text=null, protected ?int $introduction_page_id=null, protected bool $conditions_checkbox_enabled=false,)
Refinery Factory $refinery