ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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/Skill/classes/class.ilBasicSkill.php';
6 require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
7 
15 {
17 
19 
24 
26  {
27  $this->skillLevelThresholdList = $skillLevelThresholdList;
28  }
29 
30  public function getSkillLevelThresholdList()
31  {
33  }
34 
36  {
38  }
39 
41  {
42  $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
43  }
44 
45  public function __construct($parentOBJ, $testId, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
46  {
47  $this->setId('tst_skl_lev_thr_' . $testId);
48  parent::__construct($parentOBJ, $parentCmd);
49 
50  $this->lng = $lng;
51  $this->ctrl = $ctrl;
52 
53  $this->lng->loadLanguageModule('form');
54 
55  $this->setStyle('table', 'fullwidth');
56 
57  $this->setRowTemplate("tpl.tst_skl_thresholds_row.html", "Modules/Test");
58 
59  $this->enable('header');
60  #$this->disable('sort');
61  $this->disable('select_all');
62 
63  $this->setDefaultOrderField('competence');
64  $this->setDefaultOrderDirection('asc');
65  $this->setShowRowsSelector(true);
66 
67  $this->setFormAction($ctrl->getFormAction($parentOBJ));
68 
69  $this->addCommandButton(
71  $this->lng->txt('tst_save_thresholds')
72  );
73  }
74 
75  public function initColumns()
76  {
77  $this->addColumn($this->lng->txt('tst_competence'), 'competence', '50%');
78 
80  $this->addColumn($this->lng->txt('tst_num_questions'), '', '10%');
81  $this->addColumn($this->lng->txt('tst_max_comp_points'), '', '10%');
82  }
83 
84  $this->addColumn($this->lng->txt('tst_level'), '', '10%');
85  $this->addColumn($this->lng->txt('tst_threshold'), '', '10%');
86  }
87 
88  public function fillRow($data)
89  {
90  $skill = $data['skill'];
91  $levels = $skill->getLevelData();
92 
94  $this->tpl->setCurrentBlock('quest_assign_info');
95  $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
96  $this->tpl->setVariable('NUM_QUESTIONS', $data['num_assigns']);
97  $this->tpl->setVariable('MAX_COMP_POINTS', $data['max_points']);
98  $this->tpl->parseCurrentBlock();
99  }
100 
101  $this->tpl->setCurrentBlock('competence');
102  $this->tpl->setVariable('ROWSPAN', $this->getRowspan(count($levels)));
103  $this->tpl->setVariable('COMPETENCE', $data['competence']);
104  $this->tpl->parseCurrentBlock();
105 
106  $this->addHiddenInput('rendered[]', $this->buildUniqueRecordIdentifier($data));
107 
108  $this->tpl->setCurrentBlock('tbl_content');
109 
110  for ($i = 0, $max = count($levels); $i < $max; $i++) {
111  $level = $levels[$i];
112 
113  $this->tpl->setVariable('LEVEL', $level['title']);
114 
115  $this->tpl->setVariable('THRESHOLD', $this->buildThresholdInput(
116  $data['skill_base_id'],
117  $data['skill_tref_id'],
118  $level['id']
119  )->render());
120 
121  if ($i < ($max - 1)) {
122  $this->tpl->parseCurrentBlock();
123  $this->tpl->setVariable("CSS_ROW", $this->css_row);
124  $this->tpl->setVariable("CSS_NO_BORDER", 'ilBorderlessRow');
125  }
126  }
127  }
128 
134  {
135  return 'threshold_' . $row['skill_base_id'] . ':' . $row['skill_tref_id'];
136  }
137 
138  private function getRowspan($numLevels)
139  {
140  if ($numLevels == 0) {
141  return 1;
142  }
143 
144  return $numLevels;
145  }
146 
151  public function getInputElements(array $idFilter) : array
152  {
153  $elements = array();
154 
155  foreach ($this->getData() as $data) {
156  $id = $this->buildUniqueRecordIdentifier($data);
157  if (!in_array($id, $idFilter)) {
158  continue;
159  }
160 
161  $skill = $data['skill'];
162  $levels = $skill->getLevelData();
163  for ($i = 0, $max = count($levels); $i < $max; $i++) {
164  $level = $levels[$i];
165 
166  $elements[] = $this->buildThresholdInput(
167  $data['skill_base_id'],
168  $data['skill_tref_id'],
169  $level['id']
170  );
171  }
172  }
173 
174  return $elements;
175  }
176 
183  private function buildThresholdInput($skillBaseId, $skillTrefId, $skillLevelId)
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 
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)
if(!array_key_exists('StateId', $_REQUEST)) $id
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
Class ilTable2GUI.
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.
Create styles array
The data for the language used.
$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)
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.
$i
Definition: disco.tpl.php:19
language handling
getId()
Get element id.
$key
Definition: croninfo.php:18
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class object.