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