TableStatsPdf.class.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains Table_Stats_Pdf 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 PDF document.
  17. *
  18. * @name Table_Stats_Pdf
  19. * @package PhpMyAdmin
  20. * @see PMA_Schema_PDF
  21. */
  22. class Table_Stats_Pdf extends TableStats
  23. {
  24. /**
  25. * Defines properties
  26. */
  27. public $nb_fiels;
  28. public $height;
  29. private $_ff = PMA_PDF_FONT;
  30. /**
  31. * The "Table_Stats_Pdf" constructor
  32. *
  33. * @param object $diagram The PDF diagram
  34. * @param string $db The database name
  35. * @param string $tableName The table name
  36. * @param integer $fontSize The font size
  37. * @param integer $pageNumber The current page number (from the
  38. * $cfg['Servers'][$i]['table_coords'] table)
  39. * @param integer &$sameWideWidth The max. with 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_Schema_PDF, Table_Stats_Pdf::Table_Stats_setWidth,
  46. * Table_Stats_Pdf::Table_Stats_setHeight
  47. */
  48. public function __construct(
  49. $diagram, $db, $tableName, $fontSize, $pageNumber, &$sameWideWidth,
  50. $showKeys = false, $tableDimension = false, $offline = false
  51. ) {
  52. parent::__construct(
  53. $diagram, $db, $pageNumber, $tableName,
  54. $showKeys, $tableDimension, $offline
  55. );
  56. $this->heightCell = 6;
  57. $this->_setHeight();
  58. /*
  59. * setWidth must me after setHeight, because title
  60. * can include table height which changes table width
  61. */
  62. $this->_setWidth($fontSize);
  63. if ($sameWideWidth < $this->width) {
  64. $sameWideWidth = $this->width;
  65. }
  66. }
  67. /**
  68. * Displays an error when the table cannot be found.
  69. *
  70. * @return void
  71. */
  72. protected function showMissingTableError()
  73. {
  74. PMA_Export_Relation_Schema::dieSchema(
  75. $this->pageNumber,
  76. "PDF",
  77. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  78. );
  79. }
  80. /**
  81. * Returns title of the current table,
  82. * title can have the dimensions of the table
  83. *
  84. * @return string
  85. */
  86. protected function getTitle()
  87. {
  88. $ret = '';
  89. if ($this->tableDimension) {
  90. $ret = sprintf('%.0fx%0.f', $this->width, $this->height);
  91. }
  92. return $ret . ' ' . $this->tableName;
  93. }
  94. /**
  95. * Sets the width of the table
  96. *
  97. * @param integer $fontSize The font size
  98. *
  99. * @access private
  100. *
  101. * @return void
  102. *
  103. * @see PMA_Schema_PDF
  104. */
  105. private function _setWidth($fontSize)
  106. {
  107. foreach ($this->fields as $field) {
  108. $this->width = max($this->width, $this->diagram->GetStringWidth($field));
  109. }
  110. $this->width += $this->diagram->GetStringWidth(' ');
  111. $this->diagram->SetFont($this->_ff, 'B', $fontSize);
  112. /*
  113. * it is unknown what value must be added, because
  114. * table title is affected by the table width value
  115. */
  116. while ($this->width < $this->diagram->GetStringWidth($this->getTitle())) {
  117. $this->width += 5;
  118. }
  119. $this->diagram->SetFont($this->_ff, '', $fontSize);
  120. }
  121. /**
  122. * Sets the height of the table
  123. *
  124. * @return void
  125. *
  126. * @access private
  127. */
  128. private function _setHeight()
  129. {
  130. $this->height = (count($this->fields) + 1) * $this->heightCell;
  131. }
  132. /**
  133. * Do draw the table
  134. *
  135. * @param integer $fontSize The font size
  136. * @param boolean $withDoc Whether to include links to documentation
  137. * @param boolean|integer $setColor Whether to display color
  138. *
  139. * @access public
  140. *
  141. * @return void
  142. *
  143. * @see PMA_Schema_PDF
  144. */
  145. public function tableDraw($fontSize, $withDoc, $setColor = 0)
  146. {
  147. $this->diagram->setXyScale($this->x, $this->y);
  148. $this->diagram->SetFont($this->_ff, 'B', $fontSize);
  149. if ($setColor) {
  150. $this->diagram->SetTextColor(200);
  151. $this->diagram->SetFillColor(0, 0, 128);
  152. }
  153. if ($withDoc) {
  154. $this->diagram->SetLink($this->diagram->PMA_links['RT'][$this->tableName]['-'], -1);
  155. } else {
  156. $this->diagram->PMA_links['doc'][$this->tableName]['-'] = '';
  157. }
  158. $this->diagram->cellScale(
  159. $this->width,
  160. $this->heightCell,
  161. $this->getTitle(),
  162. 1,
  163. 1,
  164. 'C',
  165. $setColor,
  166. $this->diagram->PMA_links['doc'][$this->tableName]['-']
  167. );
  168. $this->diagram->setXScale($this->x);
  169. $this->diagram->SetFont($this->_ff, '', $fontSize);
  170. $this->diagram->SetTextColor(0);
  171. $this->diagram->SetFillColor(255);
  172. foreach ($this->fields as $field) {
  173. if ($setColor) {
  174. if (in_array($field, $this->primary)) {
  175. $this->diagram->SetFillColor(215, 121, 123);
  176. }
  177. if ($field == $this->displayfield) {
  178. $this->diagram->SetFillColor(142, 159, 224);
  179. }
  180. }
  181. if ($withDoc) {
  182. $this->diagram->SetLink($this->diagram->PMA_links['RT'][$this->tableName][$field], -1);
  183. } else {
  184. $this->diagram->PMA_links['doc'][$this->tableName][$field] = '';
  185. }
  186. $this->diagram->cellScale(
  187. $this->width,
  188. $this->heightCell,
  189. ' ' . $field,
  190. 1,
  191. 1,
  192. 'L',
  193. $setColor,
  194. $this->diagram->PMA_links['doc'][$this->tableName][$field]
  195. );
  196. $this->diagram->setXScale($this->x);
  197. $this->diagram->SetFillColor(255);
  198. }
  199. }
  200. }