3 * Contains PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf class
6 declare(strict_types
=1);
8 namespace PhpMyAdmin\Plugins\Schema\Pdf
;
10 use PhpMyAdmin\Pdf
as PdfLib
;
11 use PhpMyAdmin\Plugins\Schema\ExportRelationSchema
;
12 use PhpMyAdmin\Plugins\Schema\TableStats
;
16 use function in_array
;
21 * Table preferences/statistics
23 * This class preserves the table co-ordinates,fields
24 * and helps in drawing/generating the Tables in PDF document.
28 * @property Pdf $diagram
30 class TableStatsPdf
extends TableStats
36 private $ff = PdfLib
::PMA_PDF_FONT
;
40 * @see TableStatsPdf::setWidthTable
41 * @see PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf::setHeightTable
43 * @param Pdf $diagram The PDF diagram
44 * @param string $db The database name
45 * @param string $tableName The table name
46 * @param int $fontSize The font size
47 * @param int $pageNumber The current page number (from the
48 * $cfg['Servers'][$i]['table_coords'] table)
49 * @param int $sameWideWidth The max. width among tables
50 * @param bool $showKeys Whether to display keys or not
51 * @param bool $tableDimension Whether to display table position or not
52 * @param bool $offline Whether the coordinates are sent
55 public function __construct(
63 $tableDimension = false,
66 parent
::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline);
68 $this->heightCell
= 6;
71 * setWidth must me after setHeight, because title
72 * can include table height which changes table width
74 $this->setWidth($fontSize);
75 if ($sameWideWidth >= $this->width
) {
79 $sameWideWidth = $this->width
;
83 * Displays an error when the table cannot be found.
85 protected function showMissingTableError(): void
87 ExportRelationSchema
::dieSchema(
90 sprintf(__('The %s table doesn\'t exist!'), $this->tableName
)
95 * Returns title of the current table,
96 * title can have the dimensions of the table
100 protected function getTitle()
103 if ($this->tableDimension
) {
104 $ret = sprintf('%.0fx%0.f', $this->width
, $this->height
);
107 return $ret . ' ' . $this->tableName
;
111 * Sets the width of the table
113 * @see PMA_Schema_PDF
115 * @param int $fontSize The font size
117 private function setWidth($fontSize): void
119 foreach ($this->fields
as $field) {
120 $this->width
= max($this->width
, $this->diagram
->GetStringWidth($field));
123 $this->width +
= $this->diagram
->GetStringWidth(' ');
124 $this->diagram
->SetFont($this->ff
, 'B', $fontSize);
126 * it is unknown what value must be added, because
127 * table title is affected by the table width value
129 while ($this->width
< $this->diagram
->GetStringWidth($this->getTitle())) {
133 $this->diagram
->SetFont($this->ff
, '', $fontSize);
137 * Sets the height of the table
139 private function setHeight(): void
141 $this->height
= (count($this->fields
) +
1) * $this->heightCell
;
149 * @param int|null $fontSize The font size or null to use the default value
150 * @param bool $withDoc Whether to include links to documentation
151 * @param bool $setColor Whether to display color
153 public function tableDraw(?
int $fontSize, bool $withDoc, bool $setColor = false): void
155 $this->diagram
->setXyScale($this->x
, $this->y
);
156 $this->diagram
->SetFont($this->ff
, 'B', $fontSize);
158 $this->diagram
->SetTextColor(200);
159 $this->diagram
->SetFillColor(0, 0, 128);
163 $this->diagram
->SetLink($this->diagram
->customLinks
['RT'][$this->tableName
]['-'], -1);
165 $this->diagram
->customLinks
['doc'][$this->tableName
]['-'] = '';
168 $this->diagram
->cellScale(
176 $this->diagram
->customLinks
['doc'][$this->tableName
]['-']
178 $this->diagram
->setXScale($this->x
);
179 $this->diagram
->SetFont($this->ff
, '', $fontSize);
180 $this->diagram
->SetTextColor(0);
181 $this->diagram
->SetFillColor(255);
183 foreach ($this->fields
as $field) {
185 if (in_array($field, $this->primary
)) {
186 $this->diagram
->SetFillColor(215, 121, 123);
189 if ($field == $this->displayfield
) {
190 $this->diagram
->SetFillColor(142, 159, 224);
195 $this->diagram
->SetLink($this->diagram
->customLinks
['RT'][$this->tableName
][$field], -1);
197 $this->diagram
->customLinks
['doc'][$this->tableName
][$field] = '';
200 $this->diagram
->cellScale(
208 $this->diagram
->customLinks
['doc'][$this->tableName
][$field]
210 $this->diagram
->setXScale($this->x
);
211 $this->diagram
->SetFillColor(255);