TableStatsSvg.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Plugins\Schema\Svg;
  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 SVG XML document.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Table_Stats_Svg
  20. * @see PMA_SVG
  21. */
  22. class TableStatsSvg extends TableStats
  23. {
  24. /**
  25. * Defines properties
  26. */
  27. public $height;
  28. public $currentCell = 0;
  29. /**
  30. * The "PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg" constructor
  31. *
  32. * @param object $diagram The current SVG image document
  33. * @param string $db The database name
  34. * @param string $tableName The table name
  35. * @param string $font Font face
  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. *
  43. *
  44. * @see PMA_SVG, Table_Stats_Svg::Table_Stats_setWidth,
  45. * PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg::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. "SVG",
  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 size
  94. * @param integer $fontSize The font size
  95. *
  96. * @return void
  97. * @access private
  98. *
  99. * @see PMA_SVG
  100. */
  101. private function _setWidthTable($font, $fontSize)
  102. {
  103. foreach ($this->fields as $field) {
  104. $this->width = max(
  105. $this->width,
  106. Font::getStringWidth($field, $font, $fontSize)
  107. );
  108. }
  109. $this->width += Font::getStringWidth(' ', $font, $fontSize);
  110. /*
  111. * it is unknown what value must be added, because
  112. * table title is affected by the table width value
  113. */
  114. while ($this->width
  115. < Font::getStringWidth($this->getTitle(), $font, $fontSize)
  116. ) {
  117. $this->width += 7;
  118. }
  119. }
  120. /**
  121. * Sets the height of the table
  122. *
  123. * @param integer $fontSize font size
  124. *
  125. * @return void
  126. */
  127. private function _setHeightTable($fontSize)
  128. {
  129. $this->heightCell = $fontSize + 4;
  130. $this->height = (count($this->fields) + 1) * $this->heightCell;
  131. }
  132. /**
  133. * draw the table
  134. *
  135. * @param boolean $showColor Whether to display color
  136. *
  137. * @access public
  138. * @return void
  139. *
  140. * @see PMA_SVG,PMA_SVG::printElement
  141. */
  142. public function tableDraw($showColor)
  143. {
  144. $this->diagram->printElement(
  145. 'rect',
  146. $this->x,
  147. $this->y,
  148. $this->width,
  149. $this->heightCell,
  150. null,
  151. 'fill:#007;stroke:black;'
  152. );
  153. $this->diagram->printElement(
  154. 'text',
  155. $this->x + 5,
  156. $this->y + 14,
  157. $this->width,
  158. $this->heightCell,
  159. $this->getTitle(),
  160. 'fill:#fff;'
  161. );
  162. foreach ($this->fields as $field) {
  163. $this->currentCell += $this->heightCell;
  164. $fillColor = 'none';
  165. if ($showColor) {
  166. if (in_array($field, $this->primary)) {
  167. $fillColor = '#aea';
  168. }
  169. if ($field == $this->displayfield) {
  170. $fillColor = 'none';
  171. }
  172. }
  173. $this->diagram->printElement(
  174. 'rect',
  175. $this->x,
  176. $this->y + $this->currentCell,
  177. $this->width,
  178. $this->heightCell,
  179. null,
  180. 'fill:' . $fillColor . ';stroke:black;'
  181. );
  182. $this->diagram->printElement(
  183. 'text',
  184. $this->x + 5,
  185. $this->y + 14 + $this->currentCell,
  186. $this->width,
  187. $this->heightCell,
  188. $field,
  189. 'fill:black;'
  190. );
  191. }
  192. }
  193. }