Remove `@access` annotations
[phpmyadmin.git] / libraries / classes / Plugins / Schema / Dia / TableStatsDia.php
blob36e4e9f558127b21a4bad940ab25772b74210363
1 <?php
2 /**
3 * Contains PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia class
4 */
6 declare(strict_types=1);
8 namespace PhpMyAdmin\Plugins\Schema\Dia;
10 use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
11 use PhpMyAdmin\Plugins\Schema\TableStats;
13 use function __;
14 use function in_array;
15 use function shuffle;
16 use function sprintf;
18 /**
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
28 /** @var int */
29 public $tableId;
31 /** @var string */
32 public $tableColor = '#000000';
34 /**
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(
44 $diagram,
45 $db,
46 $tableName,
47 $pageNumber,
48 $showKeys = false,
49 $offline = false
50 ) {
51 parent::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, false, $offline);
53 /**
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;
60 /**
61 * Displays an error when the table cannot be found.
63 protected function showMissingTableError(): void
65 ExportRelationSchema::dieSchema(
66 $this->pageNumber,
67 'DIA',
68 sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
72 /**
73 * Do draw the table
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.
81 * @see Dia
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
90 if ($showColor) {
91 $listOfColors = [
92 'FF0000',
93 '000099',
94 '00FF00',
96 shuffle($listOfColors);
97 $this->tableColor = '#' . $listOfColors[0] . '';
98 } else {
99 $this->tableColor = '#000000';
102 $factor = 0.1;
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">
110 <dia:point val="'
111 . ($this->x * $factor) . ',' . ($this->y * $factor) . '"/>
112 </dia:attribute>
113 <dia:attribute name="obj_bb">
114 <dia:rectangle val="'
115 . ($this->x * $factor) . ',' . ($this->y * $factor) . ';9.97,9.2"/>
116 </dia:attribute>
117 <dia:attribute name="meta">
118 <dia:composite type="dict"/>
119 </dia:attribute>
120 <dia:attribute name="elem_corner">
121 <dia:point val="'
122 . ($this->x * $factor) . ',' . ($this->y * $factor) . '"/>
123 </dia:attribute>
124 <dia:attribute name="elem_width">
125 <dia:real val="5.9199999999999999"/>
126 </dia:attribute>
127 <dia:attribute name="elem_height">
128 <dia:real val="3.5"/>
129 </dia:attribute>
130 <dia:attribute name="text_colour">
131 <dia:color val="' . $this->tableColor . '"/>
132 </dia:attribute>
133 <dia:attribute name="line_colour">
134 <dia:color val="#000000"/>
135 </dia:attribute>
136 <dia:attribute name="fill_colour">
137 <dia:color val="#ffffff"/>
138 </dia:attribute>
139 <dia:attribute name="line_width">
140 <dia:real val="0.10000000000000001"/>
141 </dia:attribute>
142 <dia:attribute name="name">
143 <dia:string>#' . $this->tableName . '#</dia:string>
144 </dia:attribute>
145 <dia:attribute name="comment">
146 <dia:string>##</dia:string>
147 </dia:attribute>
148 <dia:attribute name="visible_comment">
149 <dia:boolean val="false"/>
150 </dia:attribute>
151 <dia:attribute name="tagging_comment">
152 <dia:boolean val="false"/>
153 </dia:attribute>
154 <dia:attribute name="underline_primary_key">
155 <dia:boolean val="true"/>
156 </dia:attribute>
157 <dia:attribute name="bold_primary_keys">
158 <dia:boolean val="true"/>
159 </dia:attribute>
160 <dia:attribute name="normal_font">
161 <dia:font family="monospace" style="0" name="Courier"/>
162 </dia:attribute>
163 <dia:attribute name="name_font">
164 <dia:font family="sans" style="80" name="Helvetica-Bold"/>
165 </dia:attribute>
166 <dia:attribute name="comment_font">
167 <dia:font family="sans" style="0" name="Helvetica"/>
168 </dia:attribute>
169 <dia:attribute name="normal_font_height">
170 <dia:real val="0.80000000000000004"/>
171 </dia:attribute>
172 <dia:attribute name="name_font_height">
173 <dia:real val="0.69999999999999996"/>
174 </dia:attribute>
175 <dia:attribute name="comment_font_height">
176 <dia:real val="0.69999999999999996"/>
177 </dia:attribute>'
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>
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>'
196 unset($pm);
197 $pm = 'false';
198 if (in_array($field, $this->primary)) {
199 $pm = 'true';
202 if ($field == $this->displayfield) {
203 $pm = 'false';
206 $this->diagram->writeRaw(
207 '<dia:attribute name="primary_key">
208 <dia:boolean val="' . $pm . '"/>
209 </dia:attribute>
210 <dia:attribute name="nullable">
211 <dia:boolean val="false"/>
212 </dia:attribute>
213 <dia:attribute name="unique">
214 <dia:boolean val="' . $pm . '"/>
215 </dia:attribute>
216 </dia:composite>'
220 $this->diagram->endElement();
221 $this->diagram->endElement();