Passed
Push — develop ( 2969a7...df24bb )
by Felipe
05:41 queued 11s
created

HTMLFooterController::printFooter()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 20
rs 9.7998
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-RC6
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
        $reload_param = 'none';
55
        if ($this->misc->getReloadBrowser()) {
56
            $reload_param = 'other';
57
        } elseif ($this->_reload_drop_database) {
58
            $reload_param = 'database';
59
        }
60
61
        $this->view->offsetSet('script_footer', '');
62
        $this->view->offsetSet('reload', $reload_param);
63
        $this->view->offsetSet('footer_template', $template);
64
        $this->view->offsetSet('print_bottom_link', !$this->_no_bottom_link);
65
66
        $footer_html = $this->view->fetch($template);
67
68
        if ($doBody) {
69
            echo $footer_html;
70
        } else {
71
            return $footer_html;
72
        }
73
    }
74
75
    /**
76
     * Outputs JavaScript to set default focus.
77
     *
78
     * @param string $object eg. forms[0].username
79
     */
80
    public function setFocus($object)
81
    {
82
        echo '<script type="text/javascript">'.PHP_EOL;
83
        echo "   document.{$object}.focus();\n";
84
        echo '</script>'.PHP_EOL;
85
    }
86
87
    /**
88
     * Outputs JavaScript to set the name of the browser window.
89
     *
90
     * @param string $name      the window name
91
     * @param bool   $addServer if true (default) then the server id is
92
     *                          attached to the name
93
     */
94
    public function setWindowName($name, $addServer = true)
95
    {
96
        echo '<script type="text/javascript">'.PHP_EOL;
97
        echo "//<![CDATA[\n";
98
        echo "   window.name = '{$name}", ($addServer ? ':'.htmlspecialchars($this->misc->getServerId()) : ''), "';\n";
99
        echo '//]]>'.PHP_EOL;
100
        echo '</script>'.PHP_EOL;
101
    }
102
103
    /**
104
     * Display the navlinks, below the table results.
105
     *
106
     * @param array  $navlinks An array with the the attributes and values that will be shown.
107
     *                         See printLinksList for array format.
108
     * @param string $place    Place where the $navlinks are displayed. Like 'display-browse',
109
     *                         where 'display' is the file (display) and 'browse' is the action
110
     * @param array  $env      - Associative array of defined variables in the scope of the caller.
111
     *                         Allows to give some environnement details to plugins.
112
     *                         and 'browse' is the place inside that code (doBrowse).
113
     * @param bool   $do_print if true, print html, if false, return html
114
     * @param mixed  $from     can either be null, false or the method calling this one
115
     */
116
    public function printNavLinks($navlinks, $place, $env, $do_print, $from)
117
    {
118
        if (null === $from || false === $from) {
119
            $from = __METHOD__;
120
        }
121
        //$this->prtrace($navlinks);
122
        $plugin_manager = $this->plugin_manager;
123
124
        // Navlinks hook's place
125
        $plugin_functions_parameters = [
126
            'navlinks' => &$navlinks,
127
            'place'    => $place,
128
            'env'      => $env,
129
        ];
130
        $plugin_manager->doHook('navlinks', $plugin_functions_parameters);
131
132
        if (count($navlinks) > 0) {
133
            if ($do_print) {
134
                $this->printLinksList($navlinks, 'navlink', true, $from);
135
            } else {
136
                return $this->printLinksList($navlinks, 'navlink', false, $from);
137
            }
138
        }
139
    }
140
}
141