TableStatsDia.class.php 7.6 KB

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