ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilAssQuestionSkillAssignment.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 public const int DEFAULT_COMPETENCE_POINTS = 1;
32
33 public const string EVAL_MODE_BY_QUESTION_RESULT = 'result';
34 public const string EVAL_MODE_BY_QUESTION_SOLUTION = 'solution';
35
37 private int $parent_obj_id;
38 private int $question_id;
39 private int $skill_base_id;
40 private int $skill_tref_id;
42 private string $skill_title = '';
43 private string $skill_path = '';
44 private string $eval_mode = '';
45
48
49 public function __construct(ilDBInterface $db)
50 {
51 global $DIC;
52
53 $this->db = $db;
54
55 $this->solution_comparison_expression_list = new ilAssQuestionSolutionComparisonExpressionList($this->db);
56 $this->skill_tree_service = $DIC->skills()->tree();
57 }
58
59 public function loadFromDb(): void
60 {
61 $query = "
62 SELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode
63 FROM qpl_qst_skl_assigns
64 WHERE obj_fi = %s
65 AND question_fi = %s
66 AND skill_base_fi = %s
67 AND skill_tref_fi = %s
68 ";
69
70 $res = $this->db->queryF(
71 $query,
72 ['integer', 'integer', 'integer', 'integer'],
73 [$this->parent_obj_id, $this->question_id, $this->skill_base_id, $this->skill_tref_id]
74 );
75
76 $row = $this->db->fetchAssoc($res);
77
78 if (is_array($row)) {
79 $this->setSkillPoints($row['skill_points']);
80 $this->setEvalMode($row['eval_mode']);
81 }
82
83 if ($this->getEvalMode() === self::EVAL_MODE_BY_QUESTION_SOLUTION) {
85 }
86 }
87
88 public function loadComparisonExpressions(): void
89 {
91 $this->solution_comparison_expression_list->load();
92 }
93
94 public function saveToDb(): void
95 {
96 if ($this->dbRecordExists()) {
97 $this->db->update(
98 'qpl_qst_skl_assigns',
99 [
100 'skill_points' => ['integer', $this->getSkillPoints()],
101 'eval_mode' => ['text', $this->getEvalMode()]
102 ],
103 [
104 'obj_fi' => ['integer', $this->getParentObjId()],
105 'question_fi' => ['integer', $this->getQuestionId()],
106 'skill_base_fi' => ['integer', $this->getSkillBaseId()],
107 'skill_tref_fi' => ['integer', $this->getSkillTrefId()]
108 ]
109 );
110 } else {
111 $this->db->insert('qpl_qst_skl_assigns', [
112 'obj_fi' => ['integer', $this->getParentObjId()],
113 'question_fi' => ['integer', $this->getQuestionId()],
114 'skill_base_fi' => ['integer', $this->getSkillBaseId()],
115 'skill_tref_fi' => ['integer', $this->getSkillTrefId()],
116 'skill_points' => ['integer', $this->getSkillPoints()],
117 'eval_mode' => ['text', $this->getEvalMode()]
118 ]);
119 }
120
121 if ($this->getEvalMode() == self::EVAL_MODE_BY_QUESTION_SOLUTION) {
123 }
124 }
125
126 public function saveComparisonExpressions(): void
127 {
129 $this->solution_comparison_expression_list->save();
130 }
131
132 public function deleteFromDb(): void
133 {
134 $query = "
135 DELETE FROM qpl_qst_skl_assigns
136 WHERE obj_fi = %s
137 AND question_fi = %s
138 AND skill_base_fi = %s
139 AND skill_tref_fi = %s
140 ";
141
142 $this->db->manipulateF(
143 $query,
144 ['integer', 'integer', 'integer', 'integer'],
145 [$this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId()]
146 );
147
149 }
150
151 public function deleteComparisonExpressions(): void
152 {
154 $this->solution_comparison_expression_list->delete();
155 }
156
157 public function dbRecordExists(): bool
158 {
159 $query = "
160 SELECT COUNT(*) cnt
161 FROM qpl_qst_skl_assigns
162 WHERE obj_fi = %s
163 AND question_fi = %s
164 AND skill_base_fi = %s
165 AND skill_tref_fi = %s
166 ";
167
168 $res = $this->db->queryF(
169 $query,
170 ['integer', 'integer', 'integer', 'integer'],
171 [$this->getParentObjId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId()]
172 );
173
174 $row = $this->db->fetchAssoc($res);
175
176 return $row['cnt'] > 0;
177 }
178
179 public function isSkillUsed(): bool
180 {
181 $query = "
182 SELECT COUNT(*) cnt
183 FROM qpl_qst_skl_assigns
184 WHERE obj_fi = %s
185 AND skill_base_fi = %s
186 AND skill_tref_fi = %s
187 ";
188
189 $res = $this->db->queryF(
190 $query,
191 ['integer', 'integer', 'integer'],
192 [$this->getParentObjId(), $this->getSkillBaseId(), $this->getSkillTrefId()]
193 );
194
195 $row = $this->db->fetchAssoc($res);
196
197 return $row['cnt'] > 0;
198 }
199
200 public function setSkillPoints(int $skillPoints): void
201 {
202 $this->skill_points = $skillPoints;
203 }
204
205 public function getSkillPoints(): int
206 {
207 return $this->skill_points;
208 }
209
210 public function setQuestionId(int $questionId): void
211 {
212 $this->question_id = $questionId;
213 }
214
215 public function getQuestionId(): int
216 {
217 return $this->question_id;
218 }
219
220 public function setSkillBaseId(int $skillBaseId): void
221 {
222 $this->skill_base_id = $skillBaseId;
223 }
224
225 public function getSkillBaseId(): int
226 {
228 }
229
230 public function setSkillTrefId(int $skillTrefId): void
231 {
232 $this->skill_tref_id = $skillTrefId;
233 }
234
235 public function getSkillTrefId(): int
236 {
238 }
239
240 public function setParentObjId(int $parentObjId): void
241 {
242 $this->parent_obj_id = $parentObjId;
243 }
244
245 public function getParentObjId(): int
246 {
248 }
249
250 public function loadAdditionalSkillData(): void
251 {
253 $this->setSkillPath(implode(' > ', $this->retrieveNodeTitlesArrayFromPath()));
254 }
255
256 private function retrieveNodeTitlesArrayFromPath(): array
257 {
258 $path = $this->skill_tree_service->getSkillTreePath($this->getSkillBaseId(), $this->getSkillTrefId());
259 if ($path === []) {
260 return [];
261
262 }
263
264 $nodes = [];
265 foreach ($path as $node) {
266 if ($node['title'] === 'Skill Tree Root Node') {
267 continue;
268 }
269
270 if ($node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId()) {
271 $nodes[] = $node['title'];
272 }
273 }
274
275 $root_node_skl_tree_id = reset($path)['skl_tree_id'];
276 array_unshift(
277 $nodes,
278 htmlspecialchars($this->skill_tree_service->getObjSkillTreeById($root_node_skl_tree_id)->getTitle())
279 );
280
281 return $nodes;
282 }
283
284 public function setSkillTitle($skillTitle): void
285 {
286 $this->skill_title = $skillTitle;
287 }
288
289 public function getSkillTitle(): ?string
290 {
291 return $this->skill_title;
292 }
293
294 public function setSkillPath($skillPath): void
295 {
296 $this->skill_path = $skillPath;
297 }
298
299 public function getSkillPath(): ?string
300 {
301 return $this->skill_path;
302 }
303
304 public function getEvalMode(): string
305 {
306 return $this->eval_mode;
307 }
308
309 public function setEvalMode(string $evalMode): void
310 {
311 $this->eval_mode = $evalMode;
312 }
313
314 public function hasEvalModeBySolution(): bool
315 {
316 return $this->eval_mode === self::EVAL_MODE_BY_QUESTION_SOLUTION;
317 }
318
320 {
321 $this->solution_comparison_expression_list->setQuestionId($this->getQuestionId());
322 $this->solution_comparison_expression_list->setSkillBaseId($this->getSkillBaseId());
323 $this->solution_comparison_expression_list->setSkillTrefId($this->getSkillTrefId());
324 }
325
327 {
329 }
330
331 public function getMaxSkillPoints(): int
332 {
333 if ($this->hasEvalModeBySolution()) {
334 $max_points = 0;
335
336 foreach ($this->solution_comparison_expression_list->get() as $expression) {
337 if ($expression->getPoints() > $max_points) {
338 $max_points = $expression->getPoints();
339 }
340 }
341
342 return $max_points;
343 }
344
345 return $this->getSkillPoints();
346 }
347
351 public function isValidSkillPoint($skillPoints): bool
352 {
353 return (
354 is_numeric($skillPoints) &&
355 str_replace(['.', ','], '', $skillPoints) == $skillPoints &&
356 $skillPoints > 0
357 );
358 }
359}
ilAssQuestionSolutionComparisonExpressionList $solution_comparison_expression_list
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
Interface ilDBInterface.
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26