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