Passed
Push — master ( 442876...4ec1bc )
by Felipe
15:55 queued 10:33
created

OperatorsController::doTree()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 28
rs 8.8571
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
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 */
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...
14
class OperatorsController extends BaseController
15
{
16
    public $controller_name = 'OperatorsController';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        $lang = $this->lang;
24
25
        $action = $this->action;
26
        if ('tree' == $action) {
27
            return $this->doTree();
28
        }
29
30
        $this->printHeader($lang['stroperators']);
31
        $this->printBody();
32
33
        switch ($action) {
34
            case 'save_create':
35
                if (isset($_POST['cancel'])) {
36
                    $this->doDefault();
37
                } else {
38
                    $this->doSaveCreate();
0 ignored issues
show
Bug introduced by
The method doSaveCreate() does not exist on PHPPgAdmin\Controller\OperatorsController. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
                    $this->/** @scrutinizer ignore-call */ 
39
                           doSaveCreate();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
                }
40
41
                break;
42
            case 'create':
43
                doCreate();
0 ignored issues
show
Bug introduced by
The function doCreate was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
                /** @scrutinizer ignore-call */ 
44
                doCreate();
Loading history...
44
45
                break;
46
            case 'drop':
47
                if (isset($_POST['cancel'])) {
48
                    $this->doDefault();
49
                } else {
50
                    $this->doDrop(false);
51
                }
52
53
                break;
54
            case 'confirm_drop':
55
                $this->doDrop(true);
56
57
                break;
58
            case 'properties':
59
                $this->doProperties();
60
61
                break;
62
            default:
63
                $this->doDefault();
64
65
                break;
66
        }
67
68
        $this->printFooter();
69
    }
70
71
    /**
72
     * Generate XML for the browser tree.
73
     */
74
    public function doTree()
75
    {
76
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
77
        $data = $this->misc->getDatabaseAccessor();
78
79
        $operators = $data->getOperators();
80
81
        // Operator prototype: "type operator type"
82
        $proto = Decorator::concat(Decorator::field('oprleftname'), ' ', Decorator::field('oprname'), ' ', Decorator::field('oprrightname'));
83
84
        $reqvars = $this->misc->getRequestVars('operator');
85
86
        $attrs = [
87
            'text'    => $proto,
88
            'icon'    => 'Operator',
89
            'toolTip' => Decorator::field('oprcomment'),
90
            'action'  => Decorator::actionurl(
91
                'operators.php',
92
                $reqvars,
93
                [
94
                    'action'       => 'properties',
95
                    'operator'     => $proto,
96
                    'operator_oid' => Decorator::field('oid'),
97
                ]
98
            ),
99
        ];
100
101
        return $this->printTree($operators, $attrs, 'operators');
102
    }
103
104
    /**
105
     * Show default list of operators in the database.
106
     *
107
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
108
     */
109
    public function doDefault($msg = '')
110
    {
111
        $lang = $this->lang;
112
        $data = $this->misc->getDatabaseAccessor();
113
114
        $this->printTrail('schema');
115
        $this->printTabs('schema', 'operators');
116
        $this->printMsg($msg);
117
118
        $operators = $data->getOperators();
119
120
        $columns = [
121
            'operator' => [
122
                'title' => $lang['stroperator'],
123
                'field' => Decorator::field('oprname'),
124
                'url'   => "operators.php?action=properties&amp;{$this->misc->href}&amp;",
125
                'vars'  => ['operator' => 'oprname', 'operator_oid' => 'oid'],
126
            ],
127
            'leftarg'  => [
128
                'title' => $lang['strleftarg'],
129
                'field' => Decorator::field('oprleftname'),
130
            ],
131
            'rightarg' => [
132
                'title' => $lang['strrightarg'],
133
                'field' => Decorator::field('oprrightname'),
134
            ],
135
            'returns'  => [
136
                'title' => $lang['strreturns'],
137
                'field' => Decorator::field('resultname'),
138
            ],
139
            'actions'  => [
140
                'title' => $lang['stractions'],
141
            ],
142
            'comment'  => [
143
                'title' => $lang['strcomment'],
144
                'field' => Decorator::field('oprcomment'),
145
            ],
146
        ];
147
148
        $actions = [
149
            'drop' => [
150
                // 'title' => $lang['strdrop'],
151
                // 'url'   => "operators.php?action=confirm_drop&amp;{$this->misc->href}&amp;",
152
                // 'vars'  => array('operator' => 'oprname', 'operator_oid' => 'oid'),
153
                'content' => $lang['strdrop'],
154
                'attr'    => [
155
                    'href' => [
156
                        'url'     => 'operators.php',
157
                        'urlvars' => [
158
                            'action'       => 'confirm_drop',
159
                            'operator'     => Decorator::field('oprname'),
160
                            'operator_oid' => Decorator::field('oid'),
161
                        ],
162
                    ],
163
                ],
164
            ],
165
        ];
166
167
        echo $this->printTable($operators, $columns, $actions, 'operators-operators', $lang['strnooperators']);
168
169
        //        TODO operators.php action=create $lang['strcreateoperator']
170
    }
171
172
    /**
173
     * Show read only properties for an operator.
174
     *
175
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
176
     */
