ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilTestSkillQuestionAssignmentsGUI.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
15{
16 const CMD_SHOW_SKILL_QUEST_ASSIGNS = 'showSkillQuestionAssignments';
17 const CMD_SAVE_SKILL_POINTS = 'saveSkillPoints';
18 const CMD_SHOW_SKILL_SELECT = 'showSkillSelection';
19 const CMD_ADD_SKILL_QUEST_ASSIGN = 'addSkillQuestionAssignment';
20 const CMD_REMOVE_SKILL_QUEST_ASSIGN = 'removeSkillQuestionAssignment';
24 private $ctrl;
25
29 private $tpl;
30
34 private $lng;
35
39 private $db;
40
44 private $testOBJ;
45
47 {
48 $this->ctrl = $ctrl;
49 $this->tpl = $tpl;
50 $this->lng = $lng;
51 $this->db = $db;
52 $this->testOBJ = $testOBJ;
53 }
54
55 public function executeCommand()
56 {
57 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_SKILL_QUEST_ASSIGNS) . 'Cmd';
58
59 $this->$cmd();
60 }
61
63 {
64 $questionId = (int)$_GET['question_id'];
65
66 $skillParameter = explode(':',$_GET['selected_skill']);
67 $skillBaseId = (int)$skillParameter[0];
68 $skillTrefId = (int)$skillParameter[1];
69
70 if( $this->isTestQuestion($questionId) && $skillBaseId )
71 {
72 require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignment.php';
73 $assignment = new ilTestSkillQuestionAssignment($this->db);
74
75 $assignment->setTestId($this->testOBJ->getTestId());
76 $assignment->setQuestionId($questionId);
77 $assignment->setSkillBaseId($skillBaseId);
78 $assignment->setSkillTrefId($skillTrefId);
79
80 if( !$assignment->dbRecordExists() )
81 {
83
84 $assignment->saveToDb();
85 }
86 }
87
88 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
89 }
90
92 {
93 $questionId = (int)$_GET['question_id'];
94 $skillBaseId = (int)$_GET['skill_base_id'];
95 $skillTrefId = (int)$_GET['skill_tref_id'];
96
97 if( $this->isTestQuestion($questionId) && $skillBaseId )
98 {
99 require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignment.php';
100 $assignment = new ilTestSkillQuestionAssignment($this->db);
101
102 $assignment->setTestId($this->testOBJ->getTestId());
103 $assignment->setQuestionId($questionId);
104 $assignment->setSkillBaseId($skillBaseId);
105 $assignment->setSkillTrefId($skillTrefId);
106
107 if( $assignment->dbRecordExists() )
108 {
109 $assignment->deleteFromDb();
110 }
111 }
112
113 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
114 }
115
116 private function showSkillSelectionCmd()
117 {
118 $skillSelectorGUI = $this->buildSkillSelectorGUI();
119
120 if( !$skillSelectorGUI->handleCommand() )
121 {
122 $this->ctrl->saveParameter($this, 'question_id');
123
124 $this->tpl->setContent($this->ctrl->getHTML($skillSelectorGUI));
125 }
126 }
127
128 private function saveSkillPointsCmd()
129 {
130 if( is_array($_POST['quantifiers']) )
131 {
132 require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignment.php';
133
134 $success = false;
135
136 foreach($_POST['quantifiers'] as $assignmentKey => $quantifier)
137 {
138 $assignmentKey = explode(':',$assignmentKey);
139 $skillBaseId = (int)$assignmentKey[0];
140 $skillTrefId = (int)$assignmentKey[1];
141 $questionId = (int)$assignmentKey[2];
142
143 if( $this->isTestQuestion($questionId) && (int)$quantifier > 0 )
144 {
145 $assignment = new ilTestSkillQuestionAssignment($this->db);
146
147 $assignment->setTestId($this->testOBJ->getTestId());
148 $assignment->setQuestionId($questionId);
149 $assignment->setSkillBaseId($skillBaseId);
150 $assignment->setSkillTrefId($skillTrefId);
151
152 if( $assignment->dbRecordExists() )
153 {
154 $assignment->setSkillPoints((int)$quantifier);
155 $assignment->saveToDb();
156 }
157 }
158 }
159 }
160
161 ilUtil::sendSuccess($this->lng->txt('tst_msg_skl_qst_assign_points_saved'), true);
162 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
163 }
164
166 {
167 $table = $this->buildTableGUI();
168
169 $assignmentList = $this->buildSkillQuestionAssignmentList();
170 $assignmentList->loadFromDb();
171 $assignmentList->loadAdditionalSkillData();
172 $table->setSkillQuestionAssignmentList($assignmentList);
173
174 $table->setData($this->testOBJ->getTestQuestions());
175
176 $this->tpl->setContent($this->ctrl->getHTML($table));
177 }
178
179 private function buildTableGUI()
180 {
181 require_once 'Modules/Test/classes/tables/class.ilTestSkillQuestionAssignmentsTableGUI.php';
182 $table = new ilTestSkillQuestionAssignmentsTableGUI($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS, $this->ctrl, $this->lng);
183
184 return $table;
185 }
186
188 {
189 require_once 'Modules/Test/classes/class.ilTestSkillQuestionAssignmentList.php';
190 $assignmentList = new ilTestSkillQuestionAssignmentList($this->db);
191 $assignmentList->setTestId($this->testOBJ->getTestId());
192
193 return $assignmentList;
194 }
195
196 private function buildSkillSelectorGUI()
197 {
198 require_once 'Services/Skill/classes/class.ilSkillSelectorGUI.php';
199
200 $skillSelectorGUI = new ilSkillSelectorGUI(
201 $this, self::CMD_SHOW_SKILL_SELECT, $this, self::CMD_ADD_SKILL_QUEST_ASSIGN
202 );
203
204 return $skillSelectorGUI;
205 }
206
207 private function isTestQuestion($questionId)
208 {
209 foreach($this->testOBJ->getTestQuestions() as $question)
210 {
211 if( $question['question_id'] == $questionId )
212 {
213 return true;
214 }
215 }
216
217 return false;
218 }
219}
$success
Definition: Utf8Test.php:87
$_GET["client_id"]
This class provides processing control methods.
Database Wrapper.
Definition: class.ilDB.php:29
language handling
Explorer class that works on tree objects (Services/Tree)
special template class to simplify handling of ITX/PEAR
__construct(ilCtrl $ctrl, ilTemplate $tpl, ilLanguage $lng, ilDB $db, ilObjTest $testOBJ)
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$_POST['username']
Definition: cron.php:12
$cmd
Definition: sahs_server.php:35