ILIAS  release_8 Revision v8.24
class.ilTestSkillLevelThresholdsGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 public const CMD_SHOW_SKILL_THRESHOLDS = 'showSkillThresholds';
30 public const CMD_SAVE_SKILL_THRESHOLDS = 'saveSkillThresholds';
31
32 private ilCtrl $ctrl;
36
40 private $testId;
41
46
48
50 {
51 $this->ctrl = $ctrl;
52 $this->tpl = $tpl;
53 $this->lng = $lng;
54 $this->db = $db;
55 $this->testId = $testId;
56 $this->questionAssignmentColumnsEnabled = false;
57 }
58
62 public function getQuestionContainerId(): int
63 {
65 }
66
71 {
72 $this->questionContainerId = $questionContainerId;
73 }
74
75 public function executeCommand()
76 {
77 $cmd = $this->ctrl->getCmd('show') . 'Cmd';
78
79 $this->$cmd();
80 }
81
86 {
87 $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
88 }
89
94 {
96 }
97
101 public function getTestId(): int
102 {
103 return $this->testId;
104 }
105
106 private function saveSkillThresholdsCmd()
107 {
108 require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
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 {
223 require_once 'Modules/Test/classes/tables/class.ilTestSkillLevelThresholdsTableGUI.php';
225 $this,
226 $this->getTestId(),
227 self::CMD_SHOW_SKILL_THRESHOLDS,
228 $this->ctrl,
229 $this->lng
230 );
231 $table->setQuestionAssignmentColumnsEnabled($this->areQuestionAssignmentColumnsEnabled());
232 $table->initColumns();
233
234 return $table;
235 }
236
238 {
239 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
240 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
241 $assignmentList->setParentObjId($this->getQuestionContainerId());
242
243 return $assignmentList;
244 }
245
247 {
248 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
249 $thresholdList = new ilTestSkillLevelThresholdList($this->db);
250 $thresholdList->setTestId($this->getTestId());
251
252 return $thresholdList;
253 }
254}
Class ilCtrl provides processing control methods.
language handling
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilDBInterface $db, $testId)
setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
showSkillThresholdsCmd(ilTestSkillLevelThresholdsTableGUI $table=null)
$valid
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10