TableStatsPdf.php 6.6 KB

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