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