ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestSkillLevelThresholdsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32{
33 public const CMD_SHOW_SKILL_THRESHOLDS = 'showSkillThresholds';
34 public const CMD_SAVE_SKILL_THRESHOLDS = 'saveSkillThresholds';
35
38
39 public function __construct(
40 private readonly ilCtrlInterface $ctrl,
41 private readonly ilGlobalTemplateInterface $tpl,
42 private readonly ilLanguage $lng,
43 private readonly ilDBInterface $db,
44 private readonly RequestDataCollector $request_data_collector,
45 private readonly int $test_id
46 ) {
47 }
48
52 public function getQuestionContainerId(): int
53 {
55 }
56
58 {
59 $this->question_container_id = $question_container_id;
60 }
61
62 public function executeCommand(): void
63 {
64 $cmd = $this->ctrl->getCmd('show') . 'Cmd';
65
66 $this->$cmd();
67 }
68
70 {
71 $this->question_assignment_columns_enabled = $question_assignment_columns_enabled;
72 }
73
78 {
80 }
81
85 public function getTestId(): int
86 {
87 return $this->test_id;
88 }
89
90 private function saveSkillThresholdsCmd(): void
91 {
92 if ($this->request_data_collector->isPostRequest()) {
93 $assignment_list = $this->buildSkillQuestionAssignmentList();
94 $assignment_list->loadFromDb();
95
96 $valid = true;
97
98 $table = $this->getPopulatedTable();
99 $elements = $table->getInputElements($this->request_data_collector->retrieveArrayOfStringsFromPost('rendered'));
100 foreach ($elements as $elm) {
101 if (!$elm->checkInput()
102 || floor($elm->getInput()) !== $elm->getInput()) {
103 $valid = false;
104 $elm->setValue('');
105 continue;
106 }
107
108 $elm->setValue($this->request_data_collector->strVal($elm->getPostVar()));
109 }
110
111 if (!$valid) {
112 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
113 $this->showSkillThresholdsCmd($table);
114 return;
115 }
116
117 $threshold = [];
118 foreach ($elements as $elm) {
119 $key = $elm->getPostVar();
120 $matches = null;
121 if (preg_match('/^threshold_(\d+?):(\d+?)_(\d+?)$/', $key, $matches) && is_array($matches)) {
122 $value = $this->request_data_collector->int($key);
123 $threshold[$matches[1] . ':' . $matches[2]][$matches[3]] = $value;
124 }
125 }
126
128 $skill_level_thresholds = [];
129
130 foreach ($assignment_list->getUniqueAssignedSkills() as $data) {
131 $skill = $data['skill'];
132 $skillKey = $data['skill_base_id'] . ':' . $data['skill_tref_id'];
133 $levels = $skill->getLevelData();
134
135 $thresholds_by_level = [];
136
137 foreach ($levels as $level) {
138 if (isset($threshold[$skillKey][$level['id']])) {
139 $skill_level_threshold = new ilTestSkillLevelThreshold($this->db);
140
141 $skill_level_threshold->setTestId($this->getTestId());
142 $skill_level_threshold->setSkillBaseId($data['skill_base_id']);
143 $skill_level_threshold->setSkillTrefId($data['skill_tref_id']);
144 $skill_level_threshold->setSkillLevelId($level['id']);
145
146 $skill_level_threshold->setThreshold($threshold[$skillKey][$level['id']]);
147 $skill_level_thresholds[] = $skill_level_threshold;
148 $thresholds_by_level[] = $threshold[$skillKey][$level['id']];
149 }
150 }
151
152 $sorted_thresholds_by_level = $thresholds_by_level = array_values($thresholds_by_level);
153 sort($sorted_thresholds_by_level);
154 if (
155 $sorted_thresholds_by_level != $thresholds_by_level ||
156 count($thresholds_by_level) != count(array_unique($thresholds_by_level))
157 ) {
158 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('ass_competence_respect_level_ordering'));
159 $this->showSkillThresholdsCmd($table);
160 return;
161 }
162 }
163
164 foreach ($skill_level_thresholds as $skill_level_threshold) {
165 $skill_level_threshold->saveToDb();
166 }
167
168 $this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_msg_skl_lvl_thresholds_saved'), true);
169 }
170
171 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_THRESHOLDS);
172 }
173
174 private function showSkillThresholdsCmd(?ilTestSkillLevelThresholdsTableGUI $table = null): void
175 {
176 if (null === $table) {
177 $table = $this->getPopulatedTable();
178 }
179
180 $this->tpl->setContent($this->ctrl->getHTML($table));
181 }
182
184 {
185 $table = $this->buildTableGUI();
186
187 $skill_level_threshold_list = $this->buildSkillLevelThresholdList();
188 $skill_level_threshold_list->loadFromDb();
189 $table->setSkillLevelThresholdList($skill_level_threshold_list);
190
191 $assignment_list = $this->buildSkillQuestionAssignmentList();
192 $assignment_list->loadFromDb();
193
194 $table->setData($table->completeCompetenceTitles(
195 $assignment_list->getUniqueAssignedSkills()
196 ));
197 return $table;
198 }
199
201 {
203 $this,
204 $this->getTestId(),
205 self::CMD_SHOW_SKILL_THRESHOLDS,
206 $this->ctrl,
207 $this->lng
208 );
209 $table->setQuestionAssignmentColumnsEnabled($this->areQuestionAssignmentColumnsEnabled());
210 $table->initColumns();
211
212 return $table;
213 }
214
216 {
217 $assignment_list = new ilAssQuestionSkillAssignmentList($this->db);
218 $assignment_list->setParentObjId($this->getQuestionContainerId());
219
220 return $assignment_list;
221 }
222
224 {
225 $threshold_list = new ilTestSkillLevelThresholdList($this->db);
226 $threshold_list->setTestId($this->getTestId());
227
228 return $threshold_list;
229 }
230}
language handling
setQuestionAssignmentColumnsEnabled(bool $question_assignment_columns_enabled)
__construct(private readonly ilCtrlInterface $ctrl, private readonly ilGlobalTemplateInterface $tpl, private readonly ilLanguage $lng, private readonly ilDBInterface $db, private readonly RequestDataCollector $request_data_collector, private readonly int $test_id)
showSkillThresholdsCmd(?ilTestSkillLevelThresholdsTableGUI $table=null)
$valid
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31