ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestSkillLevelThresholdsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
31  public const CMD_SHOW_SKILL_THRESHOLDS = 'showSkillThresholds';
32  public const CMD_SAVE_SKILL_THRESHOLDS = 'saveSkillThresholds';
33 
34  private ilCtrl $ctrl;
36  private ilLanguage $lng;
37  private ilDBInterface $db;
38 
42  private $testId;
43 
48 
50 
52  {
53  $this->ctrl = $ctrl;
54  $this->tpl = $tpl;
55  $this->lng = $lng;
56  $this->db = $db;
57  $this->testId = $testId;
58  $this->questionAssignmentColumnsEnabled = false;
59  }
60 
64  public function getQuestionContainerId(): int
65  {
67  }
68 
73  {
74  $this->questionContainerId = $questionContainerId;
75  }
76 
77  public function executeCommand()
78  {
79  $cmd = $this->ctrl->getCmd('show') . 'Cmd';
80 
81  $this->$cmd();
82  }
83 
87  public function setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
88  {
89  $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
90  }
91 
95  public function areQuestionAssignmentColumnsEnabled(): bool
96  {
98  }
99 
103  public function getTestId(): int
104  {
105  return $this->testId;
106  }
107 
108  private function saveSkillThresholdsCmd()
109  {
110  if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
111  $assignmentList = $this->buildSkillQuestionAssignmentList();
112  $assignmentList->loadFromDb();
113 
114  $valid = true;
115 
116  $table = $this->getPopulatedTable();
117  $elements = $table->getInputElements((array) ($_POST['rendered'] ?? []));
118  foreach ($elements as $elm) {
119  if (!$elm->checkInput()) {
120  $valid = false;
121  }
122 
123  $elm->setValue($_POST[$elm->getPostVar()]);
124  }
125 
126  if (!$valid) {
127  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
128  $this->showSkillThresholdsCmd($table);
129  return;
130  }
131 
132  $threshold = array();
133  foreach ($elements as $elm) {
134  $key = $elm->getPostVar();
135  $value = $_POST[$key];
136  $matches = null;
137  if (preg_match('/^threshold_(\d+?):(\d+?)_(\d+?)$/', $key, $matches) && is_array($matches)) {
138  $threshold[$matches[1] . ':' . $matches[2]][$matches[3]] = $value;
139  }
140  }
141 
143  $skillLevelThresholds = array();
144 
145  foreach ($assignmentList->getUniqueAssignedSkills() as $data) {
146  $skill = $data['skill'];
147  $skillKey = $data['skill_base_id'] . ':' . $data['skill_tref_id'];
148  $levels = $skill->getLevelData();
149 
150  $thresholds_by_level = array();
151 
152  foreach ($levels as $level) {
153  if (isset($threshold[$skillKey]) && isset($threshold[$skillKey][$level['id']])) {
154  $skillLevelThreshold = new ilTestSkillLevelThreshold($this->db);
155 
156  $skillLevelThreshold->setTestId($this->getTestId());
157  $skillLevelThreshold->setSkillBaseId($data['skill_base_id']);
158  $skillLevelThreshold->setSkillTrefId($data['skill_tref_id']);
159  $skillLevelThreshold->setSkillLevelId($level['id']);
160 
161  $skillLevelThreshold->setThreshold($threshold[$skillKey][$level['id']]);
162  $skillLevelThresholds[] = $skillLevelThreshold;
163  $thresholds_by_level[] = $threshold[$skillKey][$level['id']];
164  }
165  }
166 
167  $sorted_thresholds_by_level = $thresholds_by_level = array_values($thresholds_by_level);
168  sort($sorted_thresholds_by_level);
169  if (
170  $sorted_thresholds_by_level != $thresholds_by_level ||
171  count($thresholds_by_level) != count(array_unique($thresholds_by_level))
172  ) {
173  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('ass_competence_respect_level_ordering'));
174  $this->showSkillThresholdsCmd($table);
175  return;
176  }
177  }
178 
179  foreach ($skillLevelThresholds as $skillLevelThreshold) {
180  $skillLevelThreshold->saveToDb();
181  }
182 
183  $this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_msg_skl_lvl_thresholds_saved'), true);
184  }
185 
186  $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_THRESHOLDS);
187  }
188 
193  {
194  if (null === $table) {
195  $table = $this->getPopulatedTable();
196  }
197 
198  $this->tpl->setContent($this->ctrl->getHTML($table));
199  }
200 
205  {
206  $table = $this->buildTableGUI();
207 
208  $skillLevelThresholdList = $this->buildSkillLevelThresholdList();
209  $skillLevelThresholdList->loadFromDb();
210  $table->setSkillLevelThresholdList($skillLevelThresholdList);
211 
212  $assignmentList = $this->buildSkillQuestionAssignmentList();
213  $assignmentList->loadFromDb();
214 
215  $table->setData($table->completeCompetenceTitles(
216  $assignmentList->getUniqueAssignedSkills()
217  ));
218  return $table;
219  }
220 
222  {
224  $this,
225  $this->getTestId(),
226  self::CMD_SHOW_SKILL_THRESHOLDS,
227  $this->ctrl,
228  $this->lng
229  );
230  $table->setQuestionAssignmentColumnsEnabled($this->areQuestionAssignmentColumnsEnabled());
231  $table->initColumns();
232 
233  return $table;
234  }
235 
237  {
238  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
239  $assignmentList->setParentObjId($this->getQuestionContainerId());
240 
241  return $assignmentList;
242  }
243 
245  {
246  $thresholdList = new ilTestSkillLevelThresholdList($this->db);
247  $thresholdList->setTestId($this->getTestId());
248 
249  return $thresholdList;
250  }
251 }
$valid
showSkillThresholdsCmd(ilTestSkillLevelThresholdsTableGUI $table=null)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
string $key
Consumer key/client ID value.
Definition: System.php:193
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilDBInterface $db, $testId)