ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 $testOBJ;
41 
43  {
44  $this->ctrl = $ctrl;
45  $this->tpl = $tpl;
46  $this->lng = $lng;
47  $this->db = $db;
48  $this->testOBJ = $testOBJ;
49  }
50 
51  public function executeCommand()
52  {
53  $cmd = $this->ctrl->getCmd('show') . 'Cmd';
54 
55  $this->$cmd();
56  }
57 
58  private function saveSkillThresholdsCmd()
59  {
60  require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
61 
62  if( is_array($_POST['threshold']) )
63  {
64  $threshold = $_POST['threshold'];
65  $assignmentList = $this->buildSkillQuestionAssignmentList();
66  $assignmentList->loadFromDb();
67 
68  foreach($assignmentList->getUniqueAssignedSkills() as $data)
69  {
70  $skill = $data['skill'];
71  $skillKey = $data['skill_base_id'].':'.$data['skill_tref_id'];
72  $levels = $skill->getLevelData();
73 
74  foreach($levels as $level)
75  {
76  if( isset($threshold[$skillKey]) && isset($threshold[$skillKey][$level['id']]) )
77  {
78  $skillLevelThreshold = new ilTestSkillLevelThreshold($this->db);
79 
80  $skillLevelThreshold->setTestId($this->testOBJ->getTestId());
81  $skillLevelThreshold->setSkillBaseId($data['skill_base_id']);
82  $skillLevelThreshold->setSkillTrefId($data['skill_tref_id']);
83  $skillLevelThreshold->setSkillLevelId($level['id']);
84 
85  $skillLevelThreshold->setThreshold($threshold[$skillKey][$level['id']]);
86 
87  $skillLevelThreshold->saveToDb();
88  }
89  }
90  }
91  }
92 
93  ilUtil::sendSuccess($this->lng->txt('tst_msg_skl_lvl_thresholds_saved'), true);
94  $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_THRESHOLDS);
95  }
96 
97  private function showSkillThresholdsCmd()
98  {
99  $table = $this->buildTableGUI();
100 
101  $skillLevelThresholdList = $this->buildSkillLevelThresholdList();
102  $skillLevelThresholdList->loadFromDb();
103  $table->setSkillLevelThresholdList($skillLevelThresholdList);
104 
105  $assignmentList = $this->buildSkillQuestionAssignmentList();
106  $assignmentList->loadFromDb();
107 
108  $table->setData($assignmentList->getUniqueAssignedSkills());
109 
110  $this->tpl->setContent($this->ctrl->getHTML($table));
111  }
112 
113  private function buildTableGUI()
114  {
115  require_once 'Modules/Test/classes/tables/class.ilTestSkillLevelThresholdsTableGUI.php';
116  $table = new ilTestSkillLevelThresholdsTableGUI($this, self::CMD_SHOW_SKILL_THRESHOLDS, $this->ctrl, $this->lng);
117 
118  return $table;
119  }
120 
122  {
123  require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignmentList.php';
124  $assignmentList = new ilTestSkillQuestionAssignmentList($this->db);
125  $assignmentList->setTestId($this->testOBJ->getTestId());
126 
127  return $assignmentList;
128  }
129 
130  private function buildSkillLevelThresholdList()
131  {
132  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
133  $thresholdList = new ilTestSkillLevelThresholdList($this->db);
134  $thresholdList->setTestId($this->testOBJ->getTestId());
135 
136  return $thresholdList;
137  }
138 }