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