ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSkillTreeDBRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
25 {
26  protected ilDBInterface $db;
27  protected Tree\SkillTreeFactory $tree_factory;
28 
29  public function __construct(Tree\SkillTreeFactory $tree_factory, ilDBInterface $db = null)
30  {
31  global $DIC;
32 
33  $this->tree_factory = $tree_factory;
34  $this->db = ($db)
35  ?: $DIC->database();
36  }
37 
41  public function getCommonSkillIdForImportId(
42  int $a_source_inst_id,
43  int $a_skill_import_id,
44  int $a_tref_import_id = 0
45  ): array {
46  $ilDB = $this->db;
47 
48  $template_ids = [];
49  if ($a_tref_import_id > 0) {
50  $skill_node_type = "sktp";
51 
52  // get all matching tref nodes
53  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
54  " WHERE n.import_id = " . $ilDB->quote(
55  "il_" . ($a_source_inst_id) . "_sktr_" . $a_tref_import_id,
56  "text"
57  ) .
58  " ORDER BY n.creation_date DESC ");
59  while ($rec = $ilDB->fetchAssoc($set)) {
60  if (($t = ilSkillTemplateReference::_lookupTemplateId((int) $rec["obj_id"])) > 0) {
61  $template_ids[$t] = (int) $rec["obj_id"];
62  }
63  }
64  } else {
65  $skill_node_type = "skll";
66  }
67  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
68  " WHERE n.import_id = " . $ilDB->quote(
69  "il_" . ($a_source_inst_id) . "_" . $skill_node_type . "_" . $a_skill_import_id,
70  "text"
71  ) .
72  " ORDER BY n.creation_date DESC ");
73  $results = [];
74  while ($rec = $ilDB->fetchAssoc($set)) {
75  $matching_trefs = [];
76  if ($a_tref_import_id > 0) {
77  $tree = $this->tree_factory->getTreeById((int) $rec["skl_tree_id"]);
78  $skill_template_id = $tree->getTopParentNodeId((int) $rec["obj_id"]);
79 
80  // check of skill is in template
81  foreach ($template_ids as $templ => $tref) {
82  if ($skill_template_id == $templ) {
83  $matching_trefs[] = $tref;
84  }
85  }
86  } else {
87  $matching_trefs = array(0);
88  }
89 
90  foreach ($matching_trefs as $t) {
91  $results[] = array("skill_id" => (int) $rec["obj_id"],
92  "tref_id" => $t,
93  "creation_date" => $rec["creation_date"]
94  );
95  }
96  }
97  return $results;
98  }
99 
103  public function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id): array
104  {
105  $ilDB = $this->db;
106 
107  $set = $ilDB->query("SELECT * FROM skl_level l JOIN skl_tree t ON (l.skill_id = t.child) " .
108  " WHERE l.import_id = " . $ilDB->quote(
109  "il_" . $a_source_inst_id . "_sklv_" . $a_level_import_id,
110  "text"
111  ) .
112  " ORDER BY l.creation_date DESC ");
113  $results = [];
114  while ($rec = $ilDB->fetchAssoc($set)) {
115  $results[] = array("level_id" => (int) $rec["id"], "creation_date" => $rec["creation_date"]);
116  }
117  return $results;
118  }
119 
120  public function isInAnyTree(int $node_id): bool
121  {
122  $tree_id = $this->getTreeIdForNodeId($node_id);
123  if ($tree_id > 0) {
124  return true;
125  }
126  return false;
127  }
128 
129  public function getTreeIdForNodeId(int $node_id): int
130  {
131  $db = $this->db;
132 
133  $set = $db->queryF(
134  "SELECT * FROM skl_tree " .
135  " WHERE child = %s ",
136  ["integer"],
137  [$node_id]
138  );
139  $rec = $db->fetchAssoc($set);
140  return (int) ($rec["skl_tree_id"] ?? 0);
141  }
142 
143  public function getTreeForNodeId(int $node_id): ilSkillTree
144  {
145  $tree_id = $this->getTreeIdForNodeId($node_id);
146  return $this->tree_factory->getTreeById($tree_id);
147  }
148 
149  public function getVirtualTreeForNodeId(int $node_id): ilVirtualSkillTree
150  {
151  $tree_id = $this->getTreeIdForNodeId($node_id);
152  return $this->tree_factory->getVirtualTreeById($tree_id);
153  }
154 
155  public function getParentNodeIdForNodeId(int $node_id): int
156  {
157  $db = $this->db;
158 
159  $set = $db->queryF(
160  "SELECT * FROM skl_tree " .
161  " WHERE child = %s ",
162  ["integer"],
163  [$node_id]
164  );
165  $rec = $db->fetchAssoc($set);
166  return (int) ($rec["parent"] ?? 0);
167  }
168 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetchAssoc(ilDBStatement $statement)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)
global $DIC
Definition: feed.php:28
__construct(Tree\SkillTreeFactory $tree_factory, ilDBInterface $db=null)
$results
queryF(string $query, array $types, array $values)
getCommonSkillIdForImportId(int $a_source_inst_id, int $a_skill_import_id, int $a_tref_import_id=0)