aboutsummaryrefslogtreecommitdiff
path: root/lib/extern/modules/views/ExternRangeLectureTree.class.php
blob: d8337fc4c536344fa91337449caa83de66a0bc94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?
# Lifter002: TODO
# Lifter003: TEST
# Lifter007: TODO
# Lifter010: TODO

/**
* class to print out the range tree
*
* This class prints out a html representation of the tree for the "extern modules"
*
* @access   public
* @author   André Noack <noack@data-quest.de>
* @package
*/
class ExternRangeLectureTree
{
    var $tree;
    var $config;
    var $param;
    var $root_id;
    var $start_item_id;

    /**
    * constructor
    *
    * @access public
    */
    function __construct(&$config, $start_item_id, $sem_number = false, $sem_status = false)
    {
        $this->config = $config;

        $query = "SELECT item_id FROM range_tree WHERE studip_object_id = ?";
        $statement = DBManager::get()->prepare($query);
        $statement->execute([$this->config->range_id]);
        $this->root_id = $statement->fetchColumn();

        $this->start_item_id = $start_item_id ?: $this->root_id;
        $args = NULL;
        if ($sem_number !== false) {
            $args['sem_number'] = $sem_number;
        }
        if ($sem_status !== false) {
            $args['sem_status'] =  $sem_status;
        }
        $this->param = "range_id={$this->config->range_id}&module=Rangelecturetree&config_id={$this->config->id}&";

        $this->tree = TreeAbstract::GetInstance("StudipRangeTree",$args);
    }

    function showSemRangeTree () {
        echo "\n<table" . $this->config->getAttributes("Main", "table") . ">";
        echo "\n<tr><td>". $this->getSemPath() . "</td></tr>\n<tr><td>";
        $this->showContent($this->start_item_id);
        echo "\n</td></tr>";
        if ($this->tree->getNumKids($this->start_item_id)) {
            echo "\n<tr><td>";
            echo $this->showKids($this->start_item_id);
            echo "\n</td></tr>";
        }
        if ($this->config->getAttributes("TreeBackLink", "image")
                || $this->config->getAttributes("TreeBackLink", "linktext")) {
            echo "\n<tr><td>";
            echo $this->backLink($this->start_item_id) . "\n</td></tr>";
        }
        echo "\n</table>";
    }

    function showKids ($item_id) {
        $num_kids = $this->tree->getNumKids($item_id);
        $kids = $this->tree->getKids($item_id);
        $attributes_a = $this->config->getAttributes("TreeKids", "a");
        $attributes_font = $this->config->getAttributes("TreeKids", "font");
        $attributes_td = $this->config->getAttributes("TreeKids", "td");
        echo "\n<table width=\"100%\" border=\"0\"";
        echo $this->config->getAttributes("TreeKids", "table") . ">";
        for ($i = 0; $i < $num_kids; ++$i){
            $num_entries = $this->tree->getNumEntries($kids[$i],true);
            echo "<tr>\n<td$attributes_td>";
            echo "<a href=\"" .URLHelper::getLink($this->getSelf("{$this->param}start_item_id={$kids[$i]}", false));
            echo "\"$attributes_a><font$attributes_font>";
            echo htmlReady($this->tree->tree_data[$kids[$i]]['name']);
            echo "&nbsp;($num_entries)";
            echo "</font></a>";
            echo "</td></tr>\n";
        }
        echo "</table>\n";
    }

    function backLink ($item_id) {
        if ($item_id != $this->root_id){
            echo "<table width=\"100%\" border=\"0\"";
            echo $this->config->getAttributes("TreeBackLink", "table") . ">\n";
            echo "<tr><td" . $this->config->getAttributes("TreeBackLink", "td") . ">";
            if ($image = $this->config->getValue("TreeBackLink", "image")) {
                echo "<a href=\"" .URLHelper::getLink($this->getSelf("{$this->param}start_item_id={$this->tree->tree_data[$item_id]['parent_id']}", false)) . "\">";
                echo "<img src=\"$image\" border=\"0\"></a>&nbsp;";
            }
            if ($link_text = $this->config->getValue("TreeBackLink", "linktext")) {
                echo "<a href=\"" .URLHelper::getLink($this->getSelf("{$this->param}start_item_id={$this->tree->tree_data[$item_id]['parent_id']}", false)) . "\">";
                echo "<font" . $this->config->getAttributes("TreeBackLink", "font");
                echo ">" . htmlReady($link_text) . "</font></a>";
            }
            echo "</td></tr></table>\n";
        }
    }

