NodeColumn.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Functionality for the navigation tree
  5. *
  6. * @package PhpMyAdmin-Navigation
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Navigation\Nodes;
  10. use PhpMyAdmin\Util;
  11. /**
  12. * Represents a columns node in the navigation tree
  13. *
  14. * @package PhpMyAdmin-Navigation
  15. */
  16. class NodeColumn extends Node
  17. {
  18. /**
  19. * Initialises the class
  20. *
  21. * @param array $item array to identify the column node
  22. * @param int $type Type of node, may be one of CONTAINER or OBJECT
  23. * @param bool $isGroup Whether this object has been created
  24. * while grouping nodes
  25. */
  26. public function __construct($item, $type = Node::OBJECT, $isGroup = false)
  27. {
  28. $this->displayName = $this->getDisplayName($item);
  29. parent::__construct($item['name'], $type, $isGroup);
  30. $this->icon = Util::getImage($this->getColumnIcon($item['key']), __('Column'));
  31. $this->links = [
  32. 'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
  33. . '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
  34. . '&amp;change_column=1',
  35. 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
  36. . '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
  37. . '&amp;change_column=1',
  38. 'title' => __('Structure'),
  39. ];
  40. }
  41. /**
  42. * Get customized Icon for columns in navigation tree
  43. *
  44. * @param string $key The key type - (primary, foreign etc.)
  45. *
  46. * @return string Icon name for required key.
  47. */
  48. private function getColumnIcon($key)
  49. {
  50. switch ($key) {
  51. case 'PRI':
  52. $retval = 'b_primary';
  53. break;
  54. case 'UNI':
  55. $retval = 'bd_primary';
  56. break;
  57. default:
  58. $retval = 'pause';
  59. break;
  60. }
  61. return $retval;
  62. }
  63. /**
  64. * Get displayable name for navigation tree (key_type, data_type, default)
  65. *
  66. * @param array $item Item is array containing required info
  67. *
  68. * @return string Display name for navigation tree
  69. */
  70. private function getDisplayName($item)
  71. {
  72. $retval = $item['name'];
  73. $flag = 0;
  74. foreach ($item as $key => $value) {
  75. if (! empty($value) && $key != 'name') {
  76. $flag == 0 ? $retval .= ' (' : $retval .= ', ';
  77. $flag = 1;
  78. $retval .= $this->getTruncateValue($key, $value);
  79. }
  80. }
  81. $retval .= ')';
  82. return $retval;
  83. }
  84. /**
  85. * Get truncated value for display in node column view
  86. *
  87. * @param string $key key to identify default,datatype etc
  88. * @param string $value value corresponding to key
  89. *
  90. * @return string truncated value
  91. */
  92. public function getTruncateValue($key, $value)
  93. {
  94. $retval = '';
  95. switch ($key) {
  96. case 'default':
  97. strlen($value) > 6 ?
  98. $retval .= substr($value, 0, 6) . '...' :
  99. $retval = $value;
  100. break;
  101. default:
  102. $retval = $value;
  103. break;
  104. }
  105. return $retval;
  106. }
  107. }