ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestSkillLevelThresholdsGUI.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 
14 {
15  const CMD_SHOW_SKILL_THRESHOLDS = 'showSkillThresholds';
16  const CMD_SAVE_SKILL_THRESHOLDS = 'saveSkillThresholds';
20  private $ctrl;
21 
25  private $tpl;
26 
30  private $lng;
31 
35  private $db;
36 
40  private $testId;
41 
46 
48 
50  {
51  $this->ctrl = $ctrl;
52  $this->tpl = $tpl;
53  $this->lng = $lng;
54  $this->db = $db;
55  $this->testId = $testId;
56  $this->questionAssignmentColumnsEnabled = false;
57  }
58 
62  public function getQuestionContainerId()
63  {
65  }
66 
71  {
72  $this->questionContainerId = $questionContainerId;
73  }
74 
75  public function executeCommand()
76  {
77  $cmd = $this->ctrl->getCmd('show') . 'Cmd';
78 
79  $this->$cmd();
80  }
81 
86  {
87  $this->questionAssignmentColumnsEnabled = $questionAssignmentColumnsEnabled;
88  }
89 
94  {
96  }
97 
101  public function getTestId()
102  {
103  return $this->testId;
104  }
105 
106  private function saveSkillThresholdsCmd()
107  {
108  require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
109 
110  if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
111  {
112  $assignmentList = $this->buildSkillQuestionAssignmentList();
113  $assignmentList->loadFromDb();
114 
115  $valid = true;
116 
117  $table = $this->getPopulatedTable();
118  $elements = $table->getInputElements();
119  foreach($elements as $elm)
120  {
121  if(!$elm->checkInput())
122  {
123  $valid = false;
124  }
125 
126  $elm->setValueByArray($_POST);
127  }
128 
129  if(!$valid)
130  {
131  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
132  return $this->showSkillThresholdsCmd($table);
133  }
134 
135  $threshold = array();
136  foreach($_POST as $key => $value)
137  {
138  $matches = null;
139  if(preg_match('/^threshold_(\d+?):(\d+?)_(\d+?)$/', $key, $matches) && is_array($matches))
140  {
141  $threshold[$matches[1] . ':' . $matches[2]][$matches[3]] = $value;
142  }
143  }
144 
146  $skillLevelThresholds = array();
147 
148  foreach($assignmentList->getUniqueAssignedSkills() as $data)
149  {
150  $skill = $data['skill'];
151  $skillKey = $data['skill_base_id'] . ':' . $data['skill_tref_id'];
152  $levels = $skill->getLevelData();
153 
154  $thresholds_by_level = array();
155 
156  foreach($levels as $level)
157  {
158  if(isset($threshold[$skillKey]) && isset($threshold[$skillKey][$level['id']]))
159  {
160  $skillLevelThreshold = new ilTestSkillLevelThreshold($this->db);
161 
162  $skillLevelThreshold->setTestId($this->getTestId());
163  $skillLevelThreshold->setSkillBaseId($data['skill_base_id']);
164  $skillLevelThreshold->setSkillTrefId($data['skill_tref_id']);
165  $skillLevelThreshold->setSkillLevelId($level['id']);
166 
167  $skillLevelThreshold->setThreshold($threshold[$skillKey][$level['id']]);
168  $skillLevelThresholds[] = $skillLevelThreshold;
169  $thresholds_by_level[] = $threshold[$skillKey][$level['id']];
170  }
171  }
172 
173  $sorted_thresholds_by_level = $thresholds_by_level = array_values($thresholds_by_level);
174  sort($sorted_thresholds_by_level);
175  if(
176  $sorted_thresholds_by_level != $thresholds_by_level ||
177  count($thresholds_by_level) != count(array_unique($thresholds_by_level))
178  )
179  {
180  ilUtil::sendFailure($this->lng->txt('ass_competence_respect_level_ordering'));
181  return $this->showSkillThresholdsCmd($table);
182  }
183  }
184 
185  foreach($skillLevelThresholds as $skillLevelThreshold)
186  {
187  $skillLevelThreshold->saveToDb();
188  }
189 
190  ilUtil::sendSuccess($this->lng->txt('tst_msg_skl_lvl_thresholds_saved'), true);
191  }
192 
193  $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_THRESHOLDS);
194  }
195 
200  {
201  if(null === $table)
202  {
203  $table = $this->getPopulatedTable();
204  }
205 
206  $this->tpl->setContent($this->ctrl->getHTML($table));
207  }
208 
212  protected function getPopulatedTable()
213  {
214  $table = $this->buildTableGUI();
215 
216  $skillLevelThresholdList = $this->buildSkillLevelThresholdList();
217  $skillLevelThresholdList->loadFromDb();
218  $table->setSkillLevelThresholdList($skillLevelThresholdList);
219 
220  $assignmentList = $this->buildSkillQuestionAssignmentList();
221  $assignmentList->loadFromDb();
222 
223  $table->setData($table->completeCompetenceTitles(
224  $assignmentList->getUniqueAssignedSkills()
225  ));
226  return $table;
227  }
228 
229  private function buildTableGUI()
230  {
231  require_once 'Modules/Test/classes/tables/class.ilTestSkillLevelThresholdsTableGUI.php';
232  $table = new ilTestSkillLevelThresholdsTableGUI($this, self::CMD_SHOW_SKILL_THRESHOLDS, $this->ctrl, $this->lng);
233  $table->setQuestionAssignmentColumnsEnabled( $this->areQuestionAssignmentColumnsEnabled() );
234  $table->initColumns();
235 
236  return $table;
237  }
238 
240  {
241  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
242  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
243  $assignmentList->setParentObjId($this->getQuestionContainerId());
244 
245  return $assignmentList;
246  }
247 
248  private function buildSkillLevelThresholdList()
249  {
250  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
251  $thresholdList = new ilTestSkillLevelThresholdList($this->db);
252  $thresholdList->setTestId($this->getTestId());
253 
254  return $thresholdList;
255  }
256 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class provides processing control methods.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$valid
$cmd
Definition: sahs_server.php:35
Interface ilDBInterface.
showSkillThresholdsCmd(ilTestSkillLevelThresholdsTableGUI $table=null)
special template class to simplify handling of ITX/PEAR
setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct(ilCtrl $ctrl, ilTemplate $tpl, ilLanguage $lng, ilDBInterface $db, $testId)
language handling
$_POST["username"]