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