ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->setSkillTitle(
281 );
282
283 $tree = new ilSkillTree();
284
285 $path = $tree->getSkillTreePath(
286 $this->getSkillBaseId(),
287 $this->getSkillTrefId()
288 );
289
290 $nodes = array();
291 foreach ($path as $node) {
292 if ($node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId()) {
293 $nodes[] = $node['title'];
294 }
295 }
296
297 $this->setSkillPath(implode(' > ', $nodes));
298 }
299
300 public function setSkillTitle($skillTitle)
301 {
302 $this->skillTitle = $skillTitle;
303 }
304
305 public function getSkillTitle()
306 {
307 return $this->skillTitle;
308 }
309
310 public function setSkillPath($skillPath)
311 {
312 $this->skillPath = $skillPath;
313 }
314
315 public function getSkillPath()
316 {
317 return $this->skillPath;
318 }
319
320 public function getEvalMode()
321 {
322 return $this->evalMode;
323 }
324
325 public function setEvalMode($evalMode)
326 {
327 $this->evalMode = $evalMode;
328 }
329
330 public function hasEvalModeBySolution()
331 {
333 }
334
336 {
337 $this->solutionComparisonExpressionList->setQuestionId($this->getQuestionId());
338 $this->solutionComparisonExpressionList->setSkillBaseId($this->getSkillBaseId());
339 $this->solutionComparisonExpressionList->setSkillTrefId($this->getSkillTrefId());
340 }
341
343 {
345 }
346
347 public function getMaxSkillPoints()
348 {
349 if ($this->hasEvalModeBySolution()) {
350 $maxPoints = 0;
351
352 foreach ($this->solutionComparisonExpressionList->get() as $expression) {
353 if ($expression->getPoints() > $maxPoints) {
354 $maxPoints = $expression->getPoints();
355 }
356 }
357
358 return $maxPoints;
359 }
360
361 return $this->getSkillPoints();
362 }
363
369 {
370 return (
371 is_numeric($skillPoints) &&
372 str_replace(array('.', ','), '', $skillPoints) == $skillPoints &&
373 $skillPoints > 0
374 );
375 }
376}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
foreach($_POST as $key=> $value) $res