Passed
Pull Request — master (#267)
by Felipe
07:20
created

MiscTrait::getTabsSchema()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 118
Code Lines 98

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 98
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 118
rs 8.0436

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-RC9-3-gd93ec300
5
 */
6
7
namespace PHPPgAdmin\Traits;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * @file
13
 * A trait to deal with nav tabs
14
 */
15
16
/**
17
 * A trait to deal with nav tabs.
18
 */
19
trait MiscTrait
20
{
21
    public function getSubjectParams($subject)
22
    {
23
        $vars          = [];
24
        $common_params = [];
25
26
        if (\array_key_exists('server', $_REQUEST)) {
27
            $common_params['server'] = $_REQUEST['server'];
28
        }
29
30
        if (\array_key_exists('database', $_REQUEST)) {
31
            $common_params['database'] = $_REQUEST['database'];
32
        }
33
34
        if (\array_key_exists('schema', $_REQUEST)) {
35
            $common_params['schema'] = $_REQUEST['schema'];
36
        }
37
38
        switch ($subject) {
39
            case 'root':
40
                $vars = [
41
                    'params' => [
42
                        'subject' => 'root',
43
                    ],
44
                ];
45
46
                break;
47
            case 'server':
48
                $vars = ['params' => [
49
                    'subject' => 'server',
50
                    'server'  => $_REQUEST['server'],
51
                ]];
52
53
                break;
54
            case 'role':
55
                $vars = ['params' => [
56
                    'subject'  => 'role',
57
                    'server'   => $_REQUEST['server'],
58
                    'action'   => 'properties',
59
                    'rolename' => $_REQUEST['rolename'],
60
                ]];
61
62
                break;
63
            case 'database':
64
                $vars = ['params' => \array_merge($common_params, [
65
                    'subject' => 'database',
66
                ])];
67
68
                break;
69
            case 'schema':
70
                $vars = ['params' => \array_merge($common_params, [
71
                    'subject' => 'schema',
72
                ])];
73
74
                break;
75
            case 'table':
76
                $vars = ['params' => \array_merge($common_params, [
77
                    'subject' => 'table',
78
79
                    'table'   => $_REQUEST['table'],
80
                ])];
81
82
                break;
83
            case 'selectrows':
84
                $vars = [
85
                    'url'    => 'tables',
86
                    'params' => \array_merge($common_params, [
87
                        'subject' => 'table',
88
                        'table'   => $_REQUEST['table'],
89
                        'action'  => 'confselectrows',
90
                    ])];
91
92
                break;
93
            case 'view':
94
                $vars = ['params' => \array_merge($common_params, [
95
                    'subject' => 'view',
96
                    'view'    => $_REQUEST['view'],
97
                ])];
98
99
                break;
100
            case 'matview':
101
                $vars = ['params' => \array_merge($common_params, [
102
                    'subject' => 'matview',
103
                    'matview' => $_REQUEST['matview'],
104
                ])];
105
106
                break;
107
            case 'fulltext':
108
            case 'ftscfg':
109
                $vars = ['params' => \array_merge($common_params, [
110
                    'subject' => 'fulltext',
111
                    'action'  => 'viewconfig',
112
                    'ftscfg'  => $_REQUEST['ftscfg'],
113
                ])];
114
115
                break;
116
            case 'function':
117
                $vars = ['params' => \array_merge($common_params, [
118
                    'subject'      => 'function',
119
                    'function'     => $_REQUEST['function'],
120
                    'function_oid' => $_REQUEST['function_oid'],
121
                ])];
122
123
                break;
124
            case 'aggregate':
125
                $vars = ['params' => \array_merge($common_params, [
126
                    'subject'  => 'aggregate',
127
                    'action'   => 'properties',
128
                    'aggrname' => $_REQUEST['aggrname'],
129
                    'aggrtype' => $_REQUEST['aggrtype'],
130
                ])];
131
132
                break;
133
            case 'column':
134
                if (isset($_REQUEST['table'])) {
135
                    $vars = ['params' => \array_merge($common_params, [
136
                        'subject' => 'column',
137
138
                        'table'   => $_REQUEST['table'],
139
                        'column'  => $_REQUEST['column'],
140
                    ])];
141
                } elseif (isset($_REQUEST['view'])) {
142
                    $vars = ['params' => \array_merge($common_params, [
143
                        'subject' => 'column',
144
145
                        'view'    => $_REQUEST['view'],
146
                        'column'  => $_REQUEST['column'],
147
                    ])];
148
                } elseif (isset($_REQUEST['matview'])) {
149
                    $vars = ['params' => \array_merge($common_params, [
150
                        'subject' => 'column',
151
152
                        'matview' => $_REQUEST['matview'],
153
                        'column'  => $_REQUEST['column'],
154
                    ])];
155
                }
156
157
                break;
158
159
            default:
160
                return false;
161
        }
162
163
        if (!isset($vars['url'])) {
164
            $vars['url'] = self::SUBFOLDER . '/redirect';
0 ignored issues
show
Bug introduced by
The constant PHPPgAdmin\Traits\MiscTrait::SUBFOLDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
165
        }
166
167
        if (self::SUBFOLDER . '/redirect' === $vars['url'] && isset($vars['params']['subject'])) {
168
            $vars['url'] = self::SUBFOLDER . '/redirect/' . $vars['params']['subject'];
169
            unset($vars['params']['subject']);
170
        }
171
172
        return $vars;
173
    }
174
175
    public function maybeClipStr($str, $params)
176
    {
177
        if (isset($params['map'], $params['map'][$str])) {
178
            $str = $params['map'][$str];
179
        }
180
        // Clip the value if the 'clip' parameter is true.
181
        if (!isset($params['clip']) || true !== $params['clip']) {
182
            return $str;
183
        }
184
        $maxlen   = isset($params['cliplen']) && \is_int($params['cliplen']) ? $params['cliplen'] : $this->conf['max_chars'];
185
        $ellipsis = $params['ellipsis'] ?? $this->lang['strellipsis'];
186
187
        if (\mb_strlen($str) > $maxlen) {
188
            $str = \mb_substr($str, 0, $maxlen - 1) . $ellipsis;
189
        }
190
191
        return $str;
192
    }
193
194
    public function printBoolean($type, &$str, $params)
195
    {
196
        $lang = $this->lang;
197
198
        if ('yesno' === $type) {
199
            $this->coalesceArr($params, 'true', $lang['stryes']);
200
            $this->coalesceArr($params, 'false', $lang['strno']);
201
        }
202
203
        if (\is_bool($str)) {
204
            $str = $str ? 't' : 'f';
205
        }
206
207
        switch ($str) {
208
            case 't':
209
                $out   = ($params['true'] ?? $lang['strtrue']);
210
                $align = 'center';
211
212
                break;
213
            case 'f':
214
                $out   = ($params['false'] ?? $lang['strfalse']);
215
                $align = 'center';
216
217
                break;
218
219
            default:
220
                $align = null;
221
                $out   = \htmlspecialchars($str);
222
        }
223
224
        return [$str, $align, $out];
225
    }
226
227
    /**
228
     * Render a value into HTML using formatting rules specified
229
     * by a type name and parameters.
230
     *
231
     * @param null|string $str    The string to change
232
     * @param string      $type   Field type (optional), this may be an internal PostgreSQL type, or:
233
     *                            yesno    - same as bool, but renders as 'Yes' or 'No'.
234
     *                            pre      - render in a <pre> block.
235
     *                            nbsp     - replace all spaces with &nbsp;'s
236
     *                            verbatim - render exactly as supplied, no escaping what-so-ever.
237
     *                            callback - render using a callback function supplied in the 'function' param.
238
     * @param array       $params Type parameters (optional), known parameters:
239
     *                            null     - string to display if $str is null, or set to TRUE to use a default 'NULL' string,
240
     *                            otherwise nothing is rendered.
241
     *                            clip     - if true, clip the value to a fixed length, and append an ellipsis...
242
     *                            cliplen  - the maximum length when clip is enabled (defaults to $conf['max_chars'])
243
     *                            ellipsis - the string to append to a clipped value (defaults to $lang['strellipsis'])
244
     *                            tag      - an HTML element name to surround the value.
245
     *                            class    - a class attribute to apply to any surrounding HTML element.
246
     *                            align    - an align attribute ('left','right','center' etc.)
247
     *                            true     - (type='bool') the representation of true.
248
     *                            false    - (type='bool') the representation of false.
249
     *                            function - (type='callback') a function name, accepts args ($str, $params) and returns a rendering.
250
     *                            lineno   - prefix each line with a line number.
251
     *                            map      - an associative array.
252
     *
253
     * @return string The HTML rendered value
254
     */
255
    public function printVal($str, $type = null, $params = [])
256
    {
257
        $lang = $this->lang;
258
259
        if (null === $this->_data) {
260
            $data = $this->getDatabaseAccessor();
261
        } else {
262
            $data = $this->_data;
263
        }
264
265
        // Shortcircuit for a NULL value
266
        if (null === $str) {
267
            return isset($params['null'])
268
            ? (true === $params['null'] ? '<i>NULL</i>' : $params['null'])
269
            : '';
270
        }
271
272
        $str = $this->maybeClipStr($str, $params);
273
274
        $out   = '';
275
        $class = '';
276
277
        switch ($type) {
278
            case 'int2':
279
            case 'int4':
280
            case 'int8':
281
            case 'float4':
282
            case 'float8':
283
            case 'money':
284
            case 'numeric':
285
            case 'oid':
286
            case 'xid':
287
            case 'cid':
288
            case 'tid':
289
                $align = 'right';
290
                $out   = \nl2br(\htmlspecialchars(\PHPPgAdmin\Traits\HelperTrait::br2ln($str)));
291
292
                break;
293
            case 'yesno':
294
            case 'bool':
295
            case 'boolean':
296
                [$str, $align, $out] = $this->printBoolean($type, $str, $params);
297
298
                break;
299
            case 'bytea':
300
                $tag   = 'div';
301
                $class = 'pre';
302
                $out   = $data->escapeBytea($str);
303
304
                break;
305
            case 'errormsg':
306
                $tag   = 'pre';
307
                $class = 'error';
308
                $out   = \htmlspecialchars($str);
309
310
                break;
311
            case 'pre':
312
                $tag = 'pre';
313
                $out = \htmlspecialchars($str);
314
315
                break;
316
            case 'prenoescape':
317
                $tag = 'pre';
318
                $out = $str;
319
320
                break;
321
            case 'nbsp':
322
                $out = \nl2br(\str_replace(' ', '&nbsp;', \PHPPgAdmin\Traits\HelperTrait::br2ln($str)));
323
324
                break;
325
            case 'verbatim':
326
                $out = $str;
327
328
                break;
329
            case 'callback':
330
                $out = $params['function']($str, $params);
331
332
                break;
333
            case 'prettysize':
334
                $out = \PHPPgAdmin\Traits\HelperTrait::formatSizeUnits($str, $lang);
335
336
                break;
337
338
            default:
339
                // If the string contains at least one instance of >1 space in a row, a tab
340
                // character, a space at the start of a line, or a space at the start of
341
                // the whole string then render within a pre-formatted element (<pre>).
342
                if (\preg_match('/(^ |  |\t|\n )/m', $str)) {
343
                    $tag   = 'pre';
344
                    $class = 'data';
345
                    $out   = \htmlspecialchars($str);
346
                } else {
347
                    //$tag = 'span';
348
                    $out = \nl2br(\htmlspecialchars(\PHPPgAdmin\Traits\HelperTrait::br2ln($str)));
349
                }
350
        }
351
352
        $this->adjustClassAlignTag($class, $align, $tag, $out, $params);
353
354
        return $out;
355
    }
356
357
    public function adjustClassAlignTag(&$class, &$align, &$tag, &$out, $params): void
358
    {
359
        if (isset($params['class'])) {
360
            $class = $params['class'];
361
        }
362
363
        if (isset($params['align'])) {
364
            $align = $params['align'];
365
        }
366
367
        if (!isset($tag) && (!empty($class) || isset($align))) {
368
            $tag = 'div';
369
        }
370
371
        if (isset($tag)) {
372
            $alignattr = isset($align) ? " style=\"text-align: {$align}\"" : '';
373
            $classattr = !empty($class) ? " class=\"{$class}\"" : '';
374
            $out       = "<{$tag}{$alignattr}{$classattr}>{$out}</{$tag}>";
375
        }
376
    }
377
378
    /**
379
     * Gets the tabs for root view.
380
     *
381
     * @param \PHPPgAdmin\Database\ADOdbBase $data The database accesor instance
382
     *
383
     * @return array The tabs for root view
384
     */
385
    public function getTabsRoot($data)
386
    {
387
        $lang = $this->lang;
388
389
        return [
390
            'intro'   => [
391
                'title' => $lang['strintroduction'],
392
                'url'   => 'intro',
393
                'icon'  => 'Introduction',
394
            ],
395
            'servers' => [
396
                'title' => $lang['strservers'],
397
                'url'   => 'servers',
398
                'icon'  => 'Servers',
399
            ],
400
        ];
401
    }
402
403
    /**
404
     * Gets the tabs for server view.
405
     *
406
     * @param \PHPPgAdmin\Database\ADOdbBase $data The database accesor instance
407
     *
408
     * @return array The tabs for server view
409
     */
410
    public function getTabsServer($data)
411
    {
412
        $lang       = $this->lang;
413
        $hide_users = true;
414
        $hide_roles = false;
415
416
        if ($data) {
0 ignored issues
show
introduced by
$data is of type PHPPgAdmin\Database\ADOdbBase, thus it always evaluated to true.
Loading history...
417
            $hide_users = !$data->isSuperUser();
0 ignored issues
show
introduced by
The method isSuperUser() does not exist on PHPPgAdmin\Database\ADOdbBase. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

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

417
            $hide_users = !$data->/** @scrutinizer ignore-call */ isSuperUser();
Loading history...
418
        }
419
420
        $tabs = [
421
            'databases' => [
422
                'title'   => $lang['strdatabases'],
423
                'url'     => 'alldb',
424
                'urlvars' => ['subject' => 'server'],
425
                'help'    => 'pg.database',
426
                'icon'    => 'Databases',
427
            ],
428
            'users'     => [
429
                'title'   => $lang['strusers'],
430
                'url'     => 'users',
431
                'urlvars' => ['subject' => 'server'],
432
                'hide'    => $hide_roles,
433
                'help'    => 'pg.user',
434
                'icon'    => 'Users',
435
            ],
436
        ];
437
438
        if ($data && $data->hasRoles()) {
439
            $tabs = \array_merge($tabs, [
440
                'roles' => [
441
                    'title'   => $lang['strroles'],
442
                    'url'     => 'roles',
443
                    'urlvars' => ['subject' => 'server'],
444
                    'hide'    => $hide_roles,
445
                    'help'    => 'pg.role',
446
                    'icon'    => 'Roles',
447
                ],
448
            ]);
449
        } else {
450
            $tabs = \array_merge($tabs, [
451
                'groups' => [
452
                    'title'   => $lang['strgroups'],
453
                    'url'     => 'groups',
454
                    'urlvars' => ['subject' => 'server'],
455
                    'hide'    => $hide_users,
456
                    'help'    => 'pg.group',
457
                    'icon'    => 'UserGroups',
458
                ],
459
            ]);
460
        }
461
462
        return \array_merge($tabs, [
463
            'account'     => [
464
                'title'   => $lang['straccount'],
465
                'url'     => ($data && $data->hasRoles()) ? 'roles' : 'users',
466
                'urlvars' => ['subject' => 'server', 'action' => 'account'],
467
                'hide'    => !$hide_users,
468
                'help'    => 'pg.role',
469
                'icon'    => 'User',
470
            ],
471
            'tablespaces' => [
472
                'title'   => $lang['strtablespaces'],
473
                'url'     => 'tablespaces',
474
                'urlvars' => ['subject' => 'server'],
475
                'hide'    => !$data || !$data->hasTablespaces(),
476
                'help'    => 'pg.tablespace',
477
                'icon'    => 'Tablespaces',
478
            ],
479
            'export'      => [
480
                'title'   => $lang['strexport'],
481
                'url'     => 'alldb',
482
                'urlvars' => ['subject' => 'server', 'action' => 'export'],
483
                'hide'    => !$this->isDumpEnabled(),
484
                'icon'    => 'Export',
485
            ],
486
        ]);
487
    }
488
489
    /**
490
     * Gets the tabs for database view.
491
     *
492
     * @param \PHPPgAdmin\Database\ADOdbBase $data The database accesor instance
493
     *
494
     * @return array The tabs for database view
495
     */
496
    public function getTabsDatabase($data)
497
    {
498
        $lang          = $this->lang;
499
        $hide_advanced = (false === $this->conf['show_advanced']);
500
501
        return [
502
            'schemas'    => [
503
                'title'   => $lang['strschemas'],
504
                'url'     => 'schemas',
505
                'urlvars' => ['subject' => 'database'],
506
                'help'    => 'pg.schema',
507
                'icon'    => 'Schemas',
508
            ],
509
            'sql'        => [
510
                'title'   => $lang['strsql'],
511
                'url'     => 'database',
512
                'urlvars' => ['subject' => 'database', 'action' => 'sql', 'new' => 1],
513
                'help'    => 'pg.sql',
514
                'tree'    => false,
515
                'icon'    => 'SqlEditor',
516
            ],
517
            'find'       => [
518
                'title'   => $lang['strfind'],
519
                'url'     => 'database',
520
                'urlvars' => ['subject' => 'database', 'action' => 'find'],
521
                'tree'    => false,
522
                'icon'    => 'Search',
523
            ],
524
            'variables'  => [
525
                'title'   => $lang['strvariables'],
526
                'url'     => 'database',
527
                'urlvars' => ['subject' => 'database', 'action' => 'variables'],
528
                'help'    => 'pg.variable',
529
                'tree'    => false,
530
                'icon'    => 'Variables',
531
            ],
532
            'processes'  => [
533
                'title'   => $lang['strprocesses'],
534
                'url'     => 'database',
535
                'urlvars' => ['subject' => 'database', 'action' => 'processes'],
536
                'help'    => 'pg.process',
537
                'tree'    => false,
538
                'icon'    => 'Processes',
539
            ],
540
            'locks'      => [
541
                'title'   => $lang['strlocks'],
542
                'url'     => 'database',
543
                'urlvars' => ['subject' => 'database', 'action' => 'locks'],
544
                'help'    => 'pg.locks',
545
                'tree'    => false,
546
                'icon'    => 'Key',
547
            ],
548
            'admin'      => [
549
                'title'   => $lang['stradmin'],
550
                'url'     => 'database',
551
                'urlvars' => ['subject' => 'database', 'action' => 'admin'],
552
                'tree'    => false,
553
                'icon'    => 'Admin',
554
            ],
555
            'privileges' => [
556
                'title'   => $lang['strprivileges'],
557
                'url'     => 'privileges',
558
                'urlvars' => ['subject' => 'database'],
559
                'hide'    => !isset($data->privlist['database']),
560
                'help'    => 'pg.privilege',
561
                'tree'    => false,
562
                'icon'    => 'Privileges',
563
            ],
564
            'languages'  => [
565
                'title'   => $lang['strlanguages'],
566
                'url'     => 'languages',
567
                'urlvars' => ['subject' => 'database'],
568
                'hide'    => $hide_advanced,
569
                'help'    => 'pg.language',
570
                'icon'    => 'Languages',
571
            ],
572
            'casts'      => [
573
                'title'   => $lang['strcasts'],
574
                'url'     => 'casts',
575
                'urlvars' => ['subject' => 'database'],
576
                'hide'    => $hide_advanced,
577
                'help'    => 'pg.cast',
578
                'icon'    => 'Casts',
579
            ],
580
            'export'     => [
581
                'title'   => $lang['strexport'],
582
                'url'     => 'database',
583
                'urlvars' => ['subject' => 'database', 'action' => 'export'],
584
                'hide'    => !$this->isDumpEnabled(),
585
                'tree'    => false,
586
                'icon'    => 'Export',
587
            ],
588
        ];
589
    }
590
591
    public function getTabsSchema($data)
592
    {
593
        $lang          = $this->lang;
594
        $hide_advanced = (false === $this->conf['show_advanced']);
595
        $tabs          = [
596
            'tables'      => [
597
                'title'   => $lang['strtables'],
598
                'url'     => 'tables',
599
                'urlvars' => ['subject' => 'schema'],
600
                'help'    => 'pg.table',
601
                'icon'    => 'Tables',
602
            ],
603
            'views'       => [
604
                'title'   => $lang['strviews'],
605
                'url'     => 'views',
606
                'urlvars' => ['subject' => 'schema'],
607
                'help'    => 'pg.view',
608
                'icon'    => 'Views',
609
            ],
610
            'matviews'    => [
611
                'title'   => 'M ' . $lang['strviews'],
612
                'url'     => 'materializedviews',
613
                'urlvars' => ['subject' => 'schema'],
614
                'help'    => 'pg.matview',
615
                'icon'    => 'MViews',
616
            ],
617
            'sequences'   => [
618
                'title'   => $lang['strsequences'],
619
                'url'     => 'sequences',
620
                'urlvars' => ['subject' => 'schema'],
621
                'help'    => 'pg.sequence',
622
                'icon'    => 'Sequences',
623
            ],
624
            'functions'   => [
625
                'title'   => $lang['strfunctions'],
626
                'url'     => 'functions',
627
                'urlvars' => ['subject' => 'schema'],
628
                'help'    => 'pg.function',
629
                'icon'    => 'Functions',
630
            ],
631
            'fulltext'    => [
632
                'title'   => $lang['strfulltext'],
633
                'url'     => 'fulltext',
634
                'urlvars' => ['subject' => 'schema'],
635
                'help'    => 'pg.fts',
636
                'tree'    => true,
637
                'icon'    => 'Fts',
638
            ],
639
            'domains'     => [
640
                'title'   => $lang['strdomains'],
641
                'url'     => 'domains',
642
                'urlvars' => ['subject' => 'schema'],
643
                'help'    => 'pg.domain',
644
                'icon'    => 'Domains',
645
            ],
646
            'aggregates'  => [
647
                'title'   => $lang['straggregates'],
648
                'url'     => 'aggregates',
649
                'urlvars' => ['subject' => 'schema'],
650
                'hide'    => $hide_advanced,
651
                'help'    => 'pg.aggregate',
652
                'icon'    => 'Aggregates',
653
            ],
654
            'types'       => [
655
                'title'   => $lang['strtypes'],
656
                'url'     => 'types',
657
                'urlvars' => ['subject' => 'schema'],
658
                'hide'    => $hide_advanced,
659
                'help'    => 'pg.type',
660
                'icon'    => 'Types',
661
            ],
662
            'operators'   => [
663
                'title'   => $lang['stroperators'],
664
                'url'     => 'operators',
665
                'urlvars' => ['subject' => 'schema'],
666
                'hide'    => $hide_advanced,
667
                'help'    => 'pg.operator',
668
                'icon'    => 'Operators',
669
            ],
670
            'opclasses'   => [
671
                'title'   => $lang['stropclasses'],
672
                'url'     => 'opclasses',
673
                'urlvars' => ['subject' => 'schema'],
674
                'hide'    => $hide_advanced,
675
                'help'    => 'pg.opclass',
676
                'icon'    => 'OperatorClasses',
677
            ],
678
            'conversions' => [
679
                'title'   => $lang['strconversions'],
680
                'url'     => 'conversions',
681
                'urlvars' => ['subject' => 'schema'],
682
                'hide'    => $hide_advanced,
683
                'help'    => 'pg.conversion',
684
                'icon'    => 'Conversions',
685
            ],
686
            'privileges'  => [
687
                'title'   => $lang['strprivileges'],
688
                'url'     => 'privileges',
689
                'urlvars' => ['subject' => 'schema'],
690
                'help'    => 'pg.privilege',
691
                'tree'    => false,
692
                'icon'    => 'Privileges',
693
            ],
694
            'export'      => [
695
                'title'   => $lang['strexport'],
696
                'url'     => 'schemas',
697
                'urlvars' => ['subject' => 'schema', 'action' => 'export'],
698
                'hide'    => !$this->isDumpEnabled(),
699
                'tree'    => false,
700
                'icon'    => 'Export',
701
            ],
702
        ];
703
704
        if (!$data->hasFTS()) {
705
            unset($tabs['fulltext']);
706
        }
707
708
        return $tabs;
709
    }
710
711
    public function getTabsTable($data)
712
    {
713
        $lang = $this->lang;
714
715
        return [
716
            'columns'     => [
717
                'title'   => $lang['strcolumns'],
718
                'url'     => 'tblproperties',
719
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
720
                'icon'    => 'Columns',
721
                'branch'  => true,
722
            ],
723
            'browse'      => [
724
                'title'   => $lang['strbrowse'],
725
                'icon'    => 'Columns',
726
                'url'     => 'display',
727
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
728
                'return'  => 'table',
729
                'branch'  => true,
730
            ],
731
            'select'      => [
732
                'title'   => $lang['strselect'],
733
                'icon'    => 'Search',
734
                'url'     => 'tables',
735
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table'), 'action' => 'confselectrows'],
736
                'help'    => 'pg.sql.select',
737
            ],
738
            'insert'      => [
739
                'title'   => $lang['strinsert'],
740
                'url'     => 'tables',
741
                'urlvars' => [
742
                    'action' => 'confinsertrow',
743
                    'table'  => Decorator::field('table'),
744
                ],
745
                'help'    => 'pg.sql.insert',
746
                'icon'    => 'Operator',
747
            ],
748
            'indexes'     => [
749
                'title'   => $lang['strindexes'],
750
                'url'     => 'indexes',
751
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
752
                'help'    => 'pg.index',
753
                'icon'    => 'Indexes',
754
                'branch'  => true,
755
            ],
756
            'constraints' => [
757
                'title'   => $lang['strconstraints'],
758
                'url'     => 'constraints',
759
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
760
                'help'    => 'pg.constraint',
761
                'icon'    => 'Constraints',
762
                'branch'  => true,
763
            ],
764
            'triggers'    => [
765
                'title'   => $lang['strtriggers'],
766
                'url'     => 'triggers',
767
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
768
                'help'    => 'pg.trigger',
769
                'icon'    => 'Triggers',
770
                'branch'  => true,
771
            ],
772
            'rules'       => [
773
                'title'   => $lang['strrules'],
774
                'url'     => 'rules',
775
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
776
                'help'    => 'pg.rule',
777
                'icon'    => 'Rules',
778
                'branch'  => true,
779
            ],
780
            'admin'       => [
781
                'title'   => $lang['stradmin'],
782
                'url'     => 'tables',
783
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table'), 'action' => 'admin'],
784
                'icon'    => 'Admin',
785
            ],
786
            'info'        => [
787
                'title'   => $lang['strinfo'],
788
                'url'     => 'info',
789
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
790
                'icon'    => 'Statistics',
791
            ],
792
            'privileges'  => [
793
                'title'   => $lang['strprivileges'],
794
                'url'     => 'privileges',
795
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table')],
796
                'help'    => 'pg.privilege',
797
                'icon'    => 'Privileges',
798
            ],
799
            'import'      => [
800
                'title'   => $lang['strimport'],
801
                'url'     => 'tblproperties',
802
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table'), 'action' => 'import'],
803
                'icon'    => 'Import',
804
                'hide'    => false,
805
            ],
806
            'export'      => [
807
                'title'   => $lang['strexport'],
808
                'url'     => 'tblproperties',
809
                'urlvars' => ['subject' => 'table', 'table' => Decorator::field('table'), 'action' => 'export'],
810
                'icon'    => 'Export',
811
                'hide'    => false,
812
            ],
813
        ];
814
    }
815
816
    public function getTabsView($data)
817
    {
818
        $lang = $this->lang;
819
820
        return [
821
            'columns'    => [
822
                'title'   => $lang['strcolumns'],
823
                'url'     => 'viewproperties',
824
                'urlvars' => ['subject' => 'view', 'view' => Decorator::field('view')],
825
                'icon'    => 'Columns',
826
                'branch'  => true,
827
            ],
828
            'browse'     => [
829
                'title'   => $lang['strbrowse'],
830
                'icon'    => 'Columns',
831
                'url'     => 'display',
832
                'urlvars' => [
833
                    'action'  => 'confselectrows',
834
                    'return'  => 'schema',
835
                    'subject' => 'view',
836
                    'view'    => Decorator::field('view'),
837
                ],
838
                'branch'  => true,
839
            ],
840
            'select'     => [
841
                'title'   => $lang['strselect'],
842
                'icon'    => 'Search',
843
                'url'     => 'views',
844
                'urlvars' => ['action' => 'confselectrows', 'view' => Decorator::field('view')],
845
                'help'    => 'pg.sql.select',
846
            ],
847
            'definition' => [
848
                'title'   => $lang['strdefinition'],
849
                'url'     => 'viewproperties',
850
                'urlvars' => ['subject' => 'view', 'view' => Decorator::field('view'), 'action' => 'definition'],
851
                'icon'    => 'Definition',
852
            ],
853
            'rules'      => [
854
                'title'   => $lang['strrules'],
855
                'url'     => 'rules',
856
                'urlvars' => ['subject' => 'view', 'view' => Decorator::field('view')],
857
                'help'    => 'pg.rule',
858
                'icon'    => 'Rules',
859
                'branch'  => true,
860
            ],
861
            'privileges' => [
862
                'title'   => $lang['strprivileges'],
863
                'url'     => 'privileges',
864
                'urlvars' => ['subject' => 'view', 'view' => Decorator::field('view')],
865
                'help'    => 'pg.privilege',
866
                'icon'    => 'Privileges',
867
            ],
868
            'export'     => [
869
                'title'   => $lang['strexport'],
870
                'url'     => 'viewproperties',
871
                'urlvars' => ['subject' => 'view', 'view' => Decorator::field('view'), 'action' => 'export'],
872
                'icon'    => 'Export',
873
                'hide'    => false,
874
            ],
875
        ];
876
    }
877
878
    public function getTabsMatview($data)
879
    {
880
        $lang = $this->lang;
881
882
        return [
883
            'columns'    => [
884
                'title'   => $lang['strcolumns'],
885
                'url'     => 'materializedviewproperties',
886
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview')],
887
                'icon'    => 'Columns',
888
                'branch'  => true,
889
            ],
890
            'browse'     => [
891
                'title'   => $lang['strbrowse'],
892
                'icon'    => 'Columns',
893
                'url'     => 'display',
894
                'urlvars' => [
895
                    'action'  => 'confselectrows',
896
                    'return'  => 'schema',
897
                    'subject' => 'matview',
898
                    'matview' => Decorator::field('matview'),
899
                ],
900
                'branch'  => true,
901
            ],
902
            'select'     => [
903
                'title'   => $lang['strselect'],
904
                'icon'    => 'Search',
905
                'url'     => 'materializedviews',
906
                'urlvars' => ['action' => 'confselectrows', 'matview' => Decorator::field('matview')],
907
                'help'    => 'pg.sql.select',
908
            ],
909
            'definition' => [
910
                'title'   => $lang['strdefinition'],
911
                'url'     => 'materializedviewproperties',
912
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview'), 'action' => 'definition'],
913
                'icon'    => 'Definition',
914
            ],
915
            'indexes'    => [
916
                'title'   => $lang['strindexes'],
917
                'url'     => 'indexes',
918
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview')],
919
                'help'    => 'pg.index',
920
                'icon'    => 'Indexes',
921
                'branch'  => true,
922
            ],
923
            /*'constraints' => [
924
            'title' => $lang['strconstraints'],
925
            'url' => 'constraints',
926
            'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview')],
927
            'help' => 'pg.constraint',
928
            'icon' => 'Constraints',
929
            'branch' => true,
930
             */
931
932
            'rules'      => [
933
                'title'   => $lang['strrules'],
934
                'url'     => 'rules',
935
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview')],
936
                'help'    => 'pg.rule',
937
                'icon'    => 'Rules',
938
                'branch'  => true,
939
            ],
940
            'privileges' => [
941
                'title'   => $lang['strprivileges'],
942
                'url'     => 'privileges',
943
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview')],
944
                'help'    => 'pg.privilege',
945
                'icon'    => 'Privileges',
946
            ],
947
            'export'     => [
948
                'title'   => $lang['strexport'],
949
                'url'     => 'materializedviewproperties',
950
                'urlvars' => ['subject' => 'matview', 'matview' => Decorator::field('matview'), 'action' => 'export'],
951
                'icon'    => 'Export',
952
                'hide'    => false,
953
            ],
954
        ];
955
    }
956
957
    public function getTabsFunction($data)
958
    {
959
        $lang = $this->lang;
960
961
        return [
962
            'definition' => [
963
                'title'   => $lang['strdefinition'],
964
                'url'     => 'functions',
965
                'urlvars' => [
966
                    'subject'      => 'function',
967
                    'function'     => Decorator::field('function'),
968
                    'function_oid' => Decorator::field('function_oid'),
969
                    'action'       => 'properties',
970
                ],
971
                'icon'    => 'Definition',
972
            ],
973
            'privileges' => [
974
                'title'   => $lang['strprivileges'],
975
                'url'     => 'privileges',
976
                'urlvars' => [
977
                    'subject'      => 'function',
978
                    'function'     => Decorator::field('function'),
979
                    'function_oid' => Decorator::field('function_oid'),
980
                ],
981
                'icon'    => 'Privileges',
982
            ],
983
            'show'       => [
984
                'title'   => $lang['strshow'] . ' ' . $lang['strdefinition'],
985
                'url'     => 'functions',
986
                'urlvars' => [
987
                    'subject'      => 'function',
988
                    'function'     => Decorator::field('function'),
989
                    'function_oid' => Decorator::field('function_oid'),
990
                    'action'       => 'show',
991
                ],
992
                'icon'    => 'Search',
993
            ],
994
        ];
995
    }
996
997
    public function getTabsAggregate($data)
998
    {
999
        $lang = $this->lang;
1000
1001
        return [
1002
            'definition' => [
1003
                'title'   => $lang['strdefinition'],
1004
                'url'     => 'aggregates',
1005
                'urlvars' => [
1006
                    'subject'  => 'aggregate',
1007
                    'aggrname' => Decorator::field('aggrname'),
1008
                    'aggrtype' => Decorator::field('aggrtype'),
1009
                    'action'   => 'properties',
1010
                ],
1011
                'icon'    => 'Definition',
1012
            ],
1013
        ];
1014
    }
1015
1016
    public function getTabsRole($data)
1017
    {
1018
        $lang = $this->lang;
1019
1020
        return [
1021
            'definition' => [
1022
                'title'   => $lang['strdefinition'],
1023
                'url'     => 'roles',
1024
                'urlvars' => [
1025
                    'subject'  => 'role',
1026
                    'rolename' => Decorator::field('rolename'),
1027
                    'action'   => 'properties',
1028
                ],
1029
                'icon'    => 'Definition',
1030
            ],
1031
        ];
1032
    }
1033
1034
    public function getTabsPopup($data)
1035
    {
1036
        $lang = $this->lang;
1037
1038
        return [
1039
            'sql'  => [
1040
                'title'   => $lang['strsql'],
1041
                'url'     => self::SUBFOLDER . '/src/views/sqledit',
0 ignored issues
show
Bug introduced by
The constant PHPPgAdmin\Traits\MiscTrait::SUBFOLDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1042
                'urlvars' => ['action' => 'sql', 'subject' => 'schema'],
1043
                'help'    => 'pg.sql',
1044
                'icon'    => 'SqlEditor',
1045
            ],
1046
            'find' => [
1047
                'title'   => $lang['strfind'],
1048
                'url'     => self::SUBFOLDER . '/src/views/sqledit',
1049
                'urlvars' => ['action' => 'find', 'subject' => 'schema'],
1050
                'icon'    => 'Search',
1051
            ],
1052
        ];
1053
    }
1054
1055
    public function getTabsColumn($data)
1056
    {
1057
        $lang = $this->lang;
1058
        $tabs = [
1059
            'properties' => [
1060
                'title'   => $lang['strcolprop'],
1061
                'url'     => 'colproperties',
1062
                'urlvars' => [
1063
                    'subject' => 'column',
1064
                    'table'   => Decorator::field('table'),
1065
                    'view'    => Decorator::field('view'),
1066
                    'column'  => Decorator::field('column'),
1067
                ],
1068
                'icon'    => 'Column',
1069
            ],
1070
            'privileges' => [
1071
                'title'   => $lang['strprivileges'],
1072
                'url'     => 'privileges',
1073
                'urlvars' => [
1074
                    'subject' => 'column',
1075
                    'table'   => Decorator::field('table'),
1076
                    'view'    => Decorator::field('view'),
1077
                    'column'  => Decorator::field('column'),
1078
                ],
1079
                'help'    => 'pg.privilege',
1080
                'icon'    => 'Privileges',
1081
            ],
1082
        ];
1083
1084
        if (empty($tabs['properties']['urlvars']['table'])) {
1085
            unset($tabs['properties']['urlvars']['table']);
1086
        }
1087
1088
        if (empty($tabs['privileges']['urlvars']['table'])) {
1089
            unset($tabs['privileges']['urlvars']['table']);
1090
        }
1091
1092
        return $tabs;
1093
    }
1094
1095
    public function getTabsFulltext($data)
1096
    {
1097
        $lang = $this->lang;
1098
1099
        return [
1100
            'ftsconfigs' => [
1101
                'title'   => $lang['strftstabconfigs'],
1102
                'url'     => 'fulltext',
1103
                'urlvars' => ['subject' => 'schema'],
1104
                'hide'    => !$data->hasFTS(),
1105
                'help'    => 'pg.ftscfg',
1106
                'tree'    => true,
1107
                'icon'    => 'FtsCfg',
1108
            ],
1109
            'ftsdicts'   => [
1110
                'title'   => $lang['strftstabdicts'],
1111
                'url'     => 'fulltext',
1112
                'urlvars' => ['subject' => 'schema', 'action' => 'viewdicts'],
1113
                'hide'    => !$data->hasFTS(),
1114
                'help'    => 'pg.ftsdict',
1115
                'tree'    => true,
1116
                'icon'    => 'FtsDict',
1117
            ],
1118
            'ftsparsers' => [
1119
                'title'   => $lang['strftstabparsers'],
1120
                'url'     => 'fulltext',
1121
                'urlvars' => ['subject' => 'schema', 'action' => 'viewparsers'],
1122
                'hide'    => !$data->hasFTS(),
1123
                'help'    => 'pg.ftsparser',
1124
                'tree'    => true,
1125
                'icon'    => 'FtsParser',
1126
            ],
1127
        ];
1128
    }
1129
1130
    /**
1131
     * Retrieve the tab info for a specific tab bar.
1132
     *
1133
     * @param string $section the name of the tab bar
1134
     *
1135
     * @return array array of tabs
1136
     */
1137
    public function getNavTabs($section)
1138
    {
1139
        $data = $this->getDatabaseAccessor();
1140
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
1141
1142
        $hide_advanced = (false === $this->conf['show_advanced']);
0 ignored issues
show
Unused Code introduced by
The assignment to $hide_advanced is dead and can be removed.
Loading history...
1143
        $tabs          = [];
1144
1145
        switch ($section) {
1146
            case 'root':$tabs = $this->getTabsRoot($data);
1147
1148
                break;
1149
            case 'server':$tabs = $this->getTabsServer($data);
1150
1151
                break;
1152
            case 'database':$tabs = $this->getTabsDatabase($data);
1153
1154
                break;
1155
            case 'schema':$tabs = $this->getTabsSchema($data);
1156
1157
                break;
1158
            case 'table':$tabs = $this->getTabsTable($data);
1159
1160
                break;
1161
            case 'view':$tabs = $this->getTabsView($data);
1162
1163
                break;
1164
            case 'matview':$tabs = $this->getTabsMatview($data);
1165
1166
                break;
1167
            case 'function':$tabs = $this->getTabsFunction($data);
1168
1169
                break;
1170
            case 'aggregate':$tabs = $this->getTabsAggregate($data);
1171
1172
                break;
1173
            case 'role':$tabs = $this->getTabsRole($data);
1174
1175
                break;
1176
            case 'popup':$tabs = $this->getTabsPopup($data);
1177
1178
                break;
1179
            case 'column':$tabs = $this->getTabsColumn($data);
1180
1181
                break;
1182
            case 'fulltext':$tabs = $this->getTabsFulltext($data);
1183
1184
                break;
1185
        }
1186
1187
        // Tabs hook's place
1188
        $plugin_functions_parameters = [
0 ignored issues
show
Unused Code introduced by
The assignment to $plugin_functions_parameters is dead and can be removed.
Loading history...
1189
            'tabs'    => &$tabs,
1190
            'section' => $section,
1191
        ];
1192
1193
        return $tabs;
1194
    }
1195
1196
    /**
1197
     * Get the URL for the last active tab of a particular tab bar.
1198
     *
1199
     * @param string $section
1200
     *
1201
     * @return null|mixed
1202
     */
1203
    public function getLastTabURL($section)
1204
    {
1205
        //$data = $this->getDatabaseAccessor();
1206
1207
        $tabs = $this->getNavTabs($section);
1208
1209
        if (isset($_SESSION['webdbLastTab'][$section], $tabs[$_SESSION['webdbLastTab'][$section]])) {
1210
            $tab = $tabs[$_SESSION['webdbLastTab'][$section]];
1211
        } else {
1212
            $tab = \reset($tabs);
1213
        }
1214
        // $this->prtrace(['section' => $section, 'tabs' => $tabs, 'tab' => $tab]);
1215
1216
        return isset($tab['url']) ? $tab : null;
1217
    }
1218
1219
    abstract public function getDatabaseAccessor($database = '', $server_id = null);
1220
1221
    abstract public function isDumpEnabled($all = false);
1222
1223
    abstract public function prtrace();
1224
}
1225