TableStatsEps.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Eps\TableStatsEps class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Plugins\Schema\Eps;
  9. use PhpMyAdmin\Font;
  10. use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
  11. use PhpMyAdmin\Plugins\Schema\TableStats;
  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 TableStatsEps extends TableStats
  23. {
  24. /**
  25. * Defines properties
  26. */
  27. public $height;
  28. public $currentCell = 0;
  29. /**
  30. * The "PhpMyAdmin\Plugins\Schema\Eps\TableStatsEps" 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. * PhpMyAdmin\Plugins\Schema\Eps\TableStatsEps::Table_Stats_setHeight
  46. */
  47. public function __construct(
  48. $diagram,
  49. $db,
  50. $tableName,
  51. $font,
  52. $fontSize,
  53. $pageNumber,
  54. &$same_wide_width,
  55. $showKeys = false,
  56. $tableDimension = false,
  57. $offline = false
  58. ) {
  59. parent::__construct(
  60. $diagram,
  61. $db,
  62. $pageNumber,
  63. $tableName,
  64. $showKeys,
  65. $tableDimension,
  66. $offline
  67. );
  68. // height and width
  69. $this->_setHeightTable($fontSize);
  70. // setWidth must me after setHeight, because title
  71. // can include table height which changes table width
  72. $this->_setWidthTable($font, $fontSize);
  73. if ($same_wide_width < $this->width) {
  74. $same_wide_width = $this->width;
  75. }
  76. }
  77. /**
  78. * Displays an error when the table cannot be found.
  79. *
  80. * @return void
  81. */
  82. protected function showMissingTableError()
  83. {
  84. ExportRelationSchema::dieSchema(
  85. $this->pageNumber,
  86. "EPS",
  87. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  88. );
  89. }
  90. /**
  91. * Sets the width of the table
  92. *
  93. * @param string $font The font name
  94. * @param integer $fontSize The font size
  95. *
  96. * @return void
  97. *
  98. * @see PMA_EPS
  99. */
  100. private function _setWidthTable($font, $fontSize)
  101. {
  102. foreach ($this->fields as $field) {
  103. $this->width = max(
  104. $this->width,
  105. Font::getStringWidth($field, $font, $fontSize)
  106. );
  107. }
  108. $this->width += Font::getStringWidth(
  109. ' ',
  110. $font,
  111. $fontSize
  112. );
  113. /*
  114. * it is unknown what value must be added, because
  115. * table title is affected by the table width value
  116. */
  117. while ($this->width
  118. < Font::getStringWidth(
  119. $this->getTitle(),
  120. $font,
  121. $fontSize
  122. )) {
  123. $this->width += 7;
  124. }
  125. }
  126. /**
  127. * Sets the height of the table
  128. *
  129. * @param integer $fontSize The font size
  130. *
  131. * @return void
  132. */
  133. private function _setHeightTable($fontSize)
  134. {
  135. $this->heightCell = $fontSize + 4;
  136. $this->height = (count($this->fields) + 1) * $this->heightCell;
  137. }
  138. /**
  139. * Draw the table
  140. *
  141. * @param boolean $showColor Whether to display color
  142. *
  143. * @return void
  144. *
  145. * @see PMA_EPS,PMA_EPS::line,PMA_EPS::rect
  146. */
  147. public function tableDraw($showColor)
  148. {
  149. //echo $this->tableName.'<br />';
  150. $this->diagram->rect(
  151. $this->x,
  152. $this->y + 12,
  153. $this->width,
  154. $this->heightCell,
  155. 1
  156. );
  157. $this->diagram->showXY($this->getTitle(), $this->x + 5, $this->y + 14);
  158. foreach ($this->fields as $field) {
  159. $this->currentCell += $this->heightCell;
  160. $this->diagram->rect(
  161. $this->x,
  162. $this->y + 12 + $this->currentCell,
  163. $this->width,
  164. $this->heightCell,
  165. 1
  166. );
  167. $this->diagram->showXY(
  168. $field,
  169. $this->x + 5,
  170. $this->y + 14 + $this->currentCell
  171. );
  172. }
  173. }
  174. }