ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBasicSkillTreeDBRepository.php
Go to the documentation of this file.
1 <?php
2 
4 {
8  protected $db;
9 
10  public function __construct(ilDBInterface $db = null)
11  {
12  global $DIC;
13 
14  $this->db = ($db)
15  ? $db
16  : $DIC->database();
17  }
18 
22  public function getCommonSkillIdForImportId(
23  ilSkillTree $tree,
24  int $a_source_inst_id,
25  int $a_skill_import_id,
26  int $a_tref_import_id = 0
27  ) : array {
28  $ilDB = $this->db;
29 
30  $template_ids = array();
31  if ($a_tref_import_id > 0) {
32  $skill_node_type = "sktp";
33 
34  // get all matching tref nodes
35  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
36  " WHERE n.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_sktr_" . $a_tref_import_id,
37  "text") .
38  " ORDER BY n.creation_date DESC ");
39  while ($rec = $ilDB->fetchAssoc($set)) {
40  if (($t = ilSkillTemplateReference::_lookupTemplateId($rec["obj_id"])) > 0) {
41  $template_ids[$t] = $rec["obj_id"];
42  }
43  }
44  } else {
45  $skill_node_type = "skll";
46  }
47  $set = $ilDB->query("SELECT * FROM skl_tree_node n JOIN skl_tree t ON (n.obj_id = t.child) " .
48  " WHERE n.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_" . $skill_node_type . "_" . $a_skill_import_id,
49  "text") .
50  " ORDER BY n.creation_date DESC ");
51  $results = array();
52  while ($rec = $ilDB->fetchAssoc($set)) {
53  $matching_trefs = array();
54  if ($a_tref_import_id > 0) {
55  $skill_template_id = $tree->getTopParentNodeId($rec["obj_id"]);
56 
57  // check of skill is in template
58  foreach ($template_ids as $templ => $tref) {
59  if ($skill_template_id == $templ) {
60  $matching_trefs[] = $tref;
61  }
62  }
63  } else {
64  $matching_trefs = array(0);
65  }
66 
67  foreach ($matching_trefs as $t) {
68  $results[] = array("skill_id" => $rec["obj_id"],
69  "tref_id" => $t,
70  "creation_date" => $rec["creation_date"]
71  );
72  }
73  }
74  return $results;
75  }
76 
80  public function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id) : array
81  {
82  $ilDB = $this->db;
83 
84  $set = $ilDB->query("SELECT * FROM skl_level l JOIN skl_tree t ON (l.skill_id = t.child) " .
85  " WHERE l.import_id = " . $ilDB->quote("il_" . ((int) $a_source_inst_id) . "_sklv_" . $a_level_import_id,
86  "text") .
87  " ORDER BY l.creation_date DESC ");
88  $results = array();
89  while ($rec = $ilDB->fetchAssoc($set)) {
90  $results[] = array("level_id" => $rec["id"], "creation_date" => $rec["creation_date"]);
91  }
92  return $results;
93  }
94 }
Skill tree.
Interface ilBasicSkillTreeRepository.
getTopParentNodeId($a_node_id)
Get top parent node id for a node.
global $DIC
Definition: goto.php:24
static _lookupTemplateId($a_obj_id)
Lookup template ID.
$results
global $ilDB
getCommonSkillIdForImportId(ilSkillTree $tree, int $a_source_inst_id, int $a_skill_import_id, int $a_tref_import_id=0)
getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)