3 * Contains PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia class
6 declare(strict_types
=1);
8 namespace PhpMyAdmin\Plugins\Schema\Dia
;
10 use PhpMyAdmin\Plugins\Schema\ExportRelationSchema
;
11 use PhpMyAdmin\Plugins\Schema\TableStats
;
14 use function in_array
;
19 * Table preferences/statistics
21 * This class preserves the table co-ordinates,fields
22 * and helps in drawing/generating the Tables in dia XML document.
24 * @property Dia $diagram
26 class TableStatsDia
extends TableStats
32 public $tableColor = '#000000';
35 * @param Dia $diagram The current dia document
36 * @param string $db The database name
37 * @param string $tableName The table name
38 * @param int $pageNumber The current page number (from the
39 * $cfg['Servers'][$i]['table_coords'] table)
40 * @param bool $showKeys Whether to display ONLY keys or not
41 * @param bool $offline Whether the coordinates are sent from the browser
43 public function __construct(
51 parent
::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, false, $offline);
54 * Every object in Dia document needs an ID to identify
55 * so, we used a static variable to keep the things unique
57 $this->tableId
= ++DiaRelationSchema
::$objectId;
61 * Displays an error when the table cannot be found.
63 protected function showMissingTableError(): void
65 ExportRelationSchema
::dieSchema(
68 sprintf(__('The %s table doesn\'t exist!'), $this->tableName
)
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.
83 * @param bool $showColor Whether to show color for tables text or not
84 * if showColor is true then an array of $listOfColors
85 * will be used to choose the random colors for tables
86 * text we can change/add more colors to this array
88 public function tableDraw($showColor): void
96 shuffle($listOfColors);
97 $this->tableColor
= '#' . $listOfColors[0] . '';
99 $this->tableColor
= '#000000';
104 $this->diagram
->startElement('dia:object');
105 $this->diagram
->writeAttribute('type', 'Database - Table');
106 $this->diagram
->writeAttribute('version', '0');
107 $this->diagram
->writeAttribute('id', '' . $this->tableId
. '');
108 $this->diagram
->writeRaw(
109 '<dia:attribute name="obj_pos">
111 . ($this->x
* $factor) . ',' . ($this->y
* $factor) . '"/>
113 <dia:attribute name="obj_bb">
114 <dia:rectangle val="'
115 . ($this->x
* $factor) . ',' . ($this->y
* $factor) . ';9.97,9.2"/>
117 <dia:attribute name="meta">
118 <dia:composite type="dict"/>
120 <dia:attribute name="elem_corner">
122 . ($this->x
* $factor) . ',' . ($this->y
* $factor) . '"/>
124 <dia:attribute name="elem_width">
125 <dia:real val="5.9199999999999999"/>
127 <dia:attribute name="elem_height">
128 <dia:real val="3.5"/>
130 <dia:attribute name="text_colour">
131 <dia:color val="' . $this->tableColor
. '"/>
133 <dia:attribute name="line_colour">
134 <dia:color val="#000000"/>
136 <dia:attribute name="fill_colour">
137 <dia:color val="#ffffff"/>
139 <dia:attribute name="line_width">
140 <dia:real val="0.10000000000000001"/>
142 <dia:attribute name="name">
143 <dia:string>#' . $this->tableName
. '#</dia:string>
145 <dia:attribute name="comment">
146 <dia:string>##</dia:string>
148 <dia:attribute name="visible_comment">
149 <dia:boolean val="false"/>
151 <dia:attribute name="tagging_comment">
152 <dia:boolean val="false"/>
154 <dia:attribute name="underline_primary_key">
155 <dia:boolean val="true"/>
157 <dia:attribute name="bold_primary_keys">
158 <dia:boolean val="true"/>
160 <dia:attribute name="normal_font">
161 <dia:font family="monospace" style="0" name="Courier"/>
163 <dia:attribute name="name_font">
164 <dia:font family="sans" style="80" name="Helvetica-Bold"/>
166 <dia:attribute name="comment_font">
167 <dia:font family="sans" style="0" name="Helvetica"/>
169 <dia:attribute name="normal_font_height">
170 <dia:real val="0.80000000000000004"/>
172 <dia:attribute name="name_font_height">
173 <dia:real val="0.69999999999999996"/>
175 <dia:attribute name="comment_font_height">
176 <dia:real val="0.69999999999999996"/>
180 $this->diagram
->startElement('dia:attribute');
181 $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>
189 <dia:attribute name="type">
190 <dia:string>##</dia:string>
192 <dia:attribute name="comment">
193 <dia:string>##</dia:string>
198 if (in_array($field, $this->primary
)) {
202 if ($field == $this->displayfield
) {
206 $this->diagram
->writeRaw(
207 '<dia:attribute name="primary_key">
208 <dia:boolean val="' . $pm . '"/>
210 <dia:attribute name="nullable">
211 <dia:boolean val="false"/>
213 <dia:attribute name="unique">
214 <dia:boolean val="' . $pm . '"/>
220 $this->diagram
->endElement();
221 $this->diagram
->endElement();