Passed
Pull Request — develop (#92)
by Felipe
04:47
created

HelpController::doDefault()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 0
dl 0
loc 25
rs 8.5806
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
/**
10
 * Base controller class.
11
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
12
class HelpController extends BaseController
13
{
14
    public $controller_name = 'HelpController';
15
16
    /**
17
     * Default method to render the controller according to the action parameter.
18
     */
19
    public function render()
20
    {
21
        $action = $this->action;
22
23
        switch ($action) {
24
            case 'browse':
25
                $this->doBrowse();
26
27
                break;
28
            default:
29
                $this->doDefault();
30
31
                break;
32
        }
33
    }
34
35
    public function doDefault()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
36
    {
37
        $conf = $this->conf;
38
39
        $lang = $this->lang;
40
        $data = $this->misc->getDatabaseAccessor();
41
42
        if (isset($_REQUEST['help'])) {
43
            $url = $data->getHelp($_REQUEST['help']);
44
45
            \PC::debug(['url' => $url], 'HelpController::doDefault');
46
            if (is_array($url)) {
47
                $this->doChoosePage($url);
48
49
                return;
50
            }
51
52
            if ($url) {
53
                header("Location: ${url}");
54
55
                return;
56
            }
57
        }
58
59
        $this->doBrowse($lang['strinvalidhelppage']);
60
    }
61
62
    public function doBrowse($msg = '')
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
63
    {
64
        $conf = $this->conf;
65
66
        $lang = $this->lang;
67
        $data = $this->misc->getDatabaseAccessor();
68
69
        $this->printHeader($lang['strhelppagebrowser']);
70
        $this->printBody();
71
72
        $this->printTitle($lang['strselecthelppage']);
73
74
        echo $this->printMsg($msg);
75
76
        echo "<dl>\n";
77
78
        $pages = $data->getHelpPages();
79
        foreach ($pages as $page => $dummy) {
80
            echo "<dt>{$page}</dt>\n";
81
82
            $urls = $data->getHelp($page);
83
            if (!is_array($urls)) {
84
                $urls = [$urls];
85
            }
86
87
            foreach ($urls as $url) {
88
                echo "<dd><a href=\"{$url}\">{$url}</a></dd>\n";
89
            }
90
        }
91
92
        echo "</dl>\n";
93
94
        $this->printFooter();
95
    }
96
97
    public function doChoosePage($urls)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
98
    {
99
        $conf = $this->conf;
100
101
        $lang = $this->lang;
102
        $data = $this->misc->getDatabaseAccessor();
103
104
        $this->printHeader($lang['strhelppagebrowser']);
105
        $this->printBody();
106
107
        $this->printTitle($lang['strselecthelppage']);
108
109
        echo "<ul>\n";
110
        foreach ($urls as $url) {
111
            echo "<li><a href=\"{$url}\">{$url}</a></li>\n";
112
        }
113
        echo "</ul>\n";
114
115
        $this->printFooter();
116
    }
117
}
118