TableStatsEps.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains Table_Stats_Eps class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. require_once 'libraries/plugins/schema/TableStats.class.php';
  12. /**
  13. * Table preferences/statistics
  14. *
  15. * This class preserves the table co-ordinates,fields
  16. * and helps in drawing/generating the Tables in EPS.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Table_Stats_Eps
  20. * @see PMA_EPS
  21. */
  22. class Table_Stats_Eps extends TableStats
  23. {
  24. /**
  25. * Defines properties
  26. */
  27. public $height;
  28. public $currentCell = 0;
  29. /**
  30. * The "Table_Stats_Eps" constructor
  31. *
  32. * @param object $diagram The EPS diagram
  33. * @param string $db The database name
  34. * @param string $tableName The table name
  35. * @param string $font The font name
  36. * @param integer $fontSize The font size
  37. * @param integer $pageNumber Page number
  38. * @param integer &$same_wide_width The max width among tables
  39. * @param boolean $showKeys Whether to display keys or not
  40. * @param boolean $tableDimension Whether to display table position or not
  41. * @param boolean $offline Whether the coordinates are sent
  42. * from the browser
  43. *
  44. * @see PMA_EPS, Table_Stats_Eps::Table_Stats_setWidth,
  45. * Table_Stats_Eps::Table_Stats_setHeight
  46. */
  47. public function __construct(
  48. $diagram, $db, $tableName, $font, $fontSize, $pageNumber, &$same_wide_width,
  49. $showKeys = false, $tableDimension = false, $offline = false
  50. ) {
  51. parent::__construct(
  52. $diagram, $db, $pageNumber, $tableName,
  53. $showKeys, $tableDimension, $offline
  54. );
  55. // height and width
  56. $this->_setHeightTable($fontSize);
  57. // setWidth must me after setHeight, because title
  58. // can include table height which changes table width
  59. $this->_setWidthTable($font, $fontSize);
  60. if ($same_wide_width < $this->width) {
  61. $same_wide_width = $this->width;
  62. }
  63. }
  64. /**
  65. * Displays an error when the table cannot be found.
  66. *
  67. * @return void
  68. */
  69. protected function showMissingTableError()
  70. {
  71. PMA_Export_Relation_Schema::dieSchema(
  72. $this->pageNumber,
  73. "EPS",
  74. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  75. );
  76. }
  77. /**
  78. * Sets the width of the table
  79. *
  80. * @param string $font The font name
  81. * @param integer $fontSize The font size
  82. *
  83. * @return void
  84. *
  85. * @see PMA_EPS
  86. */
  87. private function _setWidthTable($font,$fontSize)
  88. {
  89. foreach ($this->fields as $field) {
  90. $this->width = max(
  91. $this->width,
  92. PMA_Font::getStringWidth($field, $font, $fontSize)
  93. );
  94. }
  95. $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
  96. /*
  97. * it is unknown what value must be added, because
  98. * table title is affected by the table width value
  99. */
  100. while ($this->width
  101. < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)) {
  102. $this->width += 7;
  103. }
  104. }
  105. /**
  106. * Sets the height of the table
  107. *
  108. * @param integer $fontSize The font size
  109. *
  110. * @return void
  111. */
  112. private function _setHeightTable($fontSize)
  113. {
  114. $this->heightCell = $fontSize + 4;
  115. $this->height = (count($this->fields) + 1) * $this->heightCell;
  116. }
  117. /**
  118. * Draw the table
  119. *
  120. * @param boolean $showColor Whether to display color
  121. *
  122. * @return void
  123. *
  124. * @see PMA_EPS,PMA_EPS::line,PMA_EPS::rect
  125. */
  126. public function tableDraw($showColor)
  127. {
  128. //echo $this->tableName.'<br />';
  129. $this->diagram->rect($this->x, $this->y + 12, $this->width, $this->heightCell, 1);
  130. $this->diagram->showXY($this->getTitle(), $this->x + 5, $this->y + 14);
  131. foreach ($this->fields as $field) {
  132. $this->currentCell += $this->heightCell;
  133. $this->diagram->rect(
  134. $this->x, $this->y + 12 + $this->currentCell,
  135. $this->width, $this->heightCell, 1
  136. );
  137. $this->diagram->showXY($field, $this->x + 5, $this->y + 14 + $this->currentCell);
  138. }
  139. }
  140. }