ILIAS  release_8 Revision v8.24
class.ilSkillTreeNode.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilDBInterface $db;
28 protected \ILIAS\Skill\Service\SkillService $skill_service;
29 protected string $type = "";
30 protected int $id = 0;
31 protected string $title = "";
32 protected string $description = "";
33 protected bool $self_eval = false;
34 protected int $order_nr = 0;
35 protected string $import_id = "";
36 protected string $creation_date = "";
37 protected int $status = 0;
38
51 protected array $data_record = [];
52
53 public const STATUS_PUBLISH = 0;
54 public const STATUS_DRAFT = 1;
55 public const STATUS_OUTDATED = 2;
56
57 public function __construct(int $a_id = 0)
58 {
59 global $DIC;
60
61 $this->db = $DIC->database();
62 $this->id = $a_id;
63
64 if ($a_id != 0) {
65 $this->read();
66 }
67 $this->skill_service = $DIC->skills();
68 }
69
70 public function setTitle(string $a_title): void
71 {
72 $this->title = $a_title;
73 }
74
75 public function getTitle(): string
76 {
77 return $this->title;
78 }
79
80 public function setDescription(string $a_description): void
81 {
82 $this->description = $a_description;
83 }
84
85 public function getDescription(): string
86 {
87 return $this->description;
88 }
89
90 public function setType(string $a_type): void
91 {
92 $this->type = $a_type;
93 }
94
95 public function getType(): string
96 {
97 return $this->type;
98 }
99
100 public function setId(int $a_id): void
101 {
102 $this->id = $a_id;
103 }
104
105 public function getId(): int
106 {
107 return $this->id;
108 }
109
110 public function setSelfEvaluation(bool $a_val): void
111 {
112 $this->self_eval = $a_val;
113 }
114
115 public function getSelfEvaluation(): bool
116 {
117 return $this->self_eval;
118 }
119
120 public function setOrderNr(int $a_val): void
121 {
122 $this->order_nr = $a_val;
123 }
124
125 public function getOrderNr(): int
126 {
127 return $this->order_nr;
128 }
129
130 public function setImportId(string $a_val): void
131 {
132 $this->import_id = $a_val;
133 }
134
135 public function getImportId(): string
136 {
137 return $this->import_id;
138 }
139
140 protected function setCreationDate(string $a_val): void
141 {
142 $this->creation_date = $a_val;
143 }
144
145 public function getCreationDate(): string
146 {
148 }
149
153 public static function getAllStatus(): array
154 {
155 global $DIC;
156
157 $lng = $DIC->language();
158
159 return array(
160 self::STATUS_DRAFT => $lng->txt("skmg_status_draft"),
161 self::STATUS_PUBLISH => $lng->txt("skmg_status_publish"),
162 self::STATUS_OUTDATED => $lng->txt("skmg_status_outdated")
163 );
164 }
165
166 public static function getStatusInfo(int $a_status): string
167 {
168 global $DIC;
169
170 $lng = $DIC->language();
171
172 switch ($a_status) {
173 case self::STATUS_PUBLISH: return $lng->txt("skmg_status_publish_info");
174 case self::STATUS_DRAFT: return $lng->txt("skmg_status_draft_info");
175 case self::STATUS_OUTDATED: return $lng->txt("skmg_status_outdated_info");
176 }
177 return "";
178 }
179
183 public function read(): void
184 {
186
187 if (empty($this->data_record)) {
188 $query = "SELECT * FROM skl_tree_node WHERE obj_id = " .
189 $ilDB->quote($this->id, "integer");
190 $obj_set = $ilDB->query($query);
191 $this->data_record = $ilDB->fetchAssoc($obj_set);
192 }
193 $this->data_record["order_nr"] = (int) $this->data_record["order_nr"];
194 $this->data_record["self_eval"] = (bool) $this->data_record["self_eval"];
195 $this->data_record["status"] = (int) $this->data_record["status"];
196 $this->setType($this->data_record["type"]);
197 $this->setTitle($this->data_record["title"]);
198 $this->setDescription($this->data_record["description"] ?? "");
199 $this->setOrderNr($this->data_record["order_nr"]);
200 $this->setSelfEvaluation($this->data_record["self_eval"]);
201 $this->setStatus($this->data_record["status"]);
202 $this->setImportId($this->data_record["import_id"] ?? "");
203 $this->setCreationDate($this->data_record["creation_date"] ?? "");
204 }
205
209 public function setDataRecord(array $a_record): void
210 {
211 $this->data_record = $a_record;
212 }
213
214 protected static function _lookup(int $a_obj_id, string $a_field): ?string
215 {
216 global $DIC;
217
218 $ilDB = $DIC->database();
219
220 $query = "SELECT $a_field FROM skl_tree_node WHERE obj_id = " .
221 $ilDB->quote($a_obj_id, "integer");
222 $obj_set = $ilDB->query($query);
223 $obj_rec = $ilDB->fetchAssoc($obj_set);
224
225 return isset($obj_rec[$a_field]) ? (string) $obj_rec[$a_field] : null;
226 }
227
228 public static function _lookupTitle(int $a_obj_id, int $a_tref_id = 0): string
229 {
230 if ($a_tref_id > 0 && ilSkillTemplateReference::_lookupTemplateId($a_tref_id) == $a_obj_id) {
231 return self::_lookup($a_tref_id, "title");
232 }
233 return (string) self::_lookup($a_obj_id, "title");
234 }
235
236 public static function _lookupDescription(int $a_obj_id): string
237 {
238 global $DIC;
239
240 $ilDB = $DIC->database();
241
242 return (string) self::_lookup($a_obj_id, "description");
243 }
244
245 public static function _lookupSelfEvaluation(int $a_obj_id): bool
246 {
247 global $DIC;
248
249 $ilDB = $DIC->database();
250
251 return (bool) self::_lookup($a_obj_id, "self_eval");
252 }
253
254 public static function _lookupStatus(int $a_obj_id): int
255 {
256 global $DIC;
257
258 $ilDB = $DIC->database();
259
260 return (int) self::_lookup($a_obj_id, "status");
261 }
262
263 public static function _lookupType(int $a_obj_id): string
264 {
265 global $DIC;
266
267 $ilDB = $DIC->database();
268
269 $query = "SELECT * FROM skl_tree_node WHERE obj_id = " .
270 $ilDB->quote($a_obj_id, "integer");
271 $obj_set = $ilDB->query($query);
272 $obj_rec = $ilDB->fetchAssoc($obj_set);
273
274 return $obj_rec["type"] ?? "";
275 }
276
277 public function setStatus(int $a_val): void
278 {
279 $this->status = $a_val;
280 }
281
282 public function getStatus(): int
283 {
284 return $this->status;
285 }
286
287 public static function _writeTitle(int $a_obj_id, string $a_title): void
288 {
289 global $DIC;
290
291 $ilDB = $DIC->database();
292
293 $query = "UPDATE skl_tree_node SET " .
294 " title = " . $ilDB->quote($a_title, "text") .
295 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
296
297 $ilDB->manipulate($query);
298 }
299
300 public static function _writeDescription(int $a_obj_id, string $a_description): void
301 {
302 global $DIC;
303
304 $ilDB = $DIC->database();
305
306 $query = "UPDATE skl_tree_node SET " .
307 " description = " . $ilDB->quote($a_description, "clob") .
308 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
309
310 $ilDB->manipulate($query);
311 }
312
313 public static function _writeOrderNr(int $a_obj_id, int $a_nr): void
314 {
315 global $DIC;
316
317 $ilDB = $DIC->database();
318
319 $query = "UPDATE skl_tree_node SET " .
320 " order_nr = " . $ilDB->quote($a_nr, "integer") .
321 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
322 $ilDB->manipulate($query);
323 }
324
328 public function create(): void
329 {
331
332 // insert object data
333 $id = $ilDB->nextId("skl_tree_node");
334 $query = "INSERT INTO skl_tree_node (obj_id, title, description, type, create_date, self_eval, order_nr, status, creation_date, import_id) " .
335 "VALUES (" .
336 $ilDB->quote($id, "integer") . "," .
337 $ilDB->quote($this->getTitle(), "text") . "," .
338 $ilDB->quote($this->getDescription(), "clob") . "," .
339 $ilDB->quote($this->getType(), "text") . ", " .
340 $ilDB->now() . ", " .
341 $ilDB->quote((int) $this->getSelfEvaluation(), "integer") . ", " .
342 $ilDB->quote($this->getOrderNr(), "integer") . ", " .
343 $ilDB->quote($this->getStatus(), "integer") . ", " .
344 $ilDB->now() . ", " .
345 $ilDB->quote($this->getImportId(), "text") .
346 ")";
347 $ilDB->manipulate($query);
348 $this->setId($id);
349 }
350
354 public function update()
355 {
357
358 $query = "UPDATE skl_tree_node SET " .
359 " title = " . $ilDB->quote($this->getTitle(), "text") .
360 " ,description = " . $ilDB->quote($this->getDescription(), "clob") .
361 " ,self_eval = " . $ilDB->quote((int) $this->getSelfEvaluation(), "integer") .
362 " ,order_nr = " . $ilDB->quote($this->getOrderNr(), "integer") .
363 " ,status = " . $ilDB->quote($this->getStatus(), "integer") .
364 " ,import_id = " . $ilDB->quote($this->getImportId(), "text") .
365 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
366
367 $ilDB->manipulate($query);
368 }
369
370 public function delete(): void
371 {
373
374 $query = "DELETE FROM skl_tree_node WHERE obj_id= " .
375 $ilDB->quote($this->getId(), "integer");
376 $ilDB->manipulate($query);
377 }
378
382 public static function uniqueTypesCheck(array $a_items): bool
383 {
384 $types = [];
385 foreach ($a_items as $item) {
387 $types[$type] = $type;
388 }
389
390 if (count($types) > 1) {
391 return false;
392 }
393 return true;
394 }
395
399 public static function getAllSelfEvaluationNodes(): array
400 {
401 global $DIC;
402
403 $ilDB = $DIC->database();
404
405 $set = $ilDB->query(
406 "SELECT obj_id, title FROM skl_tree_node WHERE " .
407 " self_eval = " . $ilDB->quote(true, "integer") . " ORDER BY TITLE "
408 );
409 $nodes = [];
410 while ($rec = $ilDB->fetchAssoc($set)) {
411 $rec["obj_id"] = (int) $rec["obj_id"];
412 $nodes[$rec["obj_id"]] = $rec["title"];
413 }
414 return $nodes;
415 }
416
420 public static function getSelectableSkills(): array
421 {
422 global $DIC;
423
424 $ilDB = $DIC->database();
425
426 $set = $ilDB->query(
427 "SELECT * FROM skl_tree_node " .
428 " WHERE self_eval = " . $ilDB->quote(1, "integer")
429 );
430
431 $sel_skills = [];
432 while ($rec = $ilDB->fetchAssoc($set)) {
433 $rec['obj_id'] = (int) $rec['obj_id'];
434 $rec['order_nr'] = (int) $rec['order_nr'];
435 $rec['status'] = (int) $rec['status'];
436 $rec['self_eval'] = (bool) $rec['self_eval'];
437 $sel_skills[] = $rec;
438 }
439
440 return $sel_skills;
441 }
442
443 public static function getIconPath(int $a_obj_id, string $a_type, string $a_size = "", int $a_status = 0): string
444 {
445 if ($a_status == self::STATUS_DRAFT && $a_type == "sctp") {
446 $a_type = "scat";
447 }
448 if ($a_status == self::STATUS_DRAFT && $a_type == "sktp") {
449 $a_type = "skll";
450 }
451
452 $off = ($a_status == self::STATUS_DRAFT)
453 ? "_off"
454 : "";
455
456 $a_name = "icon_" . $a_type . $a_size . $off . ".svg";
457 if ($a_type == "sktr") {
460 if ($type == "sctp") {
461 $a_name = "icon_sctr" . $a_size . $off . ".svg";
462 }
463 }
464 $vers = "vers=" . str_replace(array(".", " "), "-", ILIAS_VERSION);
465 return ilUtil::getImagePath($a_name) . "?" . $vers;
466 }
467
471 public static function getAllCSkillIdsForNodeIds(array $a_node_ids): array
472 {
473 $cskill_ids = [];
474 foreach ($a_node_ids as $id) {
475 if (in_array(self::_lookupType($id), array("skll", "scat", "sktr"))) {
476 $skill_id = $id;
477 $tref_id = 0;
478 if (ilSkillTreeNode::_lookupType($id) == "sktr") {
480 $tref_id = $id;
481 }
482 $cskill_ids[] = array("skill_id" => $skill_id, "tref_id" => $tref_id);
483 }
484 if (in_array(ilSkillTreeNode::_lookupType($id), array("sktp", "sctp"))) {
486 $cskill_ids[] = array("skill_id" => $id, "tref_id" => $tref_id);
487 }
488 }
489 // for cats, skills and template references, get "real" usages
490 // for skill and category templates check usage in references
491 }
492 return $cskill_ids;
493 }
494}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSelfEvaluation(bool $a_val)
static uniqueTypesCheck(array $a_items)
Check for unique types.
static getIconPath(int $a_obj_id, string $a_type, string $a_size="", int $a_status=0)
static _writeTitle(int $a_obj_id, string $a_title)
static _lookupSelfEvaluation(int $a_obj_id)
static _lookupDescription(int $a_obj_id)
static _lookup(int $a_obj_id, string $a_field)
setImportId(string $a_val)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static getStatusInfo(int $a_status)
static getAllStatus()
Get all status as array, key is value, value is lang text.
static _writeDescription(int $a_obj_id, string $a_description)
setDataRecord(array $a_record)
this method should only be called by class ilSCORM2004NodeFactory
setCreationDate(string $a_val)
static _writeOrderNr(int $a_obj_id, int $a_nr)
setTitle(string $a_title)
read()
Read Data of Node.
static _lookupType(int $a_obj_id)
static _lookupStatus(int $a_obj_id)
setType(string $a_type)
setDescription(string $a_description)
ILIAS Skill Service SkillService $skill_service
static getAllCSkillIdsForNodeIds(array $a_node_ids)
Get all possible common skill IDs for node IDs.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
const ILIAS_VERSION
Interface ilDBInterface.
$query
$lng