177
    public function doProperties($msg = '')
178
    {
179
        $lang = $this->lang;
180
        $data = $this->misc->getDatabaseAccessor();
181
182
        $this->printTrail('operator');
183
        $this->printTitle($lang['strproperties'], 'pg.operator');
184
        $this->printMsg($msg);
185
186
        $oprdata                       = $data->getOperator($_REQUEST['operator_oid']);
187
        $oprdata->fields['oprcanhash'] = $data->phpBool($oprdata->fields['oprcanhash']);
188
189
        if ($oprdata->recordCount() > 0) {
190
            echo "<table>\n";
191
            echo "<tr><th class=\"data left\">{$lang['strname']}</th>\n";
192
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprname']), "</td></tr>\n";
193
            echo "<tr><th class=\"data left\">{$lang['strleftarg']}</th>\n";
194
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprleftname']), "</td></tr>\n";
195
            echo "<tr><th class=\"data left\">{$lang['strrightarg']}</th>\n";
196
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrightname']), "</td></tr>\n";
197
            echo "<tr><th class=\"data left\">{$lang['strcommutator']}</th>\n";
198
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprcom']), "</td></tr>\n";
199
            echo "<tr><th class=\"data left\">{$lang['strnegator']}</th>\n";
200
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprnegate']), "</td></tr>\n";
201
            echo "<tr><th class=\"data left\">{$lang['strjoin']}</th>\n";
202
            echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprjoin']), "</td></tr>\n";
203
            echo "<tr><th class=\"data left\">{$lang['strhashes']}</th>\n";
204
            echo '<td class="data1">', ($oprdata->fields['oprcanhash']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
205
206
            // these field only exists in 8.2 and before in pg_catalog
207
            if (isset($oprdata->fields['oprlsortop'])) {
208
                echo "<tr><th class=\"data left\">{$lang['strmerges']}</th>\n";
209
                echo '<td class="data1">', ('0' !== $oprdata->fields['oprlsortop'] && '0' !== $oprdata->fields['oprrsortop']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
210
                echo "<tr><th class=\"data left\">{$lang['strrestrict']}</th>\n";
211
                echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrest']), "</td></tr>\n";
212
                echo "<tr><th class=\"data left\">{$lang['strleftsort']}</th>\n";
213
                echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprlsortop']), "</td></tr>\n";
214
                echo "<tr><th class=\"data left\">{$lang['strrightsort']}</th>\n";
215
                echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrsortop']), "</td></tr>\n";
216
                echo "<tr><th class=\"data left\">{$lang['strlessthan']}</th>\n";
217
                echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprltcmpop']), "</td></tr>\n";
218
                echo "<tr><th class=\"data left\">{$lang['strgreaterthan']}</th>\n";
219
                echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprgtcmpop']), "</td></tr>\n";
220
            } else {
221
                echo "<tr><th class=\"data left\">{$lang['strmerges']}</th>\n";
222
                echo '<td class="data1">', $data->phpBool($oprdata->fields['oprcanmerge']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
223
            }
224
            echo "</table>\n";
225
226
            $this->printNavLinks(
227
                [
228
                    'showall' => [
229
                        'attr'    => [
230
                            'href' => [
231
                                'url'     => 'operators.php',
232
                                'urlvars' => [
233
                                    'server'   => $_REQUEST['server'],
234
                                    'database' => $_REQUEST['database'],
235
                                    'schema'   => $_REQUEST['schema'],
236
                                ],
237
                            ],
238
                        ],
239
                        'content' => $lang['strshowalloperators'],
240
                    ]],
241
                'operators-properties',
242
                get_defined_vars()
243
            );
244
        } else {
245
            $this->doDefault($lang['strinvalidparam']);
246
        }
247
    }
248
249
    /**
250
     * Show confirmation of drop and perform actual drop.
251
     *
252
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
253
     */
254
    public function doDrop($confirm)
255
    {
256
        $lang = $this->lang;
257
        $data = $this->misc->getDatabaseAccessor();
258
259
        if ($confirm) {
260
            $this->printTrail('operator');
261
            $this->printTitle($lang['strdrop'], 'pg.operator.drop');
262
263
            echo '<p>', sprintf($lang['strconfdropoperator'], $this->misc->printVal($_REQUEST['operator'])), "</p>\n";
264
265
            echo '<form action="' . \SUBFOLDER . "/src/views/operators.php\" method=\"post\">\n";
266
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
267
            echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
268
            echo '<input type="hidden" name="operator" value="', htmlspecialchars($_REQUEST['operator']), "\" />\n";
269
            echo '<input type="hidden" name="operator_oid" value="', htmlspecialchars($_REQUEST['operator_oid']), "\" />\n";
270
            echo $this->misc->form;
271
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
272
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
273
            echo "</form>\n";
274
        } else {
275
            $status = $data->dropOperator($_POST['operator_oid'], isset($_POST['cascade']));
276
            if (0 == $status) {
277
                $this->doDefault($lang['stroperatordropped']);
278
            } else {
279
                $this->doDefault($lang['stroperatordroppedbad']);
280
            }
281
        }
282
    }
283
}
284