1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("Services/Block/classes/class.ilBlockGUI.php");
6
7/**
8 * Important pages wiki block
9 *
10 * @author Alex Killing <alex.killing@gmx.de>
11 * @version $Id$
12 *
13 * @ingroup ModulesWiki
14 */
15class ilWikiImportantPagesBlockGUI extends ilBlockGUI
16{
17    public static $block_type = "wikiimppages";
18    public static $st_data;
19    protected $export = false;
20
21    /**
22    * Constructor
23    */
24    public function __construct()
25    {
26        global $DIC;
27
28        $this->ctrl = $DIC->ctrl();
29        $this->lng = $DIC->language();
30        $this->access = $DIC->access();
31        $ilCtrl = $DIC->ctrl();
32        $lng = $DIC->language();
33
34        parent::__construct();
35
36        $lng->loadLanguageModule("wiki");
37        $this->setEnableNumInfo(false);
38
39        $this->setTitle($lng->txt("wiki_navigation"));
40        $this->allow_moving = false;
41    }
42
43    /**
44     * @inheritdoc
45     */
46    public function getBlockType() : string
47    {
48        return self::$block_type;
49    }
50
51    /**
52     * @inheritdoc
53     */
54    protected function isRepositoryObject() : bool
55    {
56        return false;
57    }
58
59    /**
60    * Get Screen Mode for current command.
61    */
62    public static function getScreenMode()
63    {
64        return IL_SCREEN_SIDE;
65    }
66
67    /**
68    * execute command
69    */
70    public function executeCommand()
71    {
72        $ilCtrl = $this->ctrl;
73
74        $next_class = $ilCtrl->getNextClass();
75        $cmd = $ilCtrl->getCmd("getHTML");
76
77        switch ($next_class) {
78            default:
79                return $this->$cmd();
80        }
81    }
82
83    /**
84    * Get bloch HTML code.
85    */
86    public function getHTML($a_export = false)
87    {
88        $ilCtrl = $this->ctrl;
89        $lng = $this->lng;
90
91        $this->export = $a_export;
92
93        include_once './Modules/Wiki/classes/class.ilWikiPerm.php';
94        if (!$this->export && ilWikiPerm::check("edit_wiki_navigation", $_GET["ref_id"])) {
95            $this->addBlockCommand(
96                $ilCtrl->getLinkTargetByClass("ilobjwikigui", "editImportantPages"),
97                $lng->txt("edit")
98            );
99        }
100
101        return parent::getHTML();
102    }
103
104    /**
105     * Fill data section
106     */
107    public function fillDataSection()
108    {
109        $this->setDataSection($this->getLegacyContent());
110    }
111
112    //
113    // New rendering
114    //
115
116    protected $new_rendering = true;
117
118
119    /**
120     * @inheritdoc
121     */
122    protected function getLegacyContent() : string
123    {
124        $ilCtrl = $this->ctrl;
125        $lng = $this->lng;
126        $ilAccess = $this->access;
127
128        $tpl = new ilTemplate("tpl.wiki_imp_pages_block.html", true, true, "Modules/Wiki");
129
130        $cpar[0] = $cpar[1] = 0;
131        include_once("./Services/UIComponent/NestedList/classes/class.ilNestedList.php");
132
133        $list = new ilNestedList();
134        $list->setItemClass("ilWikiBlockItem");
135        $list->setListClass("ilWikiBlockList");
136        $list->setListClass("ilWikiBlockListNoIndent", 1);
137
138        $cnt = 1;
139        $title = ilObjWiki::_lookupStartPage(ilObject::_lookupObjId($_GET["ref_id"]));
140        if (!$this->export) {
141            $list->addListNode("<p class='small'><a href='" .
142                $ilCtrl->getLinkTargetByClass("ilobjwikigui", "gotoStartPage")
143                . "'>" . $title . "</a></p>", 1, 0);
144        } else {
145            $list->addListNode("<p class='small'><a href='" .
146                "index.html" .
147                "'>" . $title . "</a></p>", 1, 0);
148        }
149        $cpar[0] = 1;
150
151        $ipages = ilObjWiki::_lookupImportantPagesList(ilObject::_lookupObjId($_GET["ref_id"]));
152        foreach ($ipages as $p) {
153            $cnt++;
154            $title = ilWikiPage::lookupTitle($p["page_id"]);
155            if (!$this->export) {
156                $list->addListNode("<p class='small'><a href='" .
157                    ilObjWikiGUI::getGotoLink($_GET["ref_id"], $title)
158                    . "'>" . $title . "</a></p>", $cnt, (int) $cpar[$p["indent"] - 1]);
159            } else {
160                $list->addListNode("<p class='small'><a href='" .
161                    "wpg_" . $p["page_id"] . ".html" .
162                    "'>" . $title . "</a></p>", $cnt, (int) $cpar[$p["indent"] - 1]);
163            }
164            $cpar[$p["indent"]] = $cnt;
165        }
166
167        return $list->getHTML();
168    }
169}
170