| Total Complexity | 113 |
| Total Lines | 1205 |
| Duplicated Lines | 0 % |
| Changes | 8 | ||
| Bugs | 3 | Features | 1 |
Complex classes like MiscTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MiscTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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'; |
||
|
|
|||
| 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 '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(' ', ' ', \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) { |
||
| 417 | $hide_users = !$data->isSuperUser(); |
||
| 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) |
||
| 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', |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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 |