    function showContent ($item_id) {
        echo "<table" . $this->config->getAttributes("RangeTreeLevelName", "table");
        echo ">\n<tr><td" . $this->config->getAttributes("RangeTreeLevelName", "td") . ">";
        echo "<font" . $this->config->getAttributes("RangeTreeLevelName", "font") . ">";
        $alias_names = $this->config->getValue("RangeTreeLevelName", "aliases");
        $range_object = RangeTreeObject::GetInstance($item_id);
        if ($range_object->item_data['type'])
            $name = $alias_names[$range_object->item_data['type_num'] - 1] . " ";
        $name .= $range_object->item_data['name'];
        echo htmlReady($name) ."</font></td></tr>\n</table>\n";
        if (is_array($range_object->item_data_mapping)) {
            echo "</td></tr><tr><td>\n";
            echo "<table" . $this->config->getAttributes("RangeTreeLevelContent", "table");
            echo ">\n<tr><td" . $this->config->getAttributes("RangeTreeLevelContent", "td") . ">";
            $alias_mapping = $this->config->getValue("RangeTreeLevelContent", "mapping");
            $aliases = $this->config->getValue("RangeTreeLevelContent", "aliases");
            foreach ($alias_mapping as $position => $key) {
                if ($range_object->item_data[$key]) {
                    echo "<font" . $this->config->getAttributes("RangeTreeLevelContent", "fontalias") . ">";
                    echo htmlReady($aliases[$position]) . "&nbsp;</font>";
                    echo "<font" . $this->config->getAttributes("RangeTreeLevelContent", "fontdata") . ">";
                    echo formatLinks($range_object->item_data[$key]) . "&nbsp; </font>";
                }
            }
            echo "</td></tr></table>\n";
        }
    }

    function getSemPath () {
        $delimiter = $this->config->getValue("TreePath", "delimiter");
        $attributes_a = $this->config->getAttributes("TreePath", "a");
        $ret = "<table width=\"100%\"";
        $ret .= $this->config->getAttributes("TreePath", "table") . "><tr>\n";
        $ret .= "<td". $this->config->getAttributes("TreePath", "td") . ">";
        $ret .= "<font". $this->config->getAttributes("TreePath", "td") . ">";
        $parents = $this->tree->getParents($this->start_item_id);
        $parents_root = $this->tree->getParents($this->root_id);
        if (is_array($parents)) {
            $parents = array_diff($parents, $parents_root);
            while ($parent = array_pop($parents)) {
                $ret .= $delimiter;
                $ret .= "<a href=\"" . URLHelper::getLink($this->getSelf("{$this->param}start_item_id=".$parent,false));
                $ret .= "\"$attributes_a>" . htmlReady($this->tree->tree_data[$parent]["name"]) . "</a>";
            }
        }
        if ($this->start_item_id != $this->root_id)
            $ret .= $delimiter;
        $ret .= htmlReady($this->tree->tree_data[$this->start_item_id]["name"]);
        $ret .= "</font></td></tr></table>\n";

        return $ret;
    }



    function getSelf ($param = "", $with_start_item = true) {
        if ($param)
            $url = $_SERVER['PHP_SELF'] . (($with_start_item) ? "?start_item_id=" . $this->start_item_id . "&" : "?") . $param ;
        else
            $url = $_SERVER['PHP_SELF'] . (($with_start_item) ? "?start_item_id=" . $this->start_item_id : "") ;
        return $url;
    }
}