1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/UIComponent/Explorer2/classes/class.ilTreeExplorerGUI.php");
6
7/**
8 * Taxonomy explorer GUI class
9 *
10 * @author Alex Killing <alex.killing@gmx.de>
11 * @version $Id$
12 * @ingroup ServicesTaxonomy
13 */
14class ilTaxonomyExplorerGUI extends ilTreeExplorerGUI
15{
16    /**
17     * @var ilCtrl
18     */
19    protected $ctrl;
20
21    /**
22     * Constructor
23     *
24     * @param
25     * @return
26     */
27    public function __construct(
28        $a_parent_obj,
29        $a_parent_cmd,
30        $a_tax_id,
31        $a_target_gui,
32        $a_target_cmd,
33        $a_id = ""
34    ) {
35        global $DIC;
36        $this->ctrl = $DIC->ctrl();
37        include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
38        $this->tax_tree = new ilTaxonomyTree($a_tax_id);
39        if ($a_id != "") {
40            $this->id = $a_id;
41        } else {
42            $this->id = "tax_expl_" . $this->tax_tree->getTreeId();
43        }
44        include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
45        if (ilObjTaxonomy::lookupSortingMode($a_tax_id) == ilObjTaxonomy::SORT_ALPHABETICAL) {
46            $this->setOrderField("title");
47        } else {
48            $this->setOrderField("order_nr", true);
49        }
50        $this->setPreloadChilds(true);
51        $this->target_gui = $a_target_gui;
52        $this->target_cmd = $a_target_cmd;
53        //$this->setOrderField("title");
54        parent::__construct($this->id, $a_parent_obj, $a_parent_cmd, $this->tax_tree);
55    }
56
57
58    /**
59     * Get content of node
60     *
61     * @param
62     * @return
63     */
64    public function getNodeContent($a_node)
65    {
66        $rn = $this->getRootNode();
67        if ($rn["child"] == $a_node["child"]) {
68            return ilObject::_lookupTitle($this->tax_tree->getTreeId());
69        } else {
70            return $a_node["title"];
71        }
72    }
73
74    /**
75     * Get node href
76     *
77     * @param
78     * @return
79     */
80    public function getNodeHref($a_node)
81    {
82        $ilCtrl = $this->ctrl;
83
84        if (!$this->onclick && $this->target_gui != "") {
85            $ilCtrl->setParameterByClass($this->target_gui, "tax_node", $a_node["child"]);
86            if (is_array($this->parent_obj)) {
87                // Used for taxonomies in categories
88                $href = $ilCtrl->getLinkTargetByClass($this->parent_obj, $this->target_cmd);
89            } else {
90                // See: https://mantis.ilias.de/view.php?id=27727
91                $href = $ilCtrl->getLinkTargetByClass($this->target_gui, $this->target_cmd);
92            }
93            if (isset($_GET["tax_node"]) && !is_array($_GET['tax_node'])) {
94                $ilCtrl->setParameterByClass($this->target_gui, "tax_node", ilUtil::stripSlashes((string) $_GET["tax_node"]));
95            }
96            return $href;
97        } else {
98            return "#";
99        }
100    }
101
102    /**
103     * Get node icon
104     *
105     * @param
106     * @return
107     */
108    public function getNodeIcon($a_node)
109    {
110        return ilUtil::getImagePath("icon_taxn.svg");
111    }
112
113    /**
114     *
115     *
116     * @param
117     * @return
118     */
119    public function isNodeHighlighted($a_node)
120    {
121        if ((!$this->onclick && $a_node["child"] == $_GET["tax_node"]) ||
122            ($this->onclick && is_array($this->selected_nodes) && in_array($a_node["child"], $this->selected_nodes))) {
123            return true;
124        }
125        return false;
126    }
127
128    public function setOnClick($a_value)
129    {
130        $this->onclick = $a_value;
131    }
132
133    public function getNodeOnClick($a_node)
134    {
135        if ($this->onclick) {
136            return str_replace("{NODE_CHILD}", $a_node["child"], $this->onclick);
137        } else {
138            // #14623
139            return parent::getNodeOnClick($a_node);
140        }
141    }
142}
143