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

InfoController::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 19
rs 9.4285
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 InfoController extends BaseController
15
{
16
    public $controller_name = 'InfoController';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
24
25
        $lang = $this->lang;
26
27
        $action = $this->action;
28
29
        $this->printHeader($lang['strtables'].' - '.$_REQUEST['table'].' - '.$lang['strinfo']);
30
        $this->printBody();
31
32
        switch ($action) {
33
            default:
34
                $this->doDefault();
35
36
                break;
37
        }
38
39
        $this->printFooter();
40
    }
41
42
    /**
43
     * List all the information on the table.
44
     *
45
     * @param string $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
46
     *
47
     * @return string|void
48
     */
49
    public function doDefault($msg = '')
50
    {
51
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
52
53
        $lang = $this->lang;
54
        $data = $this->misc->getDatabaseAccessor();
55
56
        $this->printTrail('table');
57
        $this->printTabs('table', 'info');
58
        $this->printMsg($msg);
59
60
        // common params for printVal
61
        $shownull = ['null' => true];
62
63
        // Fetch info
64
        $referrers      = $data->getReferrers($_REQUEST['table']);
65
        $parents        = $data->getTableParents($_REQUEST['table']);
66
        $children       = $data->getTableChildren($_REQUEST['table']);
67
        $tablestatstups = $data->getStatsTableTuples($_REQUEST['table']);
68
        $tablestatsio   = $data->getStatsTableIO($_REQUEST['table']);
69
        $indexstatstups = $data->getStatsIndexTuples($_REQUEST['table']);
70
        $indexstatsio   = $data->getStatsIndexIO($_REQUEST['table']);
71
72
        // Check that there is some info
73
        if (($referrers === -99 || ($referrers !== -99 && 0 == $referrers->recordCount()))
74
            && 0 == $parents->recordCount() && 0 == $children->recordCount()
75
            && (0 == $tablestatstups->recordCount() && 0 == $tablestatsio->recordCount()
76
                && 0 == $indexstatstups->recordCount() && 0 == $indexstatsio->recordCount())) {
2 ignored issues
show
Coding Style introduced by
Multi-line IF statement not indented correctly; expected 12 spaces but found 16
Loading history...
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
77
            $this->printMsg($lang['strnoinfo']);
78
        } else {
79
            // Referring foreign tables
80
            if ($referrers !== -99 && $referrers->recordCount() > 0) {
81
                echo "<h3>{$lang['strreferringtables']}</h3>\n";
82
83
                $columns = [
84
                    'schema' => [
85
                        'title' => $lang['strschema'],
86
                        'field' => Decorator::field('nspname'),
87
                    ],
88
                    'table' => [
89
                        'title' => $lang['strtable'],
90
                        'field' => Decorator::field('relname'),
91
                    ],
92
                    'name' => [
93
                        'title' => $lang['strname'],
94
                        'field' => Decorator::field('conname'),
95
                    ],
96
                    'definition' => [
97
                        'title' => $lang['strdefinition'],
98
                        'field' => Decorator::field('consrc'),
99
                    ],
100
                    'actions' => [
101
                        'title' => $lang['stractions'],
102
                    ],
103
                ];
104
105
                $actions = [
106
                    'properties' => [
107
                        'content' => $lang['strproperties'],
108
                        'attr'    => [
109
                            'href' => [
110
                                'url'     => 'constraints.php',
111
                                'urlvars' => [
112
                                    'schema' => Decorator::field('nspname'),
113
                                    'table'  => Decorator::field('relname'),
114
                                ],
115
                            ],
116
                        ],
117
                    ],
118
                ];
119
120
                echo $this->printTable($referrers, $columns, $actions, 'info-referrers', $lang['strnodata']);
121
            }
122
123
            // Parent tables
124
            if ($parents->recordCount() > 0) {
125
                echo "<h3>{$lang['strparenttables']}</h3>\n";
126
127
                $columns = [
128
                    'schema' => [
129
                        'title' => $lang['strschema'],
130
                        'field' => Decorator::field('nspname'),
131
                    ],
132
                    'table' => [
133
                        'title' => $lang['strtable'],
134
                        'field' => Decorator::field('relname'),
135
                    ],
136
                    'actions' => [
137
                        'title' => $lang['stractions'],
138
                    ],
139
                ];
140
141
                $actions = [
142
                    'properties' => [
143
                        'content' => $lang['strproperties'],
144
                        'attr'    => [
145
                            'href' => [
146
                                'url'     => 'tblproperties.php',
147
                                'urlvars' => [
148
                                    'schema' => Decorator::field('nspname'),
149
                                    'table'  => Decorator::field('relname'),
150
                                ],
151
                            ],
152
                        ],
153
                    ],
154
                ];
155
156
                echo $this->printTable($parents, $columns, $actions, 'info-parents', $lang['strnodata']);
157
            }
158
159
            // Child tables
160
            if ($children->recordCount() > 0) {
161
                echo "<h3>{$lang['strchildtables']}</h3>\n";
162
163
                $columns = [
164
                    'schema' => [
165
                        'title' => $lang['strschema'],
166
                        'field' => Decorator::field('nspname'),
167
                    ],
168
                    'table' => [
169
                        'title' => $lang['strtable'],
170
                        'field' => Decorator::field('relname'),
171
                    ],
172
                    'actions' => [
173
                        'title' => $lang['stractions'],
174
                    ],
175
                ];
176
177
                $actions = [
178
                    'properties' => [
179
                        'content' => $lang['strproperties'],
180
                        'attr'    => [
181
                            'href' => [
182
                                'url'     => 'tblproperties.php',
183
                                'urlvars' => [
184
                                    'schema' => Decorator::field('nspname'),
185
                                    'table'  => Decorator::field('relname'),
186
                                ],
187
                            ],
188
                        ],
189
                    ],
190
                ];
191
192
                echo $this->printTable($children, $columns, $actions, 'info-children', $lang['strnodata']);
193
            }
194
195
            // Row performance
196
            if ($tablestatstups->recordCount() > 0) {
197
                echo "<h3>{$lang['strrowperf']}</h3>\n";
198
199
                echo "<table>\n";
200
                echo "\t<tr>\n";
201
                echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strsequential']}</th>\n";
202
                echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strindex']}</th>\n";
203
                echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strrows2']}</th>\n";
204
                echo "\t</tr>\n";
205
                echo "\t<tr>\n";
206
                echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
207
                echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n";
208
                echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
209
                echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n";
210
                echo "\t\t<th class=\"data\">{$lang['strinsert']}</th>\n";
211
                echo "\t\t<th class=\"data\">{$lang['strupdate']}</th>\n";
212
                echo "\t\t<th class=\"data\">{$lang['strdelete']}</th>\n";
213
                echo "\t</tr>\n";
214
                $i = 0;
215
216
                while (!$tablestatstups->EOF) {
217
                    $id = (0 == ($i % 2) ? '1' : '2');
218
                    echo "\t<tr class=\"data{$id}\">\n";
219
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_scan'], 'int4', $shownull), "</td>\n";
220
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_tup_read'], 'int4', $shownull), "</td>\n";
221
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_scan'], 'int4', $shownull), "</td>\n";
222
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_tup_fetch'], 'int4', $shownull), "</td>\n";
223
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_ins'], 'int4', $shownull), "</td>\n";
224
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_upd'], 'int4', $shownull), "</td>\n";
225
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_del'], 'int4', $shownull), "</td>\n";
226
                    echo "\t</tr>\n";
227
                    $tablestatstups->movenext();
228
                    ++$i;
229
                }
230
231
                echo "</table>\n";
232
            }
233
234
            // I/O performance
235
            if ($tablestatsio->recordCount() > 0) {
236
                echo "<h3>{$lang['strioperf']}</h3>\n";
237
238
                echo "<table>\n";
239
                echo "\t<tr>\n";
240
                echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strheap']}</th>\n";
241
                echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strindex']}</th>\n";
242
                echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoast']}</th>\n";
243
                echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoastindex']}</th>\n";
244
                echo "\t</tr>\n";
245
                echo "\t<tr>\n";
246
                echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
247
                echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
248
                echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
249
                echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
250
                echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
251
                echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
252
                echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
253
                echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
254
                echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
255
                echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
256
                echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
257
                echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
258
                echo "\t</tr>\n";
259
                $i = 0;
260
261
                while (!$tablestatsio->EOF) {
262
                    $id = (0 == ($i % 2) ? '1' : '2');
263
                    echo "\t<tr class=\"data{$id}\">\n";
264
265
                    $total = $tablestatsio->fields['heap_blks_hit'] + $tablestatsio->fields['heap_blks_read'];
266
                    if ($total > 0) {
267
                        $percentage = round(($tablestatsio->fields['heap_blks_hit'] / $total) * 100);
268
                    } else {
269
                        $percentage = 0;
270
                    }
271
272
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_read'], 'int4', $shownull), "</td>\n";
273
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_hit'], 'int4', $shownull), "</td>\n";
274
                    echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n";
275
276
                    $total = $tablestatsio->fields['idx_blks_hit'] + $tablestatsio->fields['idx_blks_read'];
277
                    if ($total > 0) {
278
                        $percentage = round(($tablestatsio->fields['idx_blks_hit'] / $total) * 100);
279
                    } else {
280
                        $percentage = 0;
281
                    }
282
283
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_read'], 'int4', $shownull), "</td>\n";
284
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_hit'], 'int4', $shownull), "</td>\n";
285
                    echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n";
286
287
                    $total = $tablestatsio->fields['toast_blks_hit'] + $tablestatsio->fields['toast_blks_read'];
288
                    if ($total > 0) {
289
                        $percentage = round(($tablestatsio->fields['toast_blks_hit'] / $total) * 100);
290
                    } else {
291
                        $percentage = 0;
292
                    }
293
294
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_read'], 'int4', $shownull), "</td>\n";
295
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_hit'], 'int4', $shownull), "</td>\n";
296
                    echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n";
297
298
                    $total = $tablestatsio->fields['tidx_blks_hit'] + $tablestatsio->fields['tidx_blks_read'];
299
                    if ($total > 0) {
300
                        $percentage = round(($tablestatsio->fields['tidx_blks_hit'] / $total) * 100);
301
                    } else {
302
                        $percentage = 0;
303
                    }
304
305
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_read'], 'int4', $shownull), "</td>\n";
306
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_hit'], 'int4', $shownull), "</td>\n";
307
                    echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n";
308
                    echo "\t</tr>\n";
309
                    $tablestatsio->movenext();
310
                    ++$i;
311
                }
312
313
                echo "</table>\n";
314
            }
315
316
            // Index row performance
317
            if ($indexstatstups->recordCount() > 0) {
318
                echo "<h3>{$lang['stridxrowperf']}</h3>\n";
319
320
                echo "<table>\n";
321
                echo "\t<tr>\n";
322
                echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n";
323
                echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
324
                echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n";
325
                echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n";
326
                echo "\t</tr>\n";
327
                $i = 0;
328
329
                while (!$indexstatstups->EOF) {
330
                    $id = (0 == ($i % 2) ? '1' : '2');
331
                    echo "\t<tr class=\"data{$id}\">\n";
332
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['indexrelname']), "</td>\n";
333
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_scan'], 'int4', $shownull), "</td>\n";
334
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_read'], 'int4', $shownull), "</td>\n";
335
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_fetch'], 'int4', $shownull), "</td>\n";
336
                    echo "\t</tr>\n";
337
                    $indexstatstups->movenext();
338
                    ++$i;
339
                }
340
341
                echo "</table>\n";
342
            }
343
344
            // Index I/0 performance
345
            if ($indexstatsio->recordCount() > 0) {
346
                echo "<h3>{$lang['stridxioperf']}</h3>\n";
347
348
                echo "<table>\n";
349
                echo "\t<tr>\n";
350
                echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n";
351
                echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
352
                echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
353
                echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
354
                echo "\t</tr>\n";
355
                $i = 0;
356
357
                while (!$indexstatsio->EOF) {
358
                    $id = (0 == ($i % 2) ? '1' : '2');
359
                    echo "\t<tr class=\"data{$id}\">\n";
360
                    $total = $indexstatsio->fields['idx_blks_hit'] + $indexstatsio->fields['idx_blks_read'];
361
                    if ($total > 0) {
362
                        $percentage = round(($indexstatsio->fields['idx_blks_hit'] / $total) * 100);
363
                    } else {
364
                        $percentage = 0;
365
                    }
366
367
                    echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['indexrelname']), "</td>\n";
368
                    echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_read'], 'int4', $shownull), "</td>\n";
369
                    echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_hit'], 'int4', $shownull), "</td>\n";
370
                    echo "\t\t<td>({$percentage}{$lang['strpercent']})</td>\n";
371
                    echo "\t</tr>\n";
372
                    $indexstatsio->movenext();
373
                    ++$i;
374
                }
375
376
                echo "</table>\n";
377
            }
378
        }
379
    }
380
}
381