TableStatsEps.php 4.9 KB

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