1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6 * tree explorer lm public area
7 *
8 * @author Fabian Wolf <wolf@leifos.com>
9 * @version $Id$
10 *
11 * @ingroup ModulesLearningModule
12 */
13class ilPublicSectionExplorerGUI extends ilTreeExplorerGUI
14{
15    public $exp_id = "public_section";
16
17    /**
18     * constructor
19     *
20     * @param object $a_parent_obj
21     * @param string $a_parent_cmd
22     * @param ilObjLearningModule $a_lm
23     */
24    public function __construct($a_parent_obj, $a_parent_cmd, $a_lm)
25    {
26        $this->lm = $a_lm;
27
28        $tree = ilLMTree::getInstance($this->lm->getId());
29
30        parent::__construct("lm_public_section_" . $this->lm->getId(), $a_parent_obj, $a_parent_cmd, $tree);
31    }
32
33    /**
34     * get node content
35     *
36     * @param mixed $a_node
37     * @return string note name
38     */
39    public function getNodeContent($a_node)
40    {
41        $lang = ($_GET["transl"] != "")
42            ? $_GET["transl"]
43            : "-";
44        return ilLMObject::_getPresentationTitle(
45            $a_node,
46            ilLMObject::PAGE_TITLE,
47            $this->lm->isActiveNumbering(),
48            false,
49            false,
50            $this->lm->getId(),
51            $lang
52        );
53    }
54
55    /**
56     * Get node icon
57     *
58     * @param array $a_node node array
59     * @return string icon path
60     */
61    public function getNodeIcon($a_node)
62    {
63        if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
64            $icon = ilUtil::getImagePath("icon_lm.svg");
65        } else {
66            $a_name = "icon_" . $a_node["type"] . ".svg";
67            if ($a_node["type"] == "pg") {
68                $lm_set = new ilSetting("lm");
69                $active = ilLMPage::_lookupActive(
70                    $a_node["child"],
71                    $this->lm->getType(),
72                    $lm_set->get("time_scheduled_page_activation")
73                );
74
75                // is page scheduled?
76                $img_sc = ($lm_set->get("time_scheduled_page_activation") &&
77                    ilLMPage::_isScheduledActivation($a_node["child"], $this->lm->getType()))
78                    ? "_sc"
79                    : "";
80
81                $a_name = "icon_pg" . $img_sc . ".svg";
82
83                if (!$active) {
84                    $a_name = "icon_pg_d" . $img_sc . ".svg";
85                } else {
86                    $contains_dis = ilLMPage::_lookupContainsDeactivatedElements(
87                        $a_node["child"],
88                        $this->lm->getType()
89                    );
90                    if ($contains_dis) {
91                        $a_name = "icon_pg_del" . $img_sc . ".svg";
92                    }
93                }
94            }
95            $icon = ilUtil::getImagePath($a_name);
96        }
97
98        return $icon;
99    }
100
101    /**
102     * select public pages and open public chapter
103     */
104    public function beforeRendering()
105    {
106        //select public pages and open public chapters
107        foreach ($this->getAllNodes() as $node) {
108            if ($node["public_access"] == "y" && $node["type"] == "pg") {
109                $this->setNodeSelected($node["obj_id"]);
110            }
111            if ($node["public_access"] == "y" && $node["type"] == "st") {
112                $this->setNodeOpen($node["obj_id"]);
113            }
114        }
115    }
116
117    /**
118     * Returns all nodes from tree recursive
119     *
120     * @param mixed $from_id
121     * @return array nodes
122     */
123    protected function getAllNodes($from_id = null)
124    {
125        $nodes = array();
126
127        if ($from_id === null) {
128            $from_id = $this->getNodeId($this->getRootNode());
129        }
130
131        foreach ($this->getChildsOfNode($from_id) as $node) {
132            $nodes[] = $node;
133
134            if ($node["type"] == "st") {
135                $nodes = array_merge($nodes, $this->getAllNodes($node["obj_id"]));
136            }
137        }
138        return $nodes;
139    }
140
141    /**
142     * Is not clickable?
143     *
144     * @param array $a_node node array
145     * @return bool
146     */
147    public function isNodeClickable($a_node)
148    {
149        if ($a_node["type"] == "pg") {
150            return true;
151        }
152        return false;
153    }
154}
155