Remove `@access` annotations
[phpmyadmin.git] / libraries / classes / Plugins / Schema / Pdf / TableStatsPdf.php
blobf84161fe1587b83b7d8b449066565fac4783a102
1 <?php
2 /**
3 * Contains PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf class
4 */
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;
14 use function __;
15 use function count;
16 use function in_array;
17 use function max;
18 use function sprintf;
20 /**
21 * Table preferences/statistics
23 * This class preserves the table co-ordinates,fields
24 * and helps in drawing/generating the Tables in PDF document.
26 * @see Schema\Pdf
28 * @property Pdf $diagram
30 class TableStatsPdf extends TableStats
32 /** @var int */
33 public $height;
35 /** @var string */
36 private $ff = PdfLib::PMA_PDF_FONT;
38 /**
39 * @see PMA_Schema_PDF
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
53 * from the browser
55 public function __construct(
56 $diagram,
57 $db,
58 $tableName,
59 $fontSize,
60 $pageNumber,
61 &$sameWideWidth,
62 $showKeys = false,
63 $tableDimension = false,
64 $offline = false
65 ) {
66 parent::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline);
68 $this->heightCell = 6;
69 $this->setHeight();
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) {
76 return;
79 $sameWideWidth = $this->width;
82 /**
83 * Displays an error when the table cannot be found.
85 protected function showMissingTableError(): void
87 ExportRelationSchema::dieSchema(
88 $this->pageNumber,
89 'PDF',
90 sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
94 /**
95 * Returns title of the current table,
96 * title can have the dimensions of the table
98 * @return string
100 protected function getTitle()
102 $ret = '';
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())) {
130 $this->width += 5;
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;
145 * Do draw the table
147 * @see Schema\Pdf
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);
157 if ($setColor) {
158 $this->diagram->SetTextColor(200);
159 $this->diagram->SetFillColor(0, 0, 128);
162 if ($withDoc) {
163 $this->diagram->SetLink($this->diagram->customLinks['RT'][$this->tableName]['-'], -1);
164 } else {
165 $this->diagram->customLinks['doc'][$this->tableName]['-'] = '';
168 $this->diagram->cellScale(
169 $this->width,
170 $this->heightCell,
171 $this->getTitle(),
174 'C',
175 $setColor,
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) {
184 if ($setColor) {
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);
194 if ($withDoc) {
195 $this->diagram->SetLink($this->diagram->customLinks['RT'][$this->tableName][$field], -1);
196 } else {
197 $this->diagram->customLinks['doc'][$this->tableName][$field] = '';
200 $this->diagram->cellScale(
201 $this->width,
202 $this->heightCell,
203 ' ' . $field,
206 'L',
207 $setColor,
208 $this->diagram->customLinks['doc'][$this->tableName][$field]
210 $this->diagram->setXScale($this->x);
211 $this->diagram->SetFillColor(255);