ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAssQuestionSkillAssignment.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSolutionComparisonExpressionList.php';
5
13{
15
18
19
23 private $db;
24
28 private $parentObjId;
29
33 private $questionId;
34
38 private $skillBaseId;
39
43 private $skillTrefId;
44
48 private $skillPoints;
49
53 private $skillTitle;
54
58 private $skillPath;
59
63 private $evalMode;
64
69
70 public function __construct(ilDBInterface $db)
71 {
72 $this->db = $db;
73
74 $this->solutionComparisonExpressionList = new ilAssQuestionSolutionComparisonExpressionList($this->db);
75 }
76
77 public function loadFromDb()
78 {
79 $query = "
80 SELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode
81 FROM qpl_qst_skl_assigns
82 WHERE obj_fi = %s
83 AND question_fi = %s
84 AND skill_base_fi = %s
85 AND skill_tref_fi = %s
86 ";
87
88 $res = $this->db->queryF(
89 $query,
90 array('integer', 'integer', 'integer', 'integer'),
91 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
92 );
93
94 $row = $this->db->fetchAssoc($res);
95
96 if (is_array($row)) {
97 $this->setSkillPoints($row['skill_points']);
98 $this->setEvalMode($row['eval_mode']);
99 }
100
101 if ($this->getEvalMode() == self::EVAL_MODE_BY_QUESTION_SOLUTION) {
103 }
104 }
105
107 {
109 $this->solutionComparisonExpressionList->load();
110 }
111
112 public function saveToDb()
113 {
114 if ($this->dbRecordExists()) {
115 $this->db->update(
116 'qpl_qst_skl_assigns',
117 array(
118 'skill_points' => array('integer', (int) $this->getSkillPoints()),
119 'eval_mode' => array('text', $this->getEvalMode())
120 ),
121 array(
122 'obj_fi' => array('integer', $this->getParentObjId()),
123 'question_fi' => array('integer', $this->getQuestionId()),
124 'skill_base_fi' => array('integer', $this->getSkillBaseId()),
125 'skill_tref_fi' => array('integer', $this->getSkillTrefId())
126 )
127 );
128 } else {
129 $this->db->insert('qpl_qst_skl_assigns', array(
130 'obj_fi' => array('integer', $this->getParentObjId()),
131 'question_fi' => array('integer', $this->getQuestionId()),
132 'skill_base_fi' => array('integer', $this->getSkillBaseId()),
133 'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
134 'skill_points' => array('integer', (int) $this->getSkillPoints()),
135 'eval_mode' => array('text', $this->getEvalMode())
136 ));
137 }
138
139 if ($this->getEvalMode() == self::EVAL_MODE_BY_QUESTION_SOLUTION) {
141 }
142 }
143
145 {
147 $this->solutionComparisonExpressionList->save();
148 }
149
150 public function deleteFromDb()
151 {
152 $query = "
153 DELETE FROM qpl_qst_skl_assigns
154 WHERE obj_fi = %s
155 AND question_fi = %s
156 AND skill_base_fi = %s
157 AND skill_tref_fi = %s
158 ";
159
160 $this->db->manipulateF(
161 $query,
162 array('integer', 'integer', 'integer', 'integer'),
163 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
164 );
165
167 }
168
170 {
172 $this->solutionComparisonExpressionList->delete();
173 }
174
175 public function dbRecordExists()
176 {
177 $query = "
178 SELECT COUNT(*) cnt
179 FROM qpl_qst_skl_assigns
180 WHERE obj_fi = %s
181 AND question_fi = %s
182 AND skill_base_fi = %s
183 AND skill_tref_fi = %s
184 ";
185
186 $res = $this->db->queryF(
187 $query,
188 array('integer', 'integer', 'integer', 'integer'),
189 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
190 );
191
192 $row = $this->db->fetchAssoc($res);
193
194 return $row['cnt'] > 0;
195 }
196
201 {
202 $this->skillPoints = $skillPoints;
203 }
204
208 public function getSkillPoints()
209 {
210 return $this->skillPoints;
211 }
212
216 public function setQuestionId($questionId)
217 {
218 $this->questionId = $questionId;
219 }
220
224 public function getQuestionId()
225 {
226 return $this->questionId;
227 }
228
233 {
234 $this->skillBaseId = $skillBaseId;
235 }
236
240 public function getSkillBaseId()
241 {
242 return $this->skillBaseId;
243 }
244
249 {
250 $this->skillTrefId = $skillTrefId;
251 }
252
256 public function getSkillTrefId()
257 {
258 return $this->skillTrefId;
259 }
260
265 {
266 $this->parentObjId = $parentObjId;
267 }
268
272 public function getParentObjId()
273 {
274 return $this->parentObjId;
275 }
276
277 public function loadAdditionalSkillData()
278 {
279 require_once 'Services/Skill/classes/class.ilBasicSkill.php';
280 require_once 'Services/Skill/classes/class.ilSkillTree.php';
281
282 $this->setSkillTitle(
284 );
285
286 $tree = new ilSkillTree();
287
288 $path = $tree->getSkillTreePath(
289 $this->getSkillBaseId(),
290 $this->getSkillTrefId()
291 );
292
293 $nodes = array();
294 foreach ($path as $node) {
295 if ($node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId()) {
296 $nodes[] = $node['title'];
297 }
298 }
299
300 $this->setSkillPath(implode(' > ', $nodes));
301 }
302
303 public function setSkillTitle($skillTitle)
304 {
305 $this->skillTitle = $skillTitle;
306 }
307
308 public function getSkillTitle()
309 {
310 return $this->skillTitle;
311 }
312
313 public function setSkillPath($skillPath)
314 {
315 $this->skillPath = $skillPath;
316 }
317
318 public function getSkillPath()
319 {
320 return $this->skillPath;
321 }
322
323 public function getEvalMode()
324 {
325 return $this->evalMode;
326 }
327
328 public function setEvalMode($evalMode)
329 {
330 $this->evalMode = $evalMode;
331 }
332
333 public function hasEvalModeBySolution()
334 {
336 }
337
339 {
340 $this->solutionComparisonExpressionList->setQuestionId($this->getQuestionId());
341 $this->solutionComparisonExpressionList->setSkillBaseId($this->getSkillBaseId());
342 $this->solutionComparisonExpressionList->setSkillTrefId($this->getSkillTrefId());
343 }
344
346 {
348 }
349
350 public function getMaxSkillPoints()
351 {
352 if ($this->hasEvalModeBySolution()) {
353 $maxPoints = 0;
354
355 foreach ($this->solutionComparisonExpressionList->get() as $expression) {
356 if ($expression->getPoints() > $maxPoints) {
357 $maxPoints = $expression->getPoints();
358 }
359 }
360
361 return $maxPoints;
362 }
363
364 return $this->getSkillPoints();
365 }
366
372 {
373 return (
374 is_numeric($skillPoints) &&
375 str_replace(array('.', ','), '', $skillPoints) == $skillPoints &&
376 $skillPoints > 0
377 );
378 }
379}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
Interface ilDBInterface.
$query
foreach($_POST as $key=> $value) $res