ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
61 {
63 }
64
70 function setIncludeOutdated($a_val)
71 {
72 $this->include_outdated = $a_val;
73 }
74
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
268 function getVTreeIdForCSkillId($a_cskill_id)
269 {
270 $id_parts = explode(":", $a_cskill_id);
271 if ($id_parts[1] == 0)
272 {
273 $id = $id_parts[0].":0";
274 }
275 else
276 {
277 $id = $id_parts[1].":".$id_parts[0];
278 }
279 return $id;
280 }
281
282
283
290 function getNodeTitle($a_node)
291 {
292 global $lng;
293
294 $a_parent_id_parts = explode(":", $a_node["id"]);
295 $a_parent_skl_tree_id = $a_parent_id_parts[0];
296 $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
297
298 // title
299 $title = $a_node["title"];
300
301 // root?
302 if ($a_node["type"] == "skrt")
303 {
304 $lng->txt("skmg_skills");
305 }
306 else
307 {
308 if ($a_node["type"] == "sktr")
309 {
310// include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
311// $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
312 }
313 }
314
315 return $title;
316 }
317
325 function getSubTreeForCSkillId($a_cskill_id, $a_only_basic = false)
326 {
327 $id_parts = explode(":", $a_cskill_id);
328 if ($id_parts[1] == 0)
329 {
330 $id = $id_parts[0].":0";
331 }
332 else
333 {
334 $id = $id_parts[1].":".$id_parts[0];
335 }
336
337 $result = array();
338
339 $node = $this->getNode($id);
340 if (!$a_only_basic || in_array($node["type"], array("skll", "sktp")) ||
341 ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp"))
342 {
343 $result[] = $node;
344 }
345 $this->__getSubTreeRec($id, $result, $a_only_basic);
346
347 return $result;
348 }
349
357 private function __getSubTreeRec($id, &$result, $a_only_basic)
358 {
359 $childs = $this->getChildsOfNode($id);
360 foreach ($childs as $c)
361 {
362 if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
363 ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp"))
364 {
365 $result[] = $c;
366 }
367 $this->__getSubTreeRec($c["id"], $result, $a_only_basic);
368 }
369 }
370
377 function isDraft($a_node_id)
378 {
379 return in_array($a_node_id, $this->drafts);
380 }
381
388 function isOutdated($a_node_id)
389 {
390 return in_array($a_node_id, $this->outdated);
391 }
392
393}
394
395?>
$result
static _lookupTemplateId($a_obj_id)
Lookup template ID.
static _lookupStatus($a_obj_id)
Lookup Status.
static _lookupType($a_obj_id)
Lookup Type.
getSubTreeForCSkillId($a_cskill_id, $a_only_basic=false)
Get sub tree.
isDraft($a_node_id)
Is draft.
__getSubTreeRec($id, &$result, $a_only_basic)
Get subtree, internal.
isOutdated($a_node_id)
Is outdated.
getIncludeDrafts()
Get include drafts.
getChildsOfNode($a_parent_id)
Get childs of node.
getVTreeIdForCSkillId($a_cskill_id)
Get tree id for common skill id.
getNodeTitle($a_node)
Get node content.
setIncludeDrafts($a_val)
Set include drafts.
setIncludeOutdated($a_val)
Set include outdated.
getIncludeOutdated()
Get include outdated.
getCSkillIdForVTreeId($a_vtree_id)
Get common skill id for tree id.
getChildsOfNodeForCSkillId($a_cskill_id)
Get childs of node for cskill id.
global $lng
Definition: privfeed.php:40