ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilVirtualSkillTree.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
14 {
15  protected $include_drafts = false;
16  protected $drafts = array();
17  protected $include_outdated = false;
18  protected $outdated = array();
19 
23  public function __construct()
24  {
25  include_once("./Services/Skill/classes/class.ilSkillTree.php");
26  $this->tree = new ilSkillTree();
27  }
28 
34  function getRootNode()
35  {
36  $root_id = $this->tree->readRootId();
37  $root_node = $this->tree->getNodeData($root_id);
38  unset($root_node["child"]);
39  $root_node["id"] = $root_id.":0";
40  $root_node["cskill_id"] = $root_id.":0";
41 
42  return $root_node;
43  }
44 
50  function setIncludeDrafts($a_val)
51  {
52  $this->include_drafts = $a_val;
53  }
54 
60  function getIncludeDrafts()
61  {
62  return $this->include_drafts;
63  }
64 
70  function setIncludeOutdated($a_val)
71  {
72  $this->include_outdated = $a_val;
73  }
74 
80  function getIncludeOutdated()
81  {
83  }
84 
91  function getNode($a_id)
92  {
93  $id_parts = explode(":", $a_id);
94  $skl_tree_id = $id_parts[0];
95  $skl_template_tree_id = $id_parts[1];
96 
97  if ($skl_template_tree_id == 0 || (ilSkillTemplateReference::_lookupTemplateId($skl_tree_id)
98  == $skl_template_tree_id))
99  {
100  $node_data = $this->tree->getNodeData($skl_tree_id);
101  $node_data["parent"] = $node_data["parent"].":0";
102  }
103  else
104  {
105  $node_data = $this->tree->getNodeData($skl_template_tree_id);
106  $node_data["parent"] = $skl_tree_id.":".$node_data["parent"];
107  }
108 
109  unset($node_data["child"]);
110  unset($node_data["skl_tree_id"]);
111  unset($node_data["lft"]);
112  unset($node_data["rgt"]);
113  unset($node_data["depth"]);
114 
115  $node_data["id"] = $a_id;
116  $cid = $this->getCSkillIdForVTreeId($a_id);
117  $cid_parts = explode(":", $cid);
118  $node_data["skill_id"] = $cid_parts[0];
119  $node_data["tref_id"] = $cid_parts[1];
120  $node_data["cskill_id"] = $cid;
121 
122 
123  return $node_data;
124  }
125 
126 
133  function getChildsOfNode($a_parent_id)
134  {
135  $a_parent_id_parts = explode(":", $a_parent_id);
136  $a_parent_skl_tree_id = $a_parent_id_parts[0];
137  $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
138 
139  if ($a_parent_skl_template_tree_id == 0)
140  {
141  $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_tree_id, array("scat", "skll", "sktr"), "order_nr");
142  }
143  else
144  {
145  $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_template_tree_id, array("sktp", "sctp"), "order_nr");
146  }
147 
148  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
149  $drafts = array();
150  $outdated = array();
151  foreach ($childs as $k => $c)
152  {
153  if ($a_parent_skl_template_tree_id > 0)
154  {
155  // we are in template tree only
156  $child_id = $a_parent_skl_tree_id.":".$c["child"];
157  }
158  else if (!in_array($c["type"], array("sktr", "sctr")))
159  {
160  // we are in main tree only
161  $child_id = $c["child"].":0";
162  }
163  else
164  {
165  // get template id for references
166  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
167  $child_id = $c["child"].":".ilSkillTemplateReference::_lookupTemplateId($c["child"]);
168  }
169  unset($childs[$k]["child"]);
170  unset($childs[$k]["skl_tree_id"]);
171  unset($childs[$k]["lft"]);
172  unset($childs[$k]["rgt"]);
173  unset($childs[$k]["depth"]);
174  $childs[$k]["id"] = $child_id;
175 //echo "-".$child_id."-";
176  $cid = $this->getCSkillIdForVTreeId($child_id);
177 //echo "-".$cid."-";
178  $cid_parts = explode(":", $cid);
179  $childs[$k]["skill_id"] = $cid_parts[0];
180  $childs[$k]["tref_id"] = $cid_parts[1];
181  $childs[$k]["cskill_id"] = $cid;
182  $childs[$k]["parent"] = $a_parent_id;
183 
184  $this->parent[$c["id"]] = $a_parent_id;
185 
186  // @todo: prepare this for tref id?
188  in_array($a_parent_id, $this->drafts))
189  {
190  $this->drafts[] = $child_id;
191  $drafts[] = $k;
192  }
194  in_array($a_parent_id, $this->outdated))
195  {
196  $this->outdated[] = $child_id;
197  $outdated[] = $k;
198  }
199  }
200  if (!$this->getIncludeDrafts())
201  {
202  foreach ($drafts as $d)
203  {
204  unset($childs[$d]);
205  }
206  }
207  if (!$this->getIncludeOutdated())
208  {
209  foreach ($outdated as $d)
210  {
211  unset($childs[$d]);
212  }
213  }
214 
215  return $childs;
216  }
217 
224  function getChildsOfNodeForCSkillId($a_cskill_id)
225  {
226  $id_parts = explode(":", $a_cskill_id);
227  if ($id_parts[1] == 0)
228  {
229  $id = $id_parts[0].":0";
230  }
231  else
232  {
233  $id = $id_parts[1].":".$id_parts[0];
234  }
235  return $this->getChildsOfNode($id);
236  }
237 
244  function getCSkillIdForVTreeId($a_vtree_id)
245  {
246  $id_parts = explode(":", $a_vtree_id);
247  if ($id_parts[1] == 0)
248  {
249  // skill in main tree
250  $skill_id = $id_parts[0];
251  $tref_id = 0;
252  }
253  else
254  {
255  // skill in template
256  $tref_id = $id_parts[0];
257  $skill_id = $id_parts[1];
258  }
259  return $skill_id.":".$tref_id;
260  }
261 
262 
269  function getNodeTitle($a_node)
270  {
271  global $lng;
272 
273  $a_parent_id_parts = explode(":", $a_node["id"]);
274  $a_parent_skl_tree_id = $a_parent_id_parts[0];
275  $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
276 
277  // title
278  $title = $a_node["title"];
279 
280  // root?
281  if ($a_node["type"] == "skrt")
282  {
283  $lng->txt("skmg_skills");
284  }
285  else
286  {
287  if ($a_node["type"] == "sktr")
288  {
289 // include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
290 // $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
291  }
292  }
293 
294  return $title;
295  }
296 
304  function getSubTreeForCSkillId($a_cskill_id, $a_only_basic = false)
305  {
306  $id_parts = explode(":", $a_cskill_id);
307  if ($id_parts[1] == 0)
308  {
309  $id = $id_parts[0].":0";
310  }
311  else
312  {
313  $id = $id_parts[1].":".$id_parts[0];
314  }
315 
316  $result = array();
317 
318  $node = $this->getNode($id);
319  if (!$a_only_basic || in_array($node["type"], array("skll", "sktp")) ||
320  ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp"))
321  {
322  $result[] = $node;
323  }
324  $this->__getSubTreeRec($id, $result, $a_only_basic);
325 
326  return $result;
327  }
328 
336  private function __getSubTreeRec($id, &$result, $a_only_basic)
337  {
338  $childs = $this->getChildsOfNode($id);
339  foreach ($childs as $c)
340  {
341  if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
342  ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp"))
343  {
344  $result[] = $c;
345  }
346  $this->__getSubTreeRec($c["id"], $result, $a_only_basic);
347  }
348  }
349 
356  function isDraft($a_node_id)
357  {
358  return in_array($a_node_id, $this->drafts);
359  }
360 
367  function isOutdated($a_node_id)
368  {
369  return in_array($a_node_id, $this->outdated);
370  }
371 
372 }
373 
374 ?>