1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once("./Services/UIComponent/Explorer2/classes/class.ilTreeExplorerGUI.php"); 5include_once("./Services/Skill/classes/class.ilSkillTreeNode.php"); 6 7/** 8 * Explorer for selecting a personal skill 9 * 10 * @author Alex Killing <alex.killing@gmx.de> 11 * @version $Id$ 12 * 13 * @ingroup ServicesUIComponent 14 */ 15class ilPersonalSkillExplorerGUI extends ilTreeExplorerGUI 16{ 17 /** 18 * @var ilCtrl 19 */ 20 protected $ctrl; 21 22 /** 23 * @var ilLanguage 24 */ 25 protected $lng; 26 27 protected $selectable = array(); 28 protected $selectable_child_nodes = array(); 29 protected $has_selectable_nodes = false; 30 31 /** 32 * Constructor 33 */ 34 public function __construct($a_parent_obj, $a_parent_cmd, $a_select_gui, $a_select_cmd, $a_select_par = "obj_id") 35 { 36 global $DIC; 37 38 $this->ctrl = $DIC->ctrl(); 39 $this->lng = $DIC->language(); 40 41 $this->select_gui = (is_object($a_select_gui)) 42 ? strtolower(get_class($a_select_gui)) 43 : $a_select_gui; 44 $this->select_cmd = $a_select_cmd; 45 $this->select_par = $a_select_par; 46 47 $this->lng->loadLanguageModule("skmg"); 48 49 include_once("./Services/Skill/classes/class.ilSkillTree.php"); 50 $this->tree = new ilSkillTree(); 51 $this->root_id = $this->tree->readRootId(); 52 53 parent::__construct("pskill_sel", $a_parent_obj, $a_parent_cmd, $this->tree); 54 $this->setSkipRootNode(true); 55 56 $this->all_nodes = $this->tree->getSubTree($this->tree->getNodeData($this->root_id)); 57 foreach ($this->all_nodes as $n) { 58 $this->node[$n["child"]] = $n; 59 $this->child_nodes[$n["parent"]][] = $n; 60 $this->parent[$n["child"]] = $n["parent"]; 61 //echo "-$k-"; var_dump($n); 62 } 63 64 65 // $this->setTypeWhiteList(array("skrt", "skll", "scat", "sktr")); 66 $this->buildSelectableTree($this->tree->readRootId()); 67 } 68 69 /** 70 * Set selectable nodes exist? 71 * 72 * @param bool $a_val selectable nodes exist 73 */ 74 protected function setHasSelectableNodes($a_val) 75 { 76 $this->has_selectable_nodes = $a_val; 77 } 78 79 /** 80 * Get selectable nodes exist? 81 * 82 * @return bool selectable nodes exist 83 */ 84 public function getHasSelectableNodes() 85 { 86 return $this->has_selectable_nodes; 87 } 88 89 /** 90 * Build selectable tree 91 * 92 * @param int $a_node_id tree id 93 */ 94 public function buildSelectableTree($a_node_id) 95 { 96 //echo "<br>-$a_node_id-"; 97 if (in_array(ilSkillTreeNode::_lookupStatus($a_node_id), array(ilSkillTreeNode::STATUS_DRAFT, ilSkillTreeNode::STATUS_OUTDATED))) { 98 return; 99 } 100 101 if (ilSkillTreeNode::_lookupSelfEvaluation($a_node_id)) { 102 $this->selectable[$a_node_id] = true; 103 $cid = $a_node_id; 104 //$this->selectable[$this->parent[$a_node_id]] = true; 105 while (isset($this->parent[$cid])) { 106 $this->selectable[$this->parent[$cid]] = true; 107 $cid = $this->parent[$cid]; 108 } 109 } 110 foreach ($this->getOriginalChildsOfNode($a_node_id) as $n) { 111 //echo "+".$n["child"]."+"; 112 $this->buildSelectableTree($n["child"]); 113 } 114 if ($this->selectable[$a_node_id]) { 115 $this->setHasSelectableNodes(true); 116 $this->selectable_child_nodes[$this->node[$a_node_id]["parent"]][] = 117 $this->node[$a_node_id]; 118 } 119 } 120 121 /** 122 * Get childs of node (selectable tree) 123 * 124 * @param int $a_parent_id parent id 125 * @return array childs 126 */ 127 public function getChildsOfNode($a_parent_id) 128 { 129 if (is_array($this->selectable_child_nodes[$a_parent_id])) { 130 $childs = $this->selectable_child_nodes[$a_parent_id]; 131 $childs = ilUtil::sortArray($childs, "order_nr", "asc", true); 132 return $childs; 133 } 134 return array(); 135 } 136 137 /** 138 * Get original childs of node (whole tree) 139 * 140 * @param int $a_parent_id parent id 141 * @return array childs 142 */ 143 public function getOriginalChildsOfNode($a_parent_id) 144 { 145 if (is_array($this->child_nodes[$a_parent_id])) { 146 return $this->child_nodes[$a_parent_id]; 147 } 148 return array(); 149 } 150 151 /** 152 * Get href for node 153 * 154 * @param mixed $a_node node object/array 155 * @return string href attribute 156 */ 157 public function getNodeHref($a_node) 158 { 159 $ilCtrl = $this->ctrl; 160 161 $skill_id = $a_node["child"]; 162 163 $ilCtrl->setParameterByClass($this->select_gui, $this->select_par, $skill_id); 164 $ret = $ilCtrl->getLinkTargetByClass($this->select_gui, $this->select_cmd); 165 $ilCtrl->setParameterByClass($this->select_gui, $this->select_par, ""); 166 167 return $ret; 168 } 169 170 /** 171 * Get node content 172 * 173 * @param array 174 * @return 175 */ 176 public function getNodeContent($a_node) 177 { 178 $lng = $this->lng; 179 180 // title 181 $title = $a_node["title"]; 182 183 return $title; 184 } 185 186 /** 187 * Is clickable 188 * 189 * @param 190 * @return 191 */ 192 public function isNodeClickable($a_node) 193 { 194 if (!ilSkillTreeNode::_lookupSelfEvaluation($a_node["child"])) { 195 return false; 196 } 197 return true; 198 } 199 200 /** 201 * get image path (may be overwritten by derived classes) 202 */ 203 public function getNodeIcon($a_node) 204 { 205 $t = $a_node["type"]; 206 if (in_array($t, array("sktr"))) { 207 return ilUtil::getImagePath("icon_skll.svg"); 208 } 209 return ilUtil::getImagePath("icon_" . $t . ".svg"); 210 } 211 212 /** 213 * Get node icon alt attribute 214 * 215 * @param mixed $a_node node object/array 216 * @return string image alt attribute 217 */ 218 public function getNodeIconAlt($a_node) 219 { 220 $lng = $this->lng; 221 222 if ($lng->exists("skmg_" . $a_node["type"])) { 223 return $lng->txt("skmg_" . $a_node["type"]); 224 } 225 226 return $lng->txt($a_node["type"]); 227 } 228 229} 230