ILIAS  release_8 Revision v8.24
class.ilTestSkillLevelThresholdsTableGUI.php
Go to the documentation of this file.
1<?php
2
26{
28
30
34 protected array $input_elements_by_id = array();
35
37 {
38 $this->skillLevelThresholdList = $skillLevelThresholdList;
39 }
40
42 {
44 }
45
47 {
49 }
50
52 {
53 $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
54 }
55
56 public function __construct($parentOBJ, $testId, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
57 {
58 $this->setId('tst_skl_lev_thr_' . $testId);
59 parent::__construct($parentOBJ, $parentCmd);
60
61 $this->lng = $lng;
62 $this->ctrl = $ctrl;
63
64 $this->lng->loadLanguageModule('form');
65
66 $this->setStyle('table', 'fullwidth');
67
68 $this->setRowTemplate("tpl.tst_skl_thresholds_row.html", "Modules/Test");
69
70 $this->enable('header');
71 #$this->disable('sort');
72 $this->disable('select_all');
73
74 $this->setDefaultOrderField('competence');
75 $this->setDefaultOrderDirection('asc');
76 $this->setShowRowsSelector(true);
77
78 $this->setFormAction($ctrl->getFormAction($parentOBJ));
79
80 $this->addCommandButton(
82 $this->lng->txt('tst_save_thresholds')
83 );
84 }
85
86 public function initColumns(): void
87 {
88 $this->addColumn($this->lng->txt('tst_competence'), 'competence', '50%');
89
91 $this->addColumn($this->lng->txt('tst_num_questions'), '', '10%');
92 $this->addColumn($this->lng->txt('tst_max_comp_points'), '', '10%');
93 }
94
95 $this->addColumn($this->lng->txt('tst_level'), '', '10%');
96 $this->addColumn($this->lng->txt('tst_threshold'), '', '10%');
97 }
98
99 public function fillRow(array $a_set): void
100 {
101 $skill = $a_set['skill'];
102 $levels = $skill->getLevelData();
103
105 $this->tpl->setCurrentBlock('quest_assign_info');
106 $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
107 $this->tpl->setVariable('NUM_QUESTIONS', $a_set['num_assigns']);
108 $this->tpl->setVariable('MAX_COMP_POINTS', $a_set['max_points']);
109 $this->tpl->parseCurrentBlock();
110 }
111
112 $this->tpl->setCurrentBlock('competence');
113 $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
114 $this->tpl->setVariable('COMPETENCE', $a_set['competence']);
115 $this->tpl->parseCurrentBlock();
116
117 $this->addHiddenInput('rendered[]', $this->buildUniqueRecordIdentifier($a_set));
118
119 $this->tpl->setCurrentBlock('tbl_content');
120
121 for ($i = 0, $max = count($levels); $i < $max; $i++) {
122 $level = $levels[$i];
123
124 $this->tpl->setVariable('LEVEL', $level['title']);
125
126 $this->tpl->setVariable('THRESHOLD', $this->buildThresholdInput(
127 $a_set['skill_base_id'],
128 $a_set['skill_tref_id'],
129 $level['id']
130 )->render());
131
132 if ($i < ($max - 1)) {
133 $this->tpl->parseCurrentBlock();
134 $this->tpl->setVariable("CSS_ROW", $this->css_row);
135 $this->tpl->setVariable("CSS_NO_BORDER", 'ilBorderlessRow');
136 }
137 }
138 }
139
140 private function buildUniqueRecordIdentifier(array $row): string
141 {
142 return 'threshold_' . $row['skill_base_id'] . ':' . $row['skill_tref_id'];
143 }
144
145 private function getRowspan($numLevels): int
146 {
147 if ($numLevels == 0) {
148 return 1;
149 }
150
151 return $numLevels;
152 }
153
157 public function getInputElements(array $idFilter): array
158 {
159 $elements = array();
160
161 foreach ($this->getData() as $data) {
162 $id = $this->buildUniqueRecordIdentifier($data);
163 if (!in_array($id, $idFilter)) {
164 continue;
165 }
166
167 $skill = $data['skill'];
168 $levels = $skill->getLevelData();
169 for ($i = 0, $max = count($levels); $i < $max; $i++) {
170 $level = $levels[$i];
171
172 $elements[] = $this->buildThresholdInput(
173 $data['skill_base_id'],
174 $data['skill_tref_id'],
175 $level['id']
176 );
177 }
178 }
179
180 return $elements;
181 }
182
183 private function buildThresholdInput($skillBaseId, $skillTrefId, $skillLevelId): ilNumberInputGUI
184 {
185 $skillKey = $skillBaseId . ':' . $skillTrefId;
186
187 if (isset($this->input_elements_by_id[$skillKey][$skillLevelId])) {
188 return $this->input_elements_by_id[$skillKey][$skillLevelId];
189 }
190
191 $threshold = $this->skillLevelThresholdList->getThreshold($skillBaseId, $skillTrefId, $skillLevelId);
192 if ($threshold instanceof ilTestSkillLevelThreshold) {
193 $thresholdValue = $threshold->getThreshold();
194 } else {
195 $thresholdValue = '';
196 }
197
198 $value = new ilNumberInputGUI('', 'threshold_' . $skillKey . '_' . $skillLevelId);
199 $value->setValue($thresholdValue);
200 $value->setSize(5);
201 $value->setMinValue(0);
202 $value->setMaxValue(100);
203
204 if (!isset($this->input_elements_by_id[$skillKey])) {
205 $this->input_elements_by_id[$skillKey] = array();
206 }
207
208 $this->input_elements_by_id[$skillKey][$skillLevelId] = $value;
209
210 return $value;
211 }
212
213 public function completeCompetenceTitles(array $rows): array
214 {
215 foreach ($rows as $key => $row) {
216 $rows[$key]['competence'] = ilBasicSkill::_lookupTitle(
217 $row['skill']->getId(),
218 $row['skill_tref_id']
219 );
220 }
221
222 return $rows;
223 }
224}
Class ilCtrl provides processing control methods.
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
language handling
This class represents a number property in a property form.
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addHiddenInput(string $a_name, string $a_value)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
ilLanguage $lng
enable(string $a_module_name)
setStyle(string $a_element, string $a_style)
disable(string $a_module_name)
setQuestionAssignmentColumnsEnabled(bool $questionAssignmentColumnsEnabled)
buildThresholdInput($skillBaseId, $skillTrefId, $skillLevelId)
setSkillLevelThresholdList(ilTestSkillLevelThresholdList $skillLevelThresholdList)
fillRow(array $a_set)
Standard Version of Fill Row.
__construct($parentOBJ, $testId, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$rows
Definition: xhr_table.php:10