TableStatsDia.php 7.8 KB

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