1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php");
5
6/**
7 * Virtual skill tree explorer
8 *
9 * @author	Alex Killing <alex.killing@gmx.de>
10 * @version	$Id$
11 *
12 * @ingroup ServicesSkill
13 */
14class ilVirtualSkillTreeExplorerGUI extends ilExplorerBaseGUI
15{
16    /**
17     * @var ilLanguage
18     */
19    protected $lng;
20
21    /**
22     * @var ilCtrl
23     */
24    protected $ctrl;
25
26    protected $show_draft_nodes = false;
27    protected $show_outdated_nodes = false;
28
29    /**
30     * Constructor
31     */
32    public function __construct($a_id, $a_parent_obj, $a_parent_cmd)
33    {
34        global $DIC;
35
36        $this->lng = $DIC->language();
37        $this->ctrl = $DIC->ctrl();
38        parent::__construct($a_id, $a_parent_obj, $a_parent_cmd);
39
40        include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
41        $this->vtree = new ilVirtualSkillTree();
42
43        $this->setSkipRootNode(false);
44        $this->setAjax(false);
45    }
46
47    /**
48     * Set show draft nodes
49     *
50     * @param boolean $a_val show draft nodes
51     */
52    public function setShowDraftNodes($a_val)
53    {
54        $this->show_draft_nodes = $a_val;
55        $this->vtree->setIncludeDrafts($a_val);
56    }
57
58    /**
59     * Get show draft nodes
60     *
61     * @return boolean show draft nodes
62     */
63    public function getShowDraftNodes()
64    {
65        return $this->show_draft_nodes;
66    }
67
68    /**
69     * Set show outdated nodes
70     *
71     * @param boolean $a_val show outdated notes
72     */
73    public function setShowOutdatedNodes($a_val)
74    {
75        $this->show_outdated_nodes = $a_val;
76        $this->vtree->setIncludeOutdated($a_val);
77    }
78
79    /**
80     * Get show outdated nodes
81     *
82     * @return boolean show outdated notes
83     */
84    public function getShowOutdatedNodes()
85    {
86        return $this->show_outdated_nodes;
87    }
88
89    /**
90     * Get root node
91     *
92     * @return array root node data
93     */
94    public function getRootNode()
95    {
96        return $this->vtree->getRootNode();
97    }
98
99    /**
100     * Get node id
101     *
102     * @param array $a_node node data
103     * @return string node id
104     */
105    public function getNodeId($a_node)
106    {
107        return $a_node["id"];
108    }
109
110    /**
111     * @inheritdoc
112     */
113    public function getDomNodeIdForNodeId($node_id)
114    {
115        return parent::getDomNodeIdForNodeId(str_replace(":", "_", $node_id));
116    }
117
118    /**
119     * @inheritdoc
120     */
121    public function getNodeIdForDomNodeId($a_dom_node_id)
122    {
123        $id = parent::getNodeIdForDomNodeId($a_dom_node_id);
124        return str_replace("_", ":", $id);
125    }
126
127
128    /**
129     * Get childs of node
130     *
131     * @param int $a_parent_id parent id
132     * @return array childs
133     */
134    public function getChildsOfNode($a_parent_id)
135    {
136        return $this->vtree->getChildsOfNode($a_parent_id);
137    }
138
139    /**
140     * Get node content
141     *
142     * @param array
143     * @return
144     */
145    public function getNodeContent($a_node)
146    {
147        $lng = $this->lng;
148
149        $a_parent_id_parts = explode(":", $a_node["id"]);
150        $a_parent_skl_tree_id = $a_parent_id_parts[0];
151        $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
152
153        // title
154        $title = $a_node["title"];
155
156        // root?
157        if ($a_node["type"] == "skrt") {
158            $lng->txt("skmg_skills");
159        } else {
160            if ($a_node["type"] == "sktr") {
161                //				include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
162//				$title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
163            }
164        }
165
166        return $title;
167    }
168
169    /**
170     * Get node icon
171     *
172     * @param array
173     * @return
174     */
175    public function getNodeIcon($a_node)
176    {
177        $a_id_parts = explode(":", $a_node["id"]);
178        $a_skl_template_tree_id = $a_id_parts[1];
179
180        // root?
181        if ($a_node["type"] == "skrt") {
182            $icon = ilUtil::getImagePath("icon_scat.svg");
183        } else {
184            $type = $a_node["type"];
185            if ($type == "sktr") {
186                include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
187                $type = ilSkillTreeNode::_lookupType($a_skl_template_tree_id);
188            }
189            if ($type == "sktp") {
190                $type = "skll";
191            }
192            if ($type == "sctp") {
193                $type = "scat";
194            }
195            $icon = ilUtil::getImagePath("icon_" . $type . ".svg");
196        }
197
198        return $icon;
199    }
200
201    /**
202     * Get href for node
203     *
204     * @param mixed $a_node node object/array
205     * @return string href attribute
206     */
207    public function getNodeHref($a_node)
208    {
209        $ilCtrl = $this->ctrl;
210
211        // we have a tree id like <skl_tree_id>:<skl_template_tree_id> here
212        // use this, if you want a "common" skill id in format <skill_id>:<tref_id>
213        $id_parts = explode(":", $a_node["id"]);
214        if ($id_parts[1] == 0) {
215            // skill in main tree
216            $skill_id = $a_node["id"];
217        } else {
218            // skill in template
219            $skill_id = $id_parts[1] . ":" . $id_parts[0];
220        }
221
222        return "";
223    }
224
225    /**
226     * Is clickable
227     *
228     * @param
229     * @return
230     */
231    public function isNodeClickable($a_node)
232    {
233        return false;
234    }
235
236    /**
237     * Get node icon alt attribute
238     *
239     * @param mixed $a_node node object/array
240     * @return string image alt attribute
241     */
242    public function getNodeIconAlt($a_node)
243    {
244        $lng = $this->lng;
245
246        if ($lng->exists("skmg_" . $a_node["type"])) {
247            return $lng->txt("skmg_" . $a_node["type"]);
248        }
249
250        return $lng->txt($a_node["type"]);
251    }
252
253}
254