ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $assignmentList = $this->buildSkillQuestionAssignmentList();
112  $assignmentList->loadFromDb();
113 
114  $valid = true;
115 
116  $table = $this->getPopulatedTable();
117  $renderedElements = [];
118  if (isset($_POST['rendered']) && is_array($_POST['rendered'])) {
119  $renderedElements = $_POST['rendered'];
120  }
121  $elements = $table->getInputElements($renderedElements);
122  foreach ($elements as $elm) {
123  if (!$elm->checkInput()) {
124  $valid = false;
125  }
126 
127  $elm->setValueByArray($_POST);
128  }
129 
130  if (!$valid) {
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  $matches = null;
138  if (preg_match('/^threshold_(\d+?):(\d+?)_(\d+?)$/', $key, $matches) && is_array($matches)) {
139  $threshold[$matches[1] . ':' . $matches[2]][$matches[3]] = $value;
140  }
141  }
142 
144  $skillLevelThresholds = array();
145 
146  foreach ($assignmentList->getUniqueAssignedSkills() as $data) {
147  $skill = $data['skill'];
148  $skillKey = $data['skill_base_id'] . ':' . $data['skill_tref_id'];
149  $levels = $skill->getLevelData();
150 
151  $thresholds_by_level = array();
152 
153  foreach ($levels as $level) {
154  if (isset($threshold[$skillKey]) && isset($threshold[$skillKey][$level['id']])) {
155  $skillLevelThreshold = new ilTestSkillLevelThreshold($this->db);
156 
157  $skillLevelThreshold->setTestId($this->getTestId());
158  $skillLevelThreshold->setSkillBaseId($data['skill_base_id']);
159  $skillLevelThreshold->setSkillTrefId($data['skill_tref_id']);
160  $skillLevelThreshold->setSkillLevelId($level['id']);
161 
162  $skillLevelThreshold->setThreshold($threshold[$skillKey][$level['id']]);
163  $skillLevelThresholds[] = $skillLevelThreshold;
164  $thresholds_by_level[] = $threshold[$skillKey][$level['id']];
165  }
166  }
167 
168  $sorted_thresholds_by_level = $thresholds_by_level = array_values($thresholds_by_level);
169  sort($sorted_thresholds_by_level);
170  if (
171  $sorted_thresholds_by_level != $thresholds_by_level ||
172  count($thresholds_by_level) != count(array_unique($thresholds_by_level))
173  ) {
174  ilUtil::sendFailure($this->lng->txt('ass_competence_respect_level_ordering'));
175  return $this->showSkillThresholdsCmd($table);
176  }
177  }
178 
179  foreach ($skillLevelThresholds as $skillLevelThreshold) {
180  $skillLevelThreshold->saveToDb();
181  }
182 
183  ilUtil::sendSuccess($this->lng->txt('tst_msg_skl_lvl_thresholds_saved'), true);
184  }
185 
186  $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_THRESHOLDS);
187  }
188 
193  {
194  if (null === $table) {
195  $table = $this->getPopulatedTable();
196  }
197 
198  $this->tpl->setContent($this->ctrl->getHTML($table));
199  }
200 
204  protected function getPopulatedTable()
205  {
206  $table = $this->buildTableGUI();
207 
208  $skillLevelThresholdList = $this->buildSkillLevelThresholdList();
209  $skillLevelThresholdList->loadFromDb();
210  $table->setSkillLevelThresholdList($skillLevelThresholdList);
211 
212  $assignmentList = $this->buildSkillQuestionAssignmentList();
213  $assignmentList->loadFromDb();
214 
215  $table->setData($table->completeCompetenceTitles(
216  $assignmentList->getUniqueAssignedSkills()
217  ));
218  return $table;
219  }
220 
221  private function buildTableGUI()
222  {
223  require_once 'Modules/Test/classes/tables/class.ilTestSkillLevelThresholdsTableGUI.php';
225  $this,
226  $this->getTestId(),
227  self::CMD_SHOW_SKILL_THRESHOLDS,
228  $this->ctrl,
229  $this->lng
230  );
231  $table->setQuestionAssignmentColumnsEnabled($this->areQuestionAssignmentColumnsEnabled());
232  $table->initColumns();
233 
234  return $table;
235  }
236 
238  {
239  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
240  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
241  $assignmentList->setParentObjId($this->getQuestionContainerId());
242 
243  return $assignmentList;
244  }
245 
246  private function buildSkillLevelThresholdList()
247  {
248  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
249  $thresholdList = new ilTestSkillLevelThresholdList($this->db);
250  $thresholdList->setTestId($this->getTestId());
251 
252  return $thresholdList;
253  }
254 }
This class provides processing control methods.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$valid
showSkillThresholdsCmd(ilTestSkillLevelThresholdsTableGUI $table=null)
special template class to simplify handling of ITX/PEAR
setQuestionAssignmentColumnsEnabled($questionAssignmentColumnsEnabled)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct(ilCtrl $ctrl, ilTemplate $tpl, ilLanguage $lng, ilDBInterface $db, $testId)
language handling
if(empty($password)) $table
Definition: pwgen.php:24
$key
Definition: croninfo.php:18
$_POST["username"]
$data
Definition: bench.php:6