TableStatsDia.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Plugins\Schema\Dia;
  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 dia XML document.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Table_Stats_Dia
  20. * @see PMA_DIA
  21. */
  22. class TableStatsDia extends TableStats
  23. {
  24. public $tableId;
  25. public $tableColor;
  26. /**
  27. * The "PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia" constructor
  28. *
  29. * @param Dia $diagram The current dia document
  30. * @param string $db The database name
  31. * @param string $tableName The table name
  32. * @param integer $pageNumber The current page number (from the
  33. * $cfg['Servers'][$i]['table_coords'] table)
  34. * @param boolean $showKeys Whether to display ONLY keys or not
  35. * @param boolean $offline Whether the coordinates are sent from the browser
  36. */
  37. public function __construct(
  38. $diagram,
  39. $db,
  40. $tableName,
  41. $pageNumber,
  42. $showKeys = false,
  43. $offline = false
  44. ) {
  45. parent::__construct(
  46. $diagram,
  47. $db,
  48. $pageNumber,
  49. $tableName,
  50. $showKeys,
  51. false,
  52. $offline
  53. );
  54. /**
  55. * Every object in Dia document needs an ID to identify
  56. * so, we used a static variable to keep the things unique
  57. */
  58. $this->tableId = ++DiaRelationSchema::$objectId;
  59. }
  60. /**
  61. * Displays an error when the table cannot be found.
  62. *
  63. * @return void
  64. */
  65. protected function showMissingTableError()
  66. {
  67. ExportRelationSchema::dieSchema(
  68. $this->pageNumber,
  69. "DIA",
  70. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  71. );
  72. }
  73. /**
  74. * Do draw the table
  75. *
  76. * Tables are generated using object type Database - Table
  77. * primary fields are underlined in tables. Dia object
  78. * is used to generate the XML of Dia Document. Database Table
  79. * Object and their attributes are involved in the combination
  80. * of displaying Database - Table on Dia Document.
  81. *
  82. * @param boolean $showColor Whether to show color for tables text or not
  83. * if showColor is true then an array of $listOfColors
  84. * will be used to choose the random colors for tables
  85. * text we can change/add more colors to this array
  86. *
  87. * @return void
  88. *
  89. * @access public
  90. * @see Dia
  91. */
  92. public function tableDraw($showColor)
  93. {
  94. if ($showColor) {
  95. $listOfColors = [
  96. 'FF0000',
  97. '000099',
  98. '00FF00',
  99. ];
  100. shuffle($listOfColors);
  101. $this->tableColor = '#' . $listOfColors[0] . '';
  102. } else {
  103. $this->tableColor = '#000000';
  104. }
  105. $factor = 0.1;
  106. $this->diagram->startElement('dia:object');
  107. $this->diagram->writeAttribute('type', 'Database - Table');
  108. $this->diagram->writeAttribute('version', '0');
  109. $this->diagram->writeAttribute('id', '' . $this->tableId . '');
  110. $this->diagram->writeRaw(
  111. '<dia:attribute name="obj_pos">
  112. <dia:point val="'
  113. . ($this->x * $factor) . ',' . ($this->y * $factor) . '"/>
  114. </dia:attribute>
  115. <dia:attribute name="obj_bb">
  116. <dia:rectangle val="'
  117. . ($this->x * $factor) . ',' . ($this->y * $factor) . ';9.97,9.2"/>
  118. </dia:attribute>
  119. <dia:attribute name="meta">
  120. <dia:composite type="dict"/>
  121. </dia:attribute>
  122. <dia:attribute name="elem_corner">
  123. <dia:point val="'
  124. . ($this->x * $factor) . ',' . ($this->y * $factor) . '"/>
  125. </dia:attribute>
  126. <dia:attribute name="elem_width">
  127. <dia:real val="5.9199999999999999"/>
  128. </dia:attribute>
  129. <dia:attribute name="elem_height">
  130. <dia:real val="3.5"/>
  131. </dia:attribute>
  132. <dia:attribute name="text_colour">
  133. <dia:color val="' . $this->tableColor . '"/>
  134. </dia:attribute>
  135. <dia:attribute name="line_colour">
  136. <dia:color val="#000000"/>
  137. </dia:attribute>
  138. <dia:attribute name="fill_colour">
  139. <dia:color val="#ffffff"/>
  140. </dia:attribute>
  141. <dia:attribute name="line_width">
  142. <dia:real val="0.10000000000000001"/>
  143. </dia:attribute>
  144. <dia:attribute name="name">
  145. <dia:string>#' . $this->tableName . '#</dia:string>
  146. </dia:attribute>
  147. <dia:attribute name="comment">
  148. <dia:string>##</dia:string>
  149. </dia:attribute>
  150. <dia:attribute name="visible_comment">
  151. <dia:boolean val="false"/>
  152. </dia:attribute>
  153. <dia:attribute name="tagging_comment">
  154. <dia:boolean val="false"/>
  155. </dia:attribute>
  156. <dia:attribute name="underline_primary_key">
  157. <dia:boolean val="true"/>
  158. </dia:attribute>
  159. <dia:attribute name="bold_primary_keys">
  160. <dia:boolean val="true"/>
  161. </dia:attribute>
  162. <dia:attribute name="normal_font">
  163. <dia:font family="monospace" style="0" name="Courier"/>
  164. </dia:attribute>
  165. <dia:attribute name="name_font">
  166. <dia:font family="sans" style="80" name="Helvetica-Bold"/>
  167. </dia:attribute>
  168. <dia:attribute name="comment_font">
  169. <dia:font family="sans" style="0" name="Helvetica"/>
  170. </dia:attribute>
  171. <dia:attribute name="normal_font_height">
  172. <dia:real val="0.80000000000000004"/>
  173. </dia:attribute>
  174. <dia:attribute name="name_font_height">
  175. <dia:real val="0.69999999999999996"/>
  176. </dia:attribute>
  177. <dia:attribute name="comment_font_height">
  178. <dia:real val="0.69999999999999996"/>
  179. </dia:attribute>'
  180. );
  181. $this->diagram->startElement('dia:attribute');
  182. $this->diagram->writeAttribute('name', 'attributes');
  183. foreach ($this->fields as $field) {
  184. $this->diagram->writeRaw(
  185. '<dia:composite type="table_attribute">
  186. <dia:attribute name="name">
  187. <dia:string>#' . $field . '#</dia:string>
  188. </dia:attribute>
  189. <dia:attribute name="type">
  190. <dia:string>##</dia:string>
  191. </dia:attribute>
  192. <dia:attribute name="comment">
  193. <dia:string>##</dia:string>
  194. </dia:attribute>'
  195. );
  196. unset($pm);
  197. $pm = 'false';
  198. if (in_array($field, $this->primary)) {
  199. $pm = 'true';
  200. }
  201. if ($field == $this->displayfield) {
  202. $pm = 'false';
  203. }
  204. $this->diagram->writeRaw(
  205. '<dia:attribute name="primary_key">
  206. <dia:boolean val="' . $pm . '"/>
  207. </dia:attribute>
  208. <dia:attribute name="nullable">
  209. <dia:boolean val="false"/>
  210. </dia:attribute>
  211. <dia:attribute name="unique">
  212. <dia:boolean val="' . $pm . '"/>
  213. </dia:attribute>
  214. </dia:composite>'
  215. );
  216. }
  217. $this->diagram->endElement();
  218. $this->diagram->endElement();
  219. }
  220. }