ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTestRandomQuestionSetGeneralConfigFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 {
35  protected bool $edit_mode_enabled = true;
36 
37  public function __construct(
38  private ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI,
39  private ilTestRandomQuestionSetConfig $questionSetConfig
40  ) {
42  $this->lng->loadLanguageModule('form');
43  }
44 
45  public function isEditModeEnabled(): bool
46  {
48  }
49 
50  public function setEditModeEnabled(bool $edit_mode_enabled): void
51  {
52  $this->edit_mode_enabled = $edit_mode_enabled;
53  }
54 
55  public function build(): void
56  {
57  $this->setFormAction($this->ctrl->getFormAction($this->questionSetConfigGUI));
58 
59  $this->setTitle($this->lng->txt('tst_rnd_quest_set_cfg_general_form'));
60  $this->setId('tstRndQuestSetCfgGeneralForm');
61 
62  $this->addCommandButton(
64  $this->lng->txt('save')
65  );
66 
67  $requirePoolsQuestionsHomoScored = new ilCheckboxInputGUI(
68  $this->lng->txt('tst_inp_all_quest_points_equal_per_pool'),
69  'quest_points_equal_per_pool'
70  );
71 
72  $requirePoolsQuestionsHomoScored->setInfo(
73  $this->lng->txt('tst_inp_all_quest_points_equal_per_pool_desc')
74  );
75 
76  $requirePoolsQuestionsHomoScored->setChecked(
77  (bool)
78  $this->questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired()
79  );
80 
81  $this->addItem($requirePoolsQuestionsHomoScored);
82 
83  // question amount config mode (per test / per pool)
84 
85  $questionAmountConfigMode = new ilRadioGroupInputGUI(
86  $this->lng->txt('tst_inp_quest_amount_cfg_mode'),
87  'quest_amount_cfg_mode'
88  );
89 
91  $this->questionSetConfig
92  ));
93 
94  $questionAmountConfigModePerTest = new ilRadioOption(
95  $this->lng->txt('tst_inp_quest_amount_cfg_mode_test'),
97  );
98 
99  $questionAmountConfigMode->addOption($questionAmountConfigModePerTest);
100 
101  $questionAmountConfigModePerPool = new ilRadioOption(
102  $this->lng->txt('tst_inp_quest_amount_cfg_mode_pool'),
104  );
105 
106  $questionAmountConfigMode->addOption($questionAmountConfigModePerPool);
107 
108  $questionAmountConfigMode->setRequired(true);
109 
110  $this->addItem($questionAmountConfigMode);
111 
112  // question amount per test
113 
114  $questionAmountPerTest = new ilNumberInputGUI(
115  $this->lng->txt('tst_inp_quest_amount_per_test'),
116  'quest_amount_per_test'
117  );
118 
119  $questionAmountPerTest->setRequired(true);
120  $questionAmountPerTest->setMinValue(1);
121  $questionAmountPerTest->allowDecimals(false);
122  $questionAmountPerTest->setMinvalueShouldBeGreater(false);
123  $questionAmountPerTest->setSize(4);
124 
125  $questionAmountPerTest->setValue(
126  (string) $this->questionSetConfig->getQuestionAmountPerTest()
127  );
128 
129  $questionAmountConfigModePerTest->addSubItem($questionAmountPerTest);
130 
131  if (!$this->isEditModeEnabled()) {
132  $requirePoolsQuestionsHomoScored->setDisabled(true);
133  $questionAmountConfigMode->setDisabled(true);
134  $questionAmountPerTest->setDisabled(true);
135  }
136  }
137 
139  {
140  switch ($config->getQuestionAmountConfigurationMode()) {
143 
144  return $config->getQuestionAmountConfigurationMode();
145  }
146 
148  }
149 
150  public function save(AdditionalInformationGenerator $additional_info): array
151  {
152  $log_array = [];
153  $question_equal_per_pool = $this->getItemByPostVar('quest_points_equal_per_pool')->getChecked();
154  $this->questionSetConfig->setPoolsWithHomogeneousScoredQuestionsRequired(
155  $question_equal_per_pool
156  );
157 
158  $log_array[AdditionalInformationGenerator::KEY_HOMOGENEOUS_SCORING] = $additional_info
159  ->getTrueFalseTagForBool($question_equal_per_pool);
160 
161  $question_amount_configuration_mode = $this->getItemByPostVar('quest_amount_cfg_mode')->getValue();
162  $this->questionSetConfig->setQuestionAmountConfigurationMode(
163  $question_amount_configuration_mode
164  );
165 
166  $log_array[AdditionalInformationGenerator::KEY_QUESTION_AMOUNT_TYPE] = $this->questionSetConfig->getQuestionAmountPerTest()
167  ? $additional_info->getTagForLangVar('tst_inp_quest_amount_cfg_mode_test')
168  : $additional_info->getTagForLangVar('tst_inp_quest_amount_cfg_mode_pool');
169 
170  $this->questionSetConfig->setQuestionAmountPerTest(null);
171  if (!$this->questionSetConfig->getQuestionAmountPerTest()) {
172  $question_amount_per_test = (int) $this->getItemByPostVar('quest_amount_per_test')->getValue();
173  $this->questionSetConfig->setQuestionAmountPerTest(
174  $question_amount_per_test
175  );
176  $log_array[AdditionalInformationGenerator::KEY_QUESTION_AMOUNT_PER_TEST] = $question_amount_per_test;
177  }
178 
179  $this->questionSetConfig->saveToDb();
180  return $log_array;
181  }
182 }
This class represents an option in a radio group.
setId(string $a_id)
getItemByPostVar(string $a_post_var)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a property in a property form.
fetchValidQuestionAmountConfigModeWithFallbackModePerTest(ilTestRandomQuestionSetConfig $config)
setFormAction(string $a_formaction)
This class represents a number property in a property form.
__construct(private ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, private ilTestRandomQuestionSetConfig $questionSetConfig)
setRequired(bool $a_required)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
__construct(Container $dic, ilPlugin $plugin)