ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestSkillLevelThresholdsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
6 
14 {
16 
18 
22  protected $input_elements_by_id = array();
23 
25  {
26  $this->skillLevelThresholdList = $skillLevelThresholdList;
27  }
28 
29  public function getSkillLevelThresholdList()
30  {
32  }
33 
35  {
37  }
38 
40  {
41  $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
42  }
43 
44  public function __construct($parentOBJ, $testId, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
45  {
46  $this->setId('tst_skl_lev_thr_' . $testId);
47  parent::__construct($parentOBJ, $parentCmd);
48 
49  $this->lng = $lng;
50  $this->ctrl = $ctrl;
51 
52  $this->lng->loadLanguageModule('form');
53 
54  $this->setStyle('table', 'fullwidth');
55 
56  $this->setRowTemplate("tpl.tst_skl_thresholds_row.html", "Modules/Test");
57 
58  $this->enable('header');
59  #$this->disable('sort');
60  $this->disable('select_all');
61 
62  $this->setDefaultOrderField('competence');
63  $this->setDefaultOrderDirection('asc');
64  $this->setShowRowsSelector(true);
65 
66  $this->setFormAction($ctrl->getFormAction($parentOBJ));
67 
68  $this->addCommandButton(
70  $this->lng->txt('tst_save_thresholds')
71  );
72  }
73 
74  public function initColumns()
75  {
76  $this->addColumn($this->lng->txt('tst_competence'), 'competence', '50%');
77 
79  $this->addColumn($this->lng->txt('tst_num_questions'), '', '10%');
80  $this->addColumn($this->lng->txt('tst_max_comp_points'), '', '10%');
81  }
82 
83  $this->addColumn($this->lng->txt('tst_level'), '', '10%');
84  $this->addColumn($this->lng->txt('tst_threshold'), '', '10%');
85  }
86 
87  public function fillRow($data)
88  {
89  $skill = $data['skill'];
90  $levels = $skill->getLevelData();
91 
93  $this->tpl->setCurrentBlock('quest_assign_info');
94  $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
95  $this->tpl->setVariable('NUM_QUESTIONS', $data['num_assigns']);
96  $this->tpl->setVariable('MAX_COMP_POINTS', $data['max_points']);
97  $this->tpl->parseCurrentBlock();
98  }
99 
100  $this->tpl->setCurrentBlock('competence');
101  $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
102  $this->tpl->setVariable('COMPETENCE', $data['competence']);
103  $this->tpl->parseCurrentBlock();
104 
105  $this->addHiddenInput('rendered[]', $this->buildUniqueRecordIdentifier($data));
106 
107  $this->tpl->setCurrentBlock('tbl_content');
108 
109  for ($i = 0, $max = count($levels); $i < $max; $i++) {
110  $level = $levels[$i];
111 
112  $this->tpl->setVariable('LEVEL', $level['title']);
113 
114  $this->tpl->setVariable('THRESHOLD', $this->buildThresholdInput(
115  $data['skill_base_id'],
116  $data['skill_tref_id'],
117  $level['id']
118  )->render());
119 
120  if ($i < ($max - 1)) {
121  $this->tpl->parseCurrentBlock();
122  $this->tpl->setVariable("CSS_ROW", $this->css_row);
123  $this->tpl->setVariable("CSS_NO_BORDER", 'ilBorderlessRow');
124  }
125  }
126  }
127 
132  private function buildUniqueRecordIdentifier(array $row) : string
133  {
134  return 'threshold_' . $row['skill_base_id'] . ':' . $row['skill_tref_id'];
135  }
136 
137  private function getRowspan($numLevels)
138  {
139  if ($numLevels == 0) {
140  return 1;
141  }
142 
143  return $numLevels;
144  }
145 
150  public function getInputElements(array $idFilter) : array
151  {
152  $elements = array();
153 
154  foreach ($this->getData() as $data) {
155  $id = $this->buildUniqueRecordIdentifier($data);
156  if (!in_array($id, $idFilter)) {
157  continue;
158  }
159 
160  $skill = $data['skill'];
161  $levels = $skill->getLevelData();
162  for ($i = 0, $max = count($levels); $i < $max; $i++) {
163  $level = $levels[$i];
164 
165  $elements[] = $this->buildThresholdInput(
166  $data['skill_base_id'],
167  $data['skill_tref_id'],
168  $level['id']
169  );
170  }
171  }
172 
173  return $elements;
174  }
175 
182  private function buildThresholdInput($skillBaseId, $skillTrefId, $skillLevelId)
183  {
184  $skillKey = $skillBaseId . ':' . $skillTrefId;
185 
186  if (isset($this->input_elements_by_id[$skillKey][$skillLevelId])) {
187  return $this->input_elements_by_id[$skillKey][$skillLevelId];
188  }
189 
190  $threshold = $this->skillLevelThresholdList->getThreshold($skillBaseId, $skillTrefId, $skillLevelId);
191  if ($threshold instanceof ilTestSkillLevelThreshold) {
192  $thresholdValue = $threshold->getThreshold();
193  } else {
194  $thresholdValue = '';
195  }
196 
197  $value = new ilNumberInputGUI('', 'threshold_' . $skillKey . '_' . $skillLevelId);
198  $value->setValue($thresholdValue);
199  $value->setSize(5);
200  $value->setMinValue(0);
201  $value->setMaxValue(100);
202 
203  if (!isset($this->input_elements_by_id[$skillKey])) {
204  $this->input_elements_by_id[$skillKey] = array();
205  }
206 
207  $this->input_elements_by_id[$skillKey][$skillLevelId] = $value;
208 
209  return $value;
210  }
211 
213  {
214  foreach ($rows as $key => $row) {
215  $rows[$key]['competence'] = ilBasicSkill::_lookupTitle(
216  $row['skill']->getId(),
217  $row['skill_tref_id']
218  );
219  }
220 
221  return $rows;
222  }
223 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
This class provides processing control methods.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
buildThresholdInput($skillBaseId, $skillTrefId, $skillLevelId)
addHiddenInput($a_name, $a_value)
Add Hidden Input field.
__construct($parentOBJ, $testId, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
setStyle($a_element, $a_style)
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
This class represents a number property in a property form.
enable($a_module_name)
enables particular modules of table
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$rows
Definition: xhr_table.php:10
render()
render table public
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
setSkillLevelThresholdList(ilTestSkillLevelThresholdList $skillLevelThresholdList)
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getId()
Get element id.
$i
Definition: metadata.php:24