ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAssQuestionSkillAssignment.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 public const DEFAULT_COMPETENCE_POINTS = 1;
32
33 public const EVAL_MODE_BY_QUESTION_RESULT = 'result';
34 public const 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;
41 private int $skill_points;
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 {
252 $this->setSkillTitle(
254 );
255
256 $path = $this->skill_tree_service->getSkillTreePath(
257 $this->getSkillBaseId(),
258 $this->getSkillTrefId()
259 );
260
261 $nodes = [];
262 foreach ($path as $node) {
263 if ($node['title'] === "Skill Tree Root Node") {
264 continue;
265 }
266
267 if ($node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId()) {
268 $nodes[] = $node['title'];
269 }
270 }
271
272 $root_node = reset($path);
273 array_unshift(
274 $nodes,
275 $this->skill_tree_service->getObjSkillTreeById($root_node['skl_tree_id'])->getTitleForHTMLOutput()
276 );
277
278 $this->setSkillPath(implode(' > ', $nodes));
279 }
280
281 public function setSkillTitle($skillTitle): void
282 {
283 $this->skill_title = $skillTitle;
284 }
285
286 public function getSkillTitle(): ?string
287 {
288 return $this->skill_title;
289 }
290
291 public function setSkillPath($skillPath): void
292 {
293 $this->skill_path = $skillPath;
294 }
295
296 public function getSkillPath(): ?string
297 {
298 return $this->skill_path;
299 }
300
301 public function getEvalMode(): string
302 {
303 return $this->eval_mode;
304 }
305
306 public function setEvalMode(string $evalMode): void
307 {
308 $this->eval_mode = $evalMode;
309 }
310
311 public function hasEvalModeBySolution(): bool
312 {
313 return $this->eval_mode === self::EVAL_MODE_BY_QUESTION_SOLUTION;
314 }
315
317 {
318 $this->solution_comparison_expression_list->setQuestionId($this->getQuestionId());
319 $this->solution_comparison_expression_list->setSkillBaseId($this->getSkillBaseId());
320 $this->solution_comparison_expression_list->setSkillTrefId($this->getSkillTrefId());
321 }
322
324 {
326 }
327
328 public function getMaxSkillPoints(): int
329 {
330 if ($this->hasEvalModeBySolution()) {
331 $max_points = 0;
332
333 foreach ($this->solution_comparison_expression_list->get() as $expression) {
334 if ($expression->getPoints() > $max_points) {
335 $max_points = $expression->getPoints();
336 }
337 }
338
339 return $max_points;
340 }
341
342 return $this->getSkillPoints();
343 }
344
348 public function isValidSkillPoint($skillPoints): bool
349 {
350 return (
351 is_numeric($skillPoints) &&
352 str_replace(['.', ','], '', $skillPoints) == $skillPoints &&
353 $skillPoints > 0
354 );
355 }
356}
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