ILIAS  release_8 Revision v8.24
class.ilAssQuestionSkillAssignment.php
Go to the documentation of this file.
1<?php
2
20
28{
29 public const DEFAULT_COMPETENCE_POINTS = 1;
30
31 public const EVAL_MODE_BY_QUESTION_RESULT = 'result';
32 public const EVAL_MODE_BY_QUESTION_SOLUTION = 'solution';
33
34
38 private $db;
39
43 private $parentObjId;
44
48 private $questionId;
49
53 private $skillBaseId;
54
58 private $skillTrefId;
59
63 private $skillPoints;
64
68 private $skillTitle;
69
73 private $skillPath;
74
78 private $evalMode;
79
84
86
87 public function __construct(ilDBInterface $db)
88 {
89 global $DIC;
90
91 $this->db = $db;
92
93 $this->solutionComparisonExpressionList = new ilAssQuestionSolutionComparisonExpressionList($this->db);
94 $this->skill_tree_service = $DIC->skills()->tree();
95 }
96
97 public function loadFromDb(): void
98 {
99 $query = "
100 SELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode
101 FROM qpl_qst_skl_assigns
102 WHERE obj_fi = %s
103 AND question_fi = %s
104 AND skill_base_fi = %s
105 AND skill_tref_fi = %s
106 ";
107
108 $res = $this->db->queryF(
109 $query,
110 array('integer', 'integer', 'integer', 'integer'),
111 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
112 );
113
114 $row = $this->db->fetchAssoc($res);
115
116 if (is_array($row)) {
117 $this->setSkillPoints($row['skill_points']);
118 $this->setEvalMode($row['eval_mode']);
119 }
120
121 if ($this->getEvalMode() == self::EVAL_MODE_BY_QUESTION_SOLUTION) {
123 }
124 }
125
126 public function loadComparisonExpressions(): void
127 {
129 $this->solutionComparisonExpressionList->load();
130 }
131
132 public function saveToDb(): void
133 {
134 if ($this->dbRecordExists()) {
135 $this->db->update(
136 'qpl_qst_skl_assigns',
137 array(
138 'skill_points' => array('integer', $this->getSkillPoints()),
139 'eval_mode' => array('text', $this->getEvalMode())
140 ),
141 array(
142 'obj_fi' => array('integer', $this->getParentObjId()),
143 'question_fi' => array('integer', $this->getQuestionId()),
144 'skill_base_fi' => array('integer', $this->getSkillBaseId()),
145 'skill_tref_fi' => array('integer', $this->getSkillTrefId())
146 )
147 );
148 } else {
149 $this->db->insert('qpl_qst_skl_assigns', array(
150 'obj_fi' => array('integer', $this->getParentObjId()),
151 'question_fi' => array('integer', $this->getQuestionId()),
152 'skill_base_fi' => array('integer', $this->getSkillBaseId()),
153 'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
154 'skill_points' => array('integer', $this->getSkillPoints()),
155 'eval_mode' => array('text', $this->getEvalMode())
156 ));
157 }
158
159 if ($this->getEvalMode() == self::EVAL_MODE_BY_QUESTION_SOLUTION) {
161 }
162 }
163
164 public function saveComparisonExpressions(): void
165 {
167 $this->solutionComparisonExpressionList->save();
168 }
169
170 public function deleteFromDb(): void
171 {
172 $query = "
173 DELETE FROM qpl_qst_skl_assigns
174 WHERE obj_fi = %s
175 AND question_fi = %s
176 AND skill_base_fi = %s
177 AND skill_tref_fi = %s
178 ";
179
180 $this->db->manipulateF(
181 $query,
182 array('integer', 'integer', 'integer', 'integer'),
183 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
184 );
185
187 }
188
189 public function deleteComparisonExpressions(): void
190 {
192 $this->solutionComparisonExpressionList->delete();
193 }
194
195 public function dbRecordExists(): bool
196 {
197 $query = "
198 SELECT COUNT(*) cnt
199 FROM qpl_qst_skl_assigns
200 WHERE obj_fi = %s
201 AND question_fi = %s
202 AND skill_base_fi = %s
203 AND skill_tref_fi = %s
204 ";
205
206 $res = $this->db->queryF(
207 $query,
208 array('integer', 'integer', 'integer', 'integer'),
209 array($this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
210 );
211
212 $row = $this->db->fetchAssoc($res);
213
214 return $row['cnt'] > 0;
215 }
216
217 public function isSkillUsed(): bool
218 {
219 $query = "
220 SELECT COUNT(*) cnt
221 FROM qpl_qst_skl_assigns
222 WHERE obj_fi = %s
223 AND skill_base_fi = %s
224 AND skill_tref_fi = %s
225 ";
226
227 $res = $this->db->queryF(
228 $query,
229 array('integer', 'integer', 'integer'),
230 array($this->getParentObjId(), $this->getSkillBaseId(), $this->getSkillTrefId())
231 );
232
233 $row = $this->db->fetchAssoc($res);
234
235 return $row['cnt'] > 0;
236 }
237
241 public function setSkillPoints($skillPoints): void
242 {
243 $this->skillPoints = $skillPoints;
244 }
245
249 public function getSkillPoints(): int
250 {
251 return $this->skillPoints;
252 }
253
257 public function setQuestionId($questionId): void
258 {
259 $this->questionId = $questionId;
260 }
261
265 public function getQuestionId(): int
266 {
267 return $this->questionId;
268 }
269
273 public function setSkillBaseId($skillBaseId): void
274 {
275 $this->skillBaseId = $skillBaseId;
276 }
277
281 public function getSkillBaseId(): int
282 {
283 return $this->skillBaseId;
284 }
285
289 public function setSkillTrefId($skillTrefId): void
290 {
291 $this->skillTrefId = $skillTrefId;
292 }
293
297 public function getSkillTrefId(): int
298 {
299 return $this->skillTrefId;
300 }
301
305 public function setParentObjId($parentObjId): void
306 {
307 $this->parentObjId = $parentObjId;
308 }
309
313 public function getParentObjId(): int
314 {
315 return $this->parentObjId;
316 }
317
318 public function loadAdditionalSkillData(): void
319 {
320 $this->setSkillTitle(
322 );
323
324 $path = $this->skill_tree_service->getSkillTreePath(
325 $this->getSkillBaseId(),
326 $this->getSkillTrefId()
327 );
328
329 $nodes = array();
330 foreach ($path as $node) {
331 if ($node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId()) {
332 $nodes[] = $node['title'];
333 }
334 }
335
336 $this->setSkillPath(implode(' > ', $nodes));
337 }
338
339 public function setSkillTitle($skillTitle): void
340 {
341 $this->skillTitle = $skillTitle;
342 }
343
344 public function getSkillTitle(): ?string
345 {
346 return $this->skillTitle;
347 }
348
349 public function setSkillPath($skillPath): void
350 {
351 $this->skillPath = $skillPath;
352 }
353
354 public function getSkillPath(): ?string
355 {
356 return $this->skillPath;
357 }
358
359 public function getEvalMode(): string
360 {
361 return $this->evalMode;
362 }
363
364 public function setEvalMode($evalMode): void
365 {
366 $this->evalMode = $evalMode;
367 }
368
369 public function hasEvalModeBySolution(): bool
370 {
372 }
373
375 {
376 $this->solutionComparisonExpressionList->setQuestionId($this->getQuestionId());
377 $this->solutionComparisonExpressionList->setSkillBaseId($this->getSkillBaseId());
378 $this->solutionComparisonExpressionList->setSkillTrefId($this->getSkillTrefId());
379 }
380
382 {
384 }
385
386 public function getMaxSkillPoints(): int
387 {
388 if ($this->hasEvalModeBySolution()) {
389 $maxPoints = 0;
390
391 foreach ($this->solutionComparisonExpressionList->get() as $expression) {
392 if ($expression->getPoints() > $maxPoints) {
393 $maxPoints = $expression->getPoints();
394 }
395 }
396
397 return $maxPoints;
398 }
399
400 return $this->getSkillPoints();
401 }
402
407 public function isValidSkillPoint($skillPoints): bool
408 {
409 return (
410 is_numeric($skillPoints) &&
411 str_replace(array('.', ','), '', $skillPoints) == $skillPoints &&
412 $skillPoints > 0
413 );
414 }
415}
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$query