Passed
Pull Request — develop (#184)
by Felipe
06:07 queued 31s
created

HTMLFooterController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
dl 0
loc 127
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setNoBottomLink() 0 5 1
A setReloadDropDatabase() 0 5 1
A setWindowName() 0 7 2
A setFocus() 0 5 1
B printFooter() 0 22 4
B printNavLinks() 0 21 5
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-beta.45
5
 */
6
7
namespace PHPPgAdmin\XHtml;
8
9
/**
10
 * Class to render tables. Formerly part of Misc.php.
11
 */
12
class HTMLFooterController extends HTMLController
13
{
14
    public $controller_name        = 'HTMLFooterController';
15
    private $_reload_drop_database = false;
16
    private $_no_bottom_link       = false;
17
18
    /**
19
     * Sets the value of $_reload_drop_database which in turn will trigger a reload in the browser frame.
20
     *
21
     * @param bool $flag sets internal $_reload_drop_database var which will be passed to the footer methods
22
     *
23
     * @return HTMLFooterController $this the instance of this class
24
     */
25
    public function setReloadDropDatabase($flag)
26
    {
27
        $this->_reload_drop_database = (bool) $flag;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Sets $_no_bottom_link boolean value.
34
     *
35
     * @param bool $flag [description]
36
     *
37
     * @return HTMLFooterController $this the instance of this class
38
     */
39
    public function setNoBottomLink($flag)
40
    {
41
        $this->_no_bottom_link = (bool) $flag;
42
43
        return $this;
44
    }
45
46
    /**
47
     * Prints the page footer.
48
     *
49
     * @param bool  $doBody   True to output body tag, false to return the html
50
     * @param mixed $template
51
     */
52
    public function printFooter($doBody = true, $template = 'footer.twig')
53
    {
54
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
55
56
        $reload_param = 'none';
57
        if ($this->misc->getReloadBrowser()) {
58
            $reload_param = 'other';
59
        } elseif ($this->_reload_drop_database) {
60
            $reload_param = 'database';
61
        }
62
63
        $this->view->offsetSet('script_footer', '');
64
        $this->view->offsetSet('reload', $reload_param);
65
        $this->view->offsetSet('footer_template', $template);
66
        $this->view->offsetSet('print_bottom_link', !$this->_no_bottom_link);
67
68
        $footer_html = $this->view->fetch($template);
69
70
        if ($doBody) {
71
            echo $footer_html;
72
        } else {
73
            return $footer_html;
74
        }
75
    }
76
77
    /**
78
     * Outputs JavaScript to set default focus.
79
     *
80
     * @param string $object eg. forms[0].username
81
     */
82
    public function setFocus($object)
83
    {
84
        echo "<script type=\"text/javascript\">\n";
85
        echo "   document.{$object}.focus();\n";
86
        echo "</script>\n";
87
    }
88
89
    /**
90
     * Outputs JavaScript to set the name of the browser window.
91
     *
92
     * @param string $name      the window name
93
     * @param bool   $addServer if true (default) then the server id is
94
     *                          attached to the name
95
     */
96
    public function setWindowName($name, $addServer = true)
97
    {
98
        echo "<script type=\"text/javascript\">\n";
99
        echo "//<![CDATA[\n";
100
        echo "   window.name = '{$name}", ($addServer ? ':'.htmlspecialchars($this->misc->getServerId()) : ''), "';\n";
101
        echo "//]]>\n";
102
        echo "</script>\n";
103
    }
104
105
    /**
106
     * Display the navlinks, below the table results.
107
     *
108
     * @param array  $navlinks An array with the the attributes and values that will be shown.
109
     *                         See printLinksList for array format.
110
     * @param string $place    Place where the $navlinks are displayed. Like 'display-browse',
111
     *                         where 'display' is the file (display) and 'browse' is the action
112
     * @param array  $env      - Associative array of defined variables in the scope of the caller.
113
     *                         Allows to give some environnement details to plugins.
114
     *                         and 'browse' is the place inside that code (doBrowse).
115
     * @param bool   $do_print if true, print html, if false, return html
116
     * @param mixed  $from     can either be null, false or the method calling this one
117
     */
118
    public function printNavLinks($navlinks, $place, $env, $do_print, $from)
119
    {
120
        if (null === $from || false === $from) {
121
            $from = __METHOD__;
122
        }
123
        //$this->prtrace($navlinks);
124
        $plugin_manager = $this->plugin_manager;
125
126
        // Navlinks hook's place
127
        $plugin_functions_parameters = [
128
            'navlinks' => &$navlinks,
129
            'place'    => $place,
130
            'env'      => $env,
131
        ];
132
        $plugin_manager->doHook('navlinks', $plugin_functions_parameters);
133
134
        if (count($navlinks) > 0) {
135
            if ($do_print) {
136
                $this->printLinksList($navlinks, 'navlink', true, $from);
137
            } else {
138
                return $this->printLinksList($navlinks, 'navlink', false, $from);
139
            }
140
        }
141
    }
142
}
143