Update website
This commit is contained in:
parent
0a686aeb9a
commit
c4ffa0f6ee
4360 changed files with 1727 additions and 718385 deletions
|
@ -1,435 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PDF schema handling
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Plugins\Schema\Pdf;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use PhpMyAdmin\Pdf as PdfLib;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
use function __;
|
||||
use function count;
|
||||
use function getcwd;
|
||||
use function max;
|
||||
use function mb_ord;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
use function ucfirst;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
/**
|
||||
* block attempts to directly run this script
|
||||
*/
|
||||
if (getcwd() == __DIR__) {
|
||||
die('Attack stopped');
|
||||
}
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Extends the "TCPDF" class and helps
|
||||
* in developing the structure of PDF Schema Export
|
||||
*
|
||||
* @see TCPDF
|
||||
*/
|
||||
class Pdf extends PdfLib
|
||||
{
|
||||
/** @var int|float */
|
||||
public $xMin = 0;
|
||||
|
||||
/** @var int|float */
|
||||
public $yMin = 0;
|
||||
|
||||
/** @var int|float */
|
||||
public $leftMargin = 10;
|
||||
|
||||
/** @var int|float */
|
||||
public $topMargin = 10;
|
||||
|
||||
/** @var int|float */
|
||||
public $scale = 1;
|
||||
|
||||
/** @var array */
|
||||
public $customLinks = [];
|
||||
|
||||
/** @var array */
|
||||
public $widths = [];
|
||||
|
||||
/** @var float */
|
||||
public $cMargin = 0;
|
||||
|
||||
/** @var string */
|
||||
private $ff = PdfLib::PMA_PDF_FONT;
|
||||
|
||||
/** @var bool */
|
||||
private $offline = false;
|
||||
|
||||
/** @var int */
|
||||
private $pageNumber;
|
||||
|
||||
/** @var bool */
|
||||
private $withDoc;
|
||||
|
||||
/** @var string */
|
||||
private $db;
|
||||
|
||||
/** @var Relation */
|
||||
private $relation;
|
||||
|
||||
/**
|
||||
* Constructs PDF for schema export.
|
||||
*
|
||||
* @param string $orientation page orientation
|
||||
* @param string $unit unit
|
||||
* @param string $paper the format used for pages
|
||||
* @param int $pageNumber schema page number that is being exported
|
||||
* @param bool $withDoc with document dictionary
|
||||
* @param string $db the database name
|
||||
*/
|
||||
public function __construct(
|
||||
$orientation,
|
||||
$unit,
|
||||
$paper,
|
||||
$pageNumber,
|
||||
$withDoc,
|
||||
$db
|
||||
) {
|
||||
global $dbi;
|
||||
|
||||
parent::__construct($orientation, $unit, $paper);
|
||||
$this->pageNumber = $pageNumber;
|
||||
$this->withDoc = $withDoc;
|
||||
$this->db = $db;
|
||||
$this->relation = new Relation($dbi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for margins
|
||||
*
|
||||
* @param float $c_margin margin
|
||||
*/
|
||||
public function setCMargin($c_margin): void
|
||||
{
|
||||
$this->cMargin = $c_margin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scaling factor, defines minimum coordinates and margins
|
||||
*
|
||||
* @param float|int $scale The scaling factor
|
||||
* @param float|int $xMin The minimum X coordinate
|
||||
* @param float|int $yMin The minimum Y coordinate
|
||||
* @param float|int $leftMargin The left margin
|
||||
* @param float|int $topMargin The top margin
|
||||
*/
|
||||
public function setScale(
|
||||
$scale = 1,
|
||||
$xMin = 0,
|
||||
$yMin = 0,
|
||||
$leftMargin = -1,
|
||||
$topMargin = -1
|
||||
): void {
|
||||
$this->scale = $scale;
|
||||
$this->xMin = $xMin;
|
||||
$this->yMin = $yMin;
|
||||
if ($this->leftMargin != -1) {
|
||||
$this->leftMargin = $leftMargin;
|
||||
}
|
||||
|
||||
if ($this->topMargin == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->topMargin = $topMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a scaled cell
|
||||
*
|
||||
* @see TCPDF::Cell()
|
||||
*
|
||||
* @param float|int $w The cell width
|
||||
* @param float|int $h The cell height
|
||||
* @param string $txt The text to output
|
||||
* @param mixed $border Whether to add borders or not
|
||||
* @param int $ln Where to put the cursor once the output is done
|
||||
* @param string $align Align mode
|
||||
* @param bool $fill Whether to fill the cell with a color or not
|
||||
* @param string $link Link
|
||||
*/
|
||||
public function cellScale(
|
||||
$w,
|
||||
$h = 0,
|
||||
$txt = '',
|
||||
$border = 0,
|
||||
$ln = 0,
|
||||
$align = '',
|
||||
bool $fill = false,
|
||||
$link = ''
|
||||
): void {
|
||||
$h /= $this->scale;
|
||||
$w /= $this->scale;
|
||||
$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a scaled line
|
||||
*
|
||||
* @see TCPDF::Line()
|
||||
*
|
||||
* @param float $x1 The horizontal position of the starting point
|
||||
* @param float $y1 The vertical position of the starting point
|
||||
* @param float $x2 The horizontal position of the ending point
|
||||
* @param float $y2 The vertical position of the ending point
|
||||
*/
|
||||
public function lineScale($x1, $y1, $x2, $y2): void
|
||||
{
|
||||
$x1 = ($x1 - $this->xMin) / $this->scale + $this->leftMargin;
|
||||
$y1 = ($y1 - $this->yMin) / $this->scale + $this->topMargin;
|
||||
$x2 = ($x2 - $this->xMin) / $this->scale + $this->leftMargin;
|
||||
$y2 = ($y2 - $this->yMin) / $this->scale + $this->topMargin;
|
||||
$this->Line($x1, $y1, $x2, $y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets x and y scaled positions
|
||||
*
|
||||
* @see TCPDF::setXY()
|
||||
*
|
||||
* @param float $x The x position
|
||||
* @param float $y The y position
|
||||
*/
|
||||
public function setXyScale($x, $y): void
|
||||
{
|
||||
$x = ($x - $this->xMin) / $this->scale + $this->leftMargin;
|
||||
$y = ($y - $this->yMin) / $this->scale + $this->topMargin;
|
||||
$this->setXY($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the X scaled positions
|
||||
*
|
||||
* @see TCPDF::setX()
|
||||
*
|
||||
* @param float $x The x position
|
||||
*/
|
||||
public function setXScale($x): void
|
||||
{
|
||||
$x = ($x - $this->xMin) / $this->scale + $this->leftMargin;
|
||||
$this->setX($x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scaled font size
|
||||
*
|
||||
* @see TCPDF::setFontSize()
|
||||
*
|
||||
* @param float $size The font size (in points)
|
||||
*/
|
||||
public function setFontSizeScale($size): void
|
||||
{
|
||||
// Set font size in points
|
||||
$size /= $this->scale;
|
||||
$this->setFontSize($size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scaled line width
|
||||
*
|
||||
* @see TCPDF::setLineWidth()
|
||||
*
|
||||
* @param float $width The line width
|
||||
*/
|
||||
public function setLineWidthScale($width): void
|
||||
{
|
||||
$width /= $this->scale;
|
||||
$this->setLineWidth($width);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to render the page header.
|
||||
*
|
||||
* @see TCPDF::Header()
|
||||
*/
|
||||
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
public function Header(): void
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
// We only show this if we find something in the new pdf_pages table
|
||||
|
||||
// This function must be named "Header" to work with the TCPDF library
|
||||
if (! $this->withDoc) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pdfFeature = $this->relation->getRelationParameters()->pdfFeature;
|
||||
if ($this->offline || $this->pageNumber == -1 || $pdfFeature === null) {
|
||||
$pg_name = __('PDF export page');
|
||||
} else {
|
||||
$test_query = 'SELECT * FROM '
|
||||
. Util::backquote($pdfFeature->database) . '.'
|
||||
. Util::backquote($pdfFeature->pdfPages)
|
||||
. ' WHERE db_name = \'' . $dbi->escapeString($this->db)
|
||||
. '\' AND page_nr = \'' . $this->pageNumber . '\'';
|
||||
$test_rs = $dbi->queryAsControlUser($test_query);
|
||||
$pageDesc = (string) $test_rs->fetchValue('page_descr');
|
||||
|
||||
$pg_name = ucfirst($pageDesc);
|
||||
}
|
||||
|
||||
$this->setFont($this->ff, 'B', 14);
|
||||
$this->Cell(0, 6, $pg_name, 'B', 1, 'C');
|
||||
$this->setFont($this->ff, '');
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function must be named "Footer" to work with the TCPDF library
|
||||
*
|
||||
* @see PDF::Footer()
|
||||
*/
|
||||
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
public function Footer(): void
|
||||
{
|
||||
if (! $this->withDoc) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::Footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets widths
|
||||
*
|
||||
* @param array $w array of widths
|
||||
*/
|
||||
public function setWidths(array $w): void
|
||||
{
|
||||
// column widths
|
||||
$this->widths = $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates table row.
|
||||
*
|
||||
* @param array $data Data for table
|
||||
* @param array $links Links for table cells
|
||||
*/
|
||||
public function row(array $data, array $links): void
|
||||
{
|
||||
// line height
|
||||
$nb = 0;
|
||||
$data_cnt = count($data);
|
||||
for ($i = 0; $i < $data_cnt; $i++) {
|
||||
$nb = max($nb, $this->numLines($this->widths[$i], $data[$i]));
|
||||
}
|
||||
|
||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$il = $this->FontSize;
|
||||
$h = ($il + 1) * $nb;
|
||||
// page break if necessary
|
||||
$this->checkPageBreak($h);
|
||||
// draw the cells
|
||||
$data_cnt = count($data);
|
||||
for ($i = 0; $i < $data_cnt; $i++) {
|
||||
$w = $this->widths[$i];
|
||||
// save current position
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY();
|
||||
// draw the border
|
||||
$this->Rect($x, $y, $w, $h);
|
||||
if (isset($links[$i])) {
|
||||
$this->Link($x, $y, $w, $h, $links[$i]);
|
||||
}
|
||||
|
||||
// print text
|
||||
$this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
|
||||
// go to right side
|
||||
$this->setXY($x + $w, $y);
|
||||
}
|
||||
|
||||
// go to line
|
||||
$this->Ln($h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute number of lines used by a multicell of width w
|
||||
*
|
||||
* @param int $w width
|
||||
* @param string $txt text
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numLines($w, $txt)
|
||||
{
|
||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$cw = &$this->CurrentFont['cw'];
|
||||
if ($w == 0) {
|
||||
$w = $this->w - $this->rMargin - $this->x;
|
||||
}
|
||||
|
||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||
$s = str_replace("\r", '', $txt);
|
||||
$nb = strlen($s);
|
||||
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||
$nb--;
|
||||
}
|
||||
|
||||
$sep = -1;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
$l = 0;
|
||||
$nl = 1;
|
||||
while ($i < $nb) {
|
||||
$c = $s[$i];
|
||||
if ($c == "\n") {
|
||||
$i++;
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($c === ' ') {
|
||||
$sep = $i;
|
||||
}
|
||||
|
||||
$l += $cw[mb_ord($c)] ?? 0;
|
||||
if ($l > $wmax) {
|
||||
if ($sep == -1) {
|
||||
if ($i == $j) {
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$i = $sep + 1;
|
||||
}
|
||||
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return $nl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the document is generated from client side DB
|
||||
*
|
||||
* @param bool $value whether offline
|
||||
*/
|
||||
public function setOffline($value): void
|
||||
{
|
||||
$this->offline = $value;
|
||||
}
|
||||
}
|
|
@ -1,781 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PDF schema handling
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Plugins\Schema\Pdf;
|
||||
|
||||
use PhpMyAdmin\Pdf as PdfLib;
|
||||
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
use function __;
|
||||
use function ceil;
|
||||
use function getcwd;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function max;
|
||||
use function min;
|
||||
use function rsort;
|
||||
use function sort;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strtotime;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
/**
|
||||
* block attempts to directly run this script
|
||||
*/
|
||||
if (getcwd() == __DIR__) {
|
||||
die('Attack stopped');
|
||||
}
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Pdf Relation Schema Class
|
||||
*
|
||||
* Purpose of this class is to generate the PDF Document. PDF is widely
|
||||
* used format for documenting text,fonts,images and 3d vector graphics.
|
||||
*
|
||||
* This class inherits ExportRelationSchema class has common functionality added
|
||||
* to this class
|
||||
*
|
||||
* @property Pdf $diagram
|
||||
*/
|
||||
class PdfRelationSchema extends ExportRelationSchema
|
||||
{
|
||||
/** @var bool */
|
||||
private $showGrid = false;
|
||||
|
||||
/** @var bool */
|
||||
private $withDoc = false;
|
||||
|
||||
/** @var string */
|
||||
private $tableOrder = '';
|
||||
|
||||
/** @var TableStatsPdf[] */
|
||||
private $tables = [];
|
||||
|
||||
/** @var string */
|
||||
private $ff = PdfLib::PMA_PDF_FONT;
|
||||
|
||||
/** @var int|float */
|
||||
private $xMax = 0;
|
||||
|
||||
/** @var int|float */
|
||||
private $yMax = 0;
|
||||
|
||||
/** @var float|int */
|
||||
private $scale;
|
||||
|
||||
/** @var int|float */
|
||||
private $xMin = 100000;
|
||||
|
||||
/** @var int|float */
|
||||
private $yMin = 100000;
|
||||
|
||||
/** @var int */
|
||||
private $topMargin = 10;
|
||||
|
||||
/** @var int */
|
||||
private $bottomMargin = 10;
|
||||
|
||||
/** @var int */
|
||||
private $leftMargin = 10;
|
||||
|
||||
/** @var int */
|
||||
private $rightMargin = 10;
|
||||
|
||||
/** @var int */
|
||||
private $tablewidth = 0;
|
||||
|
||||
/** @var RelationStatsPdf[] */
|
||||
protected $relations = [];
|
||||
|
||||
/** @var Transformations */
|
||||
private $transformations;
|
||||
|
||||
/**
|
||||
* @see Schema\Pdf
|
||||
*
|
||||
* @param string $db database name
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->transformations = new Transformations();
|
||||
|
||||
$this->setShowGrid(isset($_REQUEST['pdf_show_grid']));
|
||||
$this->setShowColor(isset($_REQUEST['pdf_show_color']));
|
||||
$this->setShowKeys(isset($_REQUEST['pdf_show_keys']));
|
||||
$this->setTableDimension(isset($_REQUEST['pdf_show_table_dimension']));
|
||||
$this->setAllTablesSameWidth(isset($_REQUEST['pdf_all_tables_same_width']));
|
||||
$this->setWithDataDictionary(isset($_REQUEST['pdf_with_doc']));
|
||||
$this->setTableOrder($_REQUEST['pdf_table_order']);
|
||||
$this->setOrientation((string) $_REQUEST['pdf_orientation']);
|
||||
$this->setPaper((string) $_REQUEST['pdf_paper']);
|
||||
|
||||
// Initializes a new document
|
||||
parent::__construct(
|
||||
$db,
|
||||
new Pdf(
|
||||
$this->orientation,
|
||||
'mm',
|
||||
$this->paper,
|
||||
$this->pageNumber,
|
||||
$this->withDoc,
|
||||
$db
|
||||
)
|
||||
);
|
||||
$this->diagram->setTitle(
|
||||
sprintf(
|
||||
__('Schema of the %s database'),
|
||||
$this->db
|
||||
)
|
||||
);
|
||||
$this->diagram->setCMargin(0);
|
||||
$this->diagram->Open();
|
||||
$this->diagram->setAutoPageBreak(true);
|
||||
$this->diagram->setOffline($this->offline);
|
||||
|
||||
$alltables = $this->getTablesFromRequest();
|
||||
if ($this->getTableOrder() === 'name_asc') {
|
||||
sort($alltables);
|
||||
} elseif ($this->getTableOrder() === 'name_desc') {
|
||||
rsort($alltables);
|
||||
}
|
||||
|
||||
if ($this->withDoc) {
|
||||
$this->diagram->setAutoPageBreak(true, 15);
|
||||
$this->diagram->setCMargin(1);
|
||||
$this->dataDictionaryDoc($alltables);
|
||||
$this->diagram->setAutoPageBreak(true);
|
||||
$this->diagram->setCMargin(0);
|
||||
}
|
||||
|
||||
$this->diagram->AddPage();
|
||||
|
||||
if ($this->withDoc) {
|
||||
$this->diagram->setLink($this->diagram->customLinks['RT']['-'], -1);
|
||||
$this->diagram->Bookmark(__('Relational schema'));
|
||||
$this->diagram->setAlias('{00}', $this->diagram->PageNo());
|
||||
$this->topMargin = 28;
|
||||
$this->bottomMargin = 28;
|
||||
}
|
||||
|
||||
/* snip */
|
||||
foreach ($alltables as $table) {
|
||||
if (! isset($this->tables[$table])) {
|
||||
$this->tables[$table] = new TableStatsPdf(
|
||||
$this->diagram,
|
||||
$this->db,
|
||||
$table,
|
||||
null,
|
||||
$this->pageNumber,
|
||||
$this->tablewidth,
|
||||
$this->showKeys,
|
||||
$this->tableDimension,
|
||||
$this->offline
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->sameWide) {
|
||||
$this->tables[$table]->width = $this->tablewidth;
|
||||
}
|
||||
|
||||
$this->setMinMax($this->tables[$table]);
|
||||
}
|
||||
|
||||
// Defines the scale factor
|
||||
$innerWidth = $this->diagram->getPageWidth() - $this->rightMargin
|
||||
- $this->leftMargin;
|
||||
$innerHeight = $this->diagram->getPageHeight() - $this->topMargin
|
||||
- $this->bottomMargin;
|
||||
$this->scale = ceil(
|
||||
max(
|
||||
($this->xMax - $this->xMin) / $innerWidth,
|
||||
($this->yMax - $this->yMin) / $innerHeight
|
||||
) * 100
|
||||
) / 100;
|
||||
|
||||
$this->diagram->setScale($this->scale, $this->xMin, $this->yMin, $this->leftMargin, $this->topMargin);
|
||||
// Builds and save the PDF document
|
||||
$this->diagram->setLineWidthScale(0.1);
|
||||
|
||||
if ($this->showGrid) {
|
||||
$this->diagram->setFontSize(10);
|
||||
$this->strokeGrid();
|
||||
}
|
||||
|
||||
$this->diagram->setFontSizeScale(14);
|
||||
// previous logic was checking master tables and foreign tables
|
||||
// but I think that looping on every table of the pdf page as a master
|
||||
// and finding its foreigns is OK (then we can support innodb)
|
||||
$seen_a_relation = false;
|
||||
foreach ($alltables as $one_table) {
|
||||
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
|
||||
if (! $exist_rel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen_a_relation = true;
|
||||
foreach ($exist_rel as $master_field => $rel) {
|
||||
// put the foreign table on the schema only if selected
|
||||
// by the user
|
||||
// (do not use array_search() because we would have to
|
||||
// to do a === false and this is not PHP3 compatible)
|
||||
if ($master_field !== 'foreign_keys_data') {
|
||||
if (in_array($rel['foreign_table'], $alltables)) {
|
||||
$this->addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($rel as $one_key) {
|
||||
if (! in_array($one_key['ref_table_name'], $alltables)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($one_key['index_list'] as $index => $one_field) {
|
||||
$this->addRelation(
|
||||
$one_table,
|
||||
$one_field,
|
||||
$one_key['ref_table_name'],
|
||||
$one_key['ref_index_list'][$index]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($seen_a_relation) {
|
||||
$this->drawRelations();
|
||||
}
|
||||
|
||||
$this->drawTables();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Show Grid
|
||||
*
|
||||
* @param bool $value show grid of the document or not
|
||||
*/
|
||||
public function setShowGrid($value): void
|
||||
{
|
||||
$this->showGrid = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to show grid
|
||||
*/
|
||||
public function isShowGrid(): bool
|
||||
{
|
||||
return $this->showGrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Data Dictionary
|
||||
*
|
||||
* @param bool $value show selected database data dictionary or not
|
||||
*/
|
||||
public function setWithDataDictionary($value): void
|
||||
{
|
||||
$this->withDoc = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to show selected database data dictionary or not
|
||||
*/
|
||||
public function isWithDataDictionary(): bool
|
||||
{
|
||||
return $this->withDoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the order of the table in data dictionary
|
||||
*
|
||||
* @param string $value table order
|
||||
*/
|
||||
public function setTableOrder($value): void
|
||||
{
|
||||
$this->tableOrder = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order of the table in data dictionary
|
||||
*
|
||||
* @return string table order
|
||||
*/
|
||||
public function getTableOrder()
|
||||
{
|
||||
return $this->tableOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output Pdf Document for download
|
||||
*/
|
||||
public function showOutput(): void
|
||||
{
|
||||
$this->diagram->download($this->getFileName('.pdf'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets X and Y minimum and maximum for a table cell
|
||||
*
|
||||
* @param TableStatsPdf $table The table name of which sets XY co-ordinates
|
||||
*/
|
||||
private function setMinMax($table): void
|
||||
{
|
||||
$this->xMax = max($this->xMax, $table->x + $table->width);
|
||||
$this->yMax = max($this->yMax, $table->y + $table->height);
|
||||
$this->xMin = min($this->xMin, $table->x);
|
||||
$this->yMin = min($this->yMin, $table->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines relation objects
|
||||
*
|
||||
* @see setMinMax
|
||||
*
|
||||
* @param string $masterTable The master table name
|
||||
* @param string $masterField The relation field in the master table
|
||||
* @param string $foreignTable The foreign table name
|
||||
* @param string $foreignField The relation field in the foreign table
|
||||
*/
|
||||
private function addRelation(
|
||||
$masterTable,
|
||||
$masterField,
|
||||
$foreignTable,
|
||||
$foreignField
|
||||
): void {
|
||||
if (! isset($this->tables[$masterTable])) {
|
||||
$this->tables[$masterTable] = new TableStatsPdf(
|
||||
$this->diagram,
|
||||
$this->db,
|
||||
$masterTable,
|
||||
null,
|
||||
$this->pageNumber,
|
||||
$this->tablewidth,
|
||||
$this->showKeys,
|
||||
$this->tableDimension
|
||||
);
|
||||
$this->setMinMax($this->tables[$masterTable]);
|
||||
}
|
||||
|
||||
if (! isset($this->tables[$foreignTable])) {
|
||||
$this->tables[$foreignTable] = new TableStatsPdf(
|
||||
$this->diagram,
|
||||
$this->db,
|
||||
$foreignTable,
|
||||
null,
|
||||
$this->pageNumber,
|
||||
$this->tablewidth,
|
||||
$this->showKeys,
|
||||
$this->tableDimension
|
||||
);
|
||||
$this->setMinMax($this->tables[$foreignTable]);
|
||||
}
|
||||
|
||||
$this->relations[] = new RelationStatsPdf(
|
||||
$this->diagram,
|
||||
$this->tables[$masterTable],
|
||||
$masterField,
|
||||
$this->tables[$foreignTable],
|
||||
$foreignField
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the grid
|
||||
*
|
||||
* @see PMA_Schema_PDF
|
||||
*/
|
||||
private function strokeGrid(): void
|
||||
{
|
||||
$gridSize = 10;
|
||||
$labelHeight = 4;
|
||||
$labelWidth = 5;
|
||||
if ($this->withDoc) {
|
||||
$topSpace = 6;
|
||||
$bottomSpace = 15;
|
||||
} else {
|
||||
$topSpace = 0;
|
||||
$bottomSpace = 0;
|
||||
}
|
||||
|
||||
$this->diagram->setMargins(0, 0);
|
||||
$this->diagram->setDrawColor(200, 200, 200);
|
||||
// Draws horizontal lines
|
||||
$innerHeight = $this->diagram->getPageHeight() - $topSpace - $bottomSpace;
|
||||
for ($l = 0, $size = intval($innerHeight / $gridSize); $l <= $size; $l++) {
|
||||
$this->diagram->line(
|
||||
0,
|
||||
$l * $gridSize + $topSpace,
|
||||
$this->diagram->getPageWidth(),
|
||||
$l * $gridSize + $topSpace
|
||||
);
|
||||
// Avoid duplicates
|
||||
if ($l <= 0 || $l > intval(($innerHeight - $labelHeight) / $gridSize)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->diagram->setXY(0, $l * $gridSize + $topSpace);
|
||||
$label = (string) sprintf(
|
||||
'%.0f',
|
||||
($l * $gridSize + $topSpace - $this->topMargin)
|
||||
* $this->scale + $this->yMin
|
||||
);
|
||||
$this->diagram->Cell($labelWidth, $labelHeight, ' ' . $label);
|
||||
}
|
||||
|
||||
// Draws vertical lines
|
||||
for ($j = 0, $size = intval($this->diagram->getPageWidth() / $gridSize); $j <= $size; $j++) {
|
||||
$this->diagram->line(
|
||||
$j * $gridSize,
|
||||
$topSpace,
|
||||
$j * $gridSize,
|
||||
$this->diagram->getPageHeight() - $bottomSpace
|
||||
);
|
||||
$this->diagram->setXY($j * $gridSize, $topSpace);
|
||||
$label = (string) sprintf('%.0f', ($j * $gridSize - $this->leftMargin) * $this->scale + $this->xMin);
|
||||
$this->diagram->Cell($labelWidth, $labelHeight, $label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws relation arrows
|
||||
*
|
||||
* @see Relation_Stats_Pdf::relationdraw()
|
||||
*/
|
||||
private function drawRelations(): void
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->relations as $relation) {
|
||||
$relation->relationDraw($this->showColor, $i);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws tables
|
||||
*
|
||||
* @see TableStatsPdf::tableDraw()
|
||||
*/
|
||||
private function drawTables(): void
|
||||
{
|
||||
foreach ($this->tables as $table) {
|
||||
$table->tableDraw(null, $this->withDoc, $this->showColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates data dictionary pages.
|
||||
*
|
||||
* @param array $alltables Tables to document.
|
||||
*/
|
||||
public function dataDictionaryDoc(array $alltables): void
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
// TOC
|
||||
$this->diagram->AddPage($this->orientation);
|
||||
$this->diagram->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
|
||||
$this->diagram->Ln(15);
|
||||
$i = 1;
|
||||
foreach ($alltables as $table) {
|
||||
$this->diagram->customLinks['doc'][$table]['-'] = $this->diagram->AddLink();
|
||||
$this->diagram->setX(10);
|
||||
// $this->diagram->Ln(1);
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
6,
|
||||
__('Page number:') . ' {' . sprintf('%02d', $i) . '}',
|
||||
0,
|
||||
0,
|
||||
'R',
|
||||
false,
|
||||
$this->diagram->customLinks['doc'][$table]['-']
|
||||
);
|
||||
$this->diagram->setX(10);
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
6,
|
||||
$i . ' ' . $table,
|
||||
0,
|
||||
1,
|
||||
'L',
|
||||
false,
|
||||
$this->diagram->customLinks['doc'][$table]['-']
|
||||
);
|
||||
// $this->diagram->Ln(1);
|
||||
$fields = $dbi->getColumns($this->db, $table);
|
||||
foreach ($fields as $row) {
|
||||
$this->diagram->setX(20);
|
||||
$field_name = $row['Field'];
|
||||
$this->diagram->customLinks['doc'][$table][$field_name] = $this->diagram->AddLink();
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->diagram->customLinks['RT']['-'] = $this->diagram->AddLink();
|
||||
$this->diagram->setX(10);
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
6,
|
||||
__('Page number:') . ' {00}',
|
||||
0,
|
||||
0,
|
||||
'R',
|
||||
false,
|
||||
$this->diagram->customLinks['RT']['-']
|
||||
);
|
||||
$this->diagram->setX(10);
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
6,
|
||||
$i . ' ' . __('Relational schema'),
|
||||
0,
|
||||
1,
|
||||
'L',
|
||||
false,
|
||||
$this->diagram->customLinks['RT']['-']
|
||||
);
|
||||
$z = 0;
|
||||
foreach ($alltables as $table) {
|
||||
$z++;
|
||||
$this->diagram->setAutoPageBreak(true, 15);
|
||||
$this->diagram->AddPage($this->orientation);
|
||||
$this->diagram->Bookmark($table);
|
||||
$this->diagram->setAlias(
|
||||
'{' . sprintf('%02d', $z) . '}',
|
||||
$this->diagram->PageNo()
|
||||
);
|
||||
$this->diagram->customLinks['RT'][$table]['-'] = $this->diagram->AddLink();
|
||||
$this->diagram->setLink($this->diagram->customLinks['doc'][$table]['-'], -1);
|
||||
$this->diagram->setFont($this->ff, 'B', 18);
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
8,
|
||||
$z . ' ' . $table,
|
||||
1,
|
||||
1,
|
||||
'C',
|
||||
false,
|
||||
$this->diagram->customLinks['RT'][$table]['-']
|
||||
);
|
||||
$this->diagram->setFont($this->ff, '', 8);
|
||||
$this->diagram->Ln();
|
||||
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
$comments = $this->relation->getComments($this->db, $table);
|
||||
if ($relationParameters->browserTransformationFeature !== null) {
|
||||
$mime_map = $this->transformations->getMime($this->db, $table, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets table information
|
||||
*/
|
||||
$showtable = $dbi->getTable($this->db, $table)
|
||||
->getStatusInfo();
|
||||
$show_comment = $showtable['Comment'] ?? '';
|
||||
$create_time = isset($showtable['Create_time'])
|
||||
? Util::localisedDate(
|
||||
strtotime($showtable['Create_time'])
|
||||
)
|
||||
: '';
|
||||
$update_time = isset($showtable['Update_time'])
|
||||
? Util::localisedDate(
|
||||
strtotime($showtable['Update_time'])
|
||||
)
|
||||
: '';
|
||||
$check_time = isset($showtable['Check_time'])
|
||||
? Util::localisedDate(
|
||||
strtotime($showtable['Check_time'])
|
||||
)
|
||||
: '';
|
||||
|
||||
/**
|
||||
* Gets fields properties
|
||||
*/
|
||||
$columns = $dbi->getColumns($this->db, $table);
|
||||
|
||||
// Find which tables are related with the current one and write it in
|
||||
// an array
|
||||
$res_rel = $this->relation->getForeigners($this->db, $table);
|
||||
|
||||
/**
|
||||
* Displays the comments of the table if MySQL >= 3.23
|
||||
*/
|
||||
|
||||
$break = false;
|
||||
if (! empty($show_comment)) {
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
3,
|
||||
__('Table comments:') . ' ' . $show_comment,
|
||||
0,
|
||||
1
|
||||
);
|
||||
$break = true;
|
||||
}
|
||||
|
||||
if (! empty($create_time)) {
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
3,
|
||||
__('Creation:') . ' ' . $create_time,
|
||||
0,
|
||||
1
|
||||
);
|
||||
$break = true;
|
||||
}
|
||||
|
||||
if (! empty($update_time)) {
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
3,
|
||||
__('Last update:') . ' ' . $update_time,
|
||||
0,
|
||||
1
|
||||
);
|
||||
$break = true;
|
||||
}
|
||||
|
||||
if (! empty($check_time)) {
|
||||
$this->diagram->Cell(
|
||||
0,
|
||||
3,
|
||||
__('Last check:') . ' ' . $check_time,
|
||||
0,
|
||||
1
|
||||
);
|
||||
$break = true;
|
||||
}
|
||||
|
||||
if ($break == true) {
|
||||
$this->diagram->Cell(0, 3, '', 0, 1);
|
||||
$this->diagram->Ln();
|
||||
}
|
||||
|
||||
$this->diagram->setFont($this->ff, 'B');
|
||||
if (isset($this->orientation) && $this->orientation === 'L') {
|
||||
$this->diagram->Cell(25, 8, __('Column'), 1, 0, 'C');
|
||||
$this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C');
|
||||
$this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C');
|
||||
$this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C');
|
||||
$this->diagram->Cell(20, 8, __('Default'), 1, 0, 'C');
|
||||
$this->diagram->Cell(25, 8, __('Extra'), 1, 0, 'C');
|
||||
$this->diagram->Cell(45, 8, __('Links to'), 1, 0, 'C');
|
||||
|
||||
if ($this->paper === 'A4') {
|
||||
$comments_width = 67;
|
||||
} else {
|
||||
// this is really intended for 'letter'
|
||||
/**
|
||||
* @todo find optimal width for all formats
|
||||
*/
|
||||
$comments_width = 50;
|
||||
}
|
||||
|
||||
$this->diagram->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
|
||||
$this->diagram->Cell(45, 8, 'MIME', 1, 1, 'C');
|
||||
$this->diagram->setWidths(
|
||||
[
|
||||
25,
|
||||
20,
|
||||
20,
|
||||
10,
|
||||
20,
|
||||
25,
|
||||
45,
|
||||
$comments_width,
|
||||
45,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->diagram->Cell(20, 8, __('Column'), 1, 0, 'C');
|
||||
$this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C');
|
||||
$this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C');
|
||||
$this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C');
|
||||
$this->diagram->Cell(15, 8, __('Default'), 1, 0, 'C');
|
||||
$this->diagram->Cell(15, 8, __('Extra'), 1, 0, 'C');
|
||||
$this->diagram->Cell(30, 8, __('Links to'), 1, 0, 'C');
|
||||
$this->diagram->Cell(30, 8, __('Comments'), 1, 0, 'C');
|
||||
$this->diagram->Cell(30, 8, 'MIME', 1, 1, 'C');
|
||||
$this->diagram->setWidths([20, 20, 20, 10, 15, 15, 30, 30, 30]);
|
||||
}
|
||||
|
||||
$this->diagram->setFont($this->ff, '');
|
||||
|
||||
foreach ($columns as $row) {
|
||||
$extracted_columnspec = Util::extractColumnSpec($row['Type']);
|
||||
$type = $extracted_columnspec['print_type'];
|
||||
$attribute = $extracted_columnspec['attribute'];
|
||||
if (! isset($row['Default'])) {
|
||||
if ($row['Null'] != '' && $row['Null'] !== 'NO') {
|
||||
$row['Default'] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
$field_name = $row['Field'];
|
||||
// $this->diagram->Ln();
|
||||
$this->diagram->customLinks['RT'][$table][$field_name] = $this->diagram->AddLink();
|
||||
$this->diagram->Bookmark($field_name, 1, -1);
|
||||
$this->diagram->setLink($this->diagram->customLinks['doc'][$table][$field_name], -1);
|
||||
$foreigner = $this->relation->searchColumnInForeigners($res_rel, $field_name);
|
||||
|
||||
$linksTo = '';
|
||||
if ($foreigner) {
|
||||
$linksTo = '-> ';
|
||||
if ($foreigner['foreign_db'] != $this->db) {
|
||||
$linksTo .= $foreigner['foreign_db'] . '.';
|
||||
}
|
||||
|
||||
$linksTo .= $foreigner['foreign_table']
|
||||
. '.' . $foreigner['foreign_field'];
|
||||
|
||||
if (isset($foreigner['on_update'])) { // not set for internal
|
||||
$linksTo .= "\n" . 'ON UPDATE ' . $foreigner['on_update'];
|
||||
$linksTo .= "\n" . 'ON DELETE ' . $foreigner['on_delete'];
|
||||
}
|
||||
}
|
||||
|
||||
$diagram_row = [
|
||||
$field_name,
|
||||
$type,
|
||||
$attribute,
|
||||
$row['Null'] == '' || $row['Null'] === 'NO'
|
||||
? __('No')
|
||||
: __('Yes'),
|
||||
$row['Default'] ?? '',
|
||||
$row['Extra'],
|
||||
$linksTo,
|
||||
$comments[$field_name] ?? '',
|
||||
isset($mime_map, $mime_map[$field_name])
|
||||
? str_replace('_', '/', $mime_map[$field_name]['mimetype'])
|
||||
: '',
|
||||
];
|
||||
$links = [];
|
||||
$links[0] = $this->diagram->customLinks['RT'][$table][$field_name];
|
||||
if (
|
||||
$foreigner
|
||||
&& isset(
|
||||
$this->diagram->customLinks['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]
|
||||
)
|
||||
) {
|
||||
$foreignTable = $this->diagram->customLinks['doc'][$foreigner['foreign_table']];
|
||||
$links[6] = $foreignTable[$foreigner['foreign_field']];
|
||||
}
|
||||
|
||||
$this->diagram->row($diagram_row, $links);
|
||||
}
|
||||
|
||||
$this->diagram->setFont($this->ff, '', 14);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Contains PhpMyAdmin\Plugins\Schema\Pdf\RelationStatsPdf class
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Plugins\Schema\Pdf;
|
||||
|
||||
use PhpMyAdmin\Plugins\Schema\RelationStats;
|
||||
|
||||
use function sqrt;
|
||||
|
||||
/**
|
||||
* Relation preferences/statistics
|
||||
*
|
||||
* This class fetches the table master and foreign fields positions
|
||||
* and helps in generating the Table references and then connects
|
||||
* master table's master field to foreign table's foreign key
|
||||
* in PDF document.
|
||||
*
|
||||
* @see Schema\Pdf::setDrawColor
|
||||
* @see Schema\Pdf::setLineWidthScale
|
||||
* @see Pdf::lineScale
|
||||
*/
|
||||
class RelationStatsPdf extends RelationStats
|
||||
{
|
||||
/**
|
||||
* @param Pdf $diagram The PDF diagram
|
||||
* @param string $master_table The master table name
|
||||
* @param string $master_field The relation field in the master table
|
||||
* @param string $foreign_table The foreign table name
|
||||
* @param string $foreign_field The relation field in the foreign table
|
||||
*/
|
||||
public function __construct(
|
||||
$diagram,
|
||||
$master_table,
|
||||
$master_field,
|
||||
$foreign_table,
|
||||
$foreign_field
|
||||
) {
|
||||
$this->wTick = 5;
|
||||
parent::__construct($diagram, $master_table, $master_field, $foreign_table, $foreign_field);
|
||||
}
|
||||
|
||||
/**
|
||||
* draws relation links and arrows shows foreign key relations
|
||||
*
|
||||
* @see Pdf
|
||||
*
|
||||
* @param bool $showColor Whether to use one color per relation or not
|
||||
* @param int $i The id of the link to draw
|
||||
*/
|
||||
public function relationDraw($showColor, $i): void
|
||||
{
|
||||
if ($showColor) {
|
||||
$d = $i % 6;
|
||||
$j = ($i - $d) / 6;
|
||||
$j %= 4;
|
||||
$j++;
|
||||
$case = [
|
||||
[
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
[
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
],
|
||||
[
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
],
|
||||
[
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
],
|
||||
[
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
],
|
||||
];
|
||||
[$a, $b, $c] = $case[$d];
|
||||
$e = 1 - ($j - 1) / 6;
|
||||
$this->diagram->setDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
|
||||
} else {
|
||||
$this->diagram->setDrawColor(0);
|
||||
}
|
||||
|
||||
$this->diagram->setLineWidthScale(0.2);
|
||||
$this->diagram->lineScale($this->xSrc, $this->ySrc, $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc);
|
||||
$this->diagram->lineScale(
|
||||
$this->xDest + $this->destDir * $this->wTick,
|
||||
$this->yDest,
|
||||
$this->xDest,
|
||||
$this->yDest
|
||||
);
|
||||
$this->diagram->setLineWidthScale(0.1);
|
||||
$this->diagram->lineScale(
|
||||
$this->xSrc + $this->srcDir * $this->wTick,
|
||||
$this->ySrc,
|
||||
$this->xDest + $this->destDir * $this->wTick,
|
||||
$this->yDest
|
||||
);
|
||||
/*
|
||||
* Draws arrows ->
|
||||
*/
|
||||
$root2 = 2 * sqrt(2);
|
||||
$this->diagram->lineScale(
|
||||
$this->xSrc + $this->srcDir * $this->wTick * 0.75,
|
||||
$this->ySrc,
|
||||
$this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
|
||||
$this->ySrc + $this->wTick / $root2
|
||||
);
|
||||
$this->diagram->lineScale(
|
||||
$this->xSrc + $this->srcDir * $this->wTick * 0.75,
|
||||
$this->ySrc,
|
||||
$this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
|
||||
$this->ySrc - $this->wTick / $root2
|
||||
);
|
||||
|
||||
$this->diagram->lineScale(
|
||||
$this->xDest + $this->destDir * $this->wTick / 2,
|
||||
$this->yDest,
|
||||
$this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
|
||||
$this->yDest + $this->wTick / $root2
|
||||
);
|
||||
$this->diagram->lineScale(
|
||||
$this->xDest + $this->destDir * $this->wTick / 2,
|
||||
$this->yDest,
|
||||
$this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
|
||||
$this->yDest - $this->wTick / $root2
|
||||
);
|
||||
$this->diagram->setDrawColor(0);
|
||||
}
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Contains PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf class
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Plugins\Schema\Pdf;
|
||||
|
||||
use PhpMyAdmin\Pdf as PdfLib;
|
||||
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
|
||||
use PhpMyAdmin\Plugins\Schema\TableStats;
|
||||
|
||||
use function __;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function max;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Table preferences/statistics
|
||||
*
|
||||
* This class preserves the table co-ordinates,fields
|
||||
* and helps in drawing/generating the Tables in PDF document.
|
||||
*
|
||||
* @see Schema\Pdf
|
||||
*
|
||||
* @property Pdf $diagram
|
||||
*/
|
||||
class TableStatsPdf extends TableStats
|
||||
{
|
||||
/** @var int */
|
||||
public $height;
|
||||
|
||||
/** @var string */
|
||||
private $ff = PdfLib::PMA_PDF_FONT;
|
||||
|
||||
/**
|
||||
* @see PMA_Schema_PDF
|
||||
* @see TableStatsPdf::setWidthTable
|
||||
* @see PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf::setHeightTable
|
||||
*
|
||||
* @param Pdf $diagram The PDF diagram
|
||||
* @param string $db The database name
|
||||
* @param string $tableName The table name
|
||||
* @param int $fontSize The font size
|
||||
* @param int $pageNumber The current page number (from the
|
||||
* $cfg['Servers'][$i]['table_coords'] table)
|
||||
* @param int $sameWideWidth The max. width among tables
|
||||
* @param bool $showKeys Whether to display keys or not
|
||||
* @param bool $tableDimension Whether to display table position or not
|
||||
* @param bool $offline Whether the coordinates are sent
|
||||
* from the browser
|
||||
*/
|
||||
public function __construct(
|
||||
$diagram,
|
||||
$db,
|
||||
$tableName,
|
||||
$fontSize,
|
||||
$pageNumber,
|
||||
&$sameWideWidth,
|
||||
$showKeys = false,
|
||||
$tableDimension = false,
|
||||
$offline = false
|
||||
) {
|
||||
parent::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline);
|
||||
|
||||
$this->heightCell = 6;
|
||||
$this->setHeight();
|
||||
/*
|
||||
* setWidth must me after setHeight, because title
|
||||
* can include table height which changes table width
|
||||
*/
|
||||
$this->setWidth($fontSize);
|
||||
if ($sameWideWidth >= $this->width) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sameWideWidth = $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error when the table cannot be found.
|
||||
*/
|
||||
protected function showMissingTableError(): void
|
||||
{
|
||||
ExportRelationSchema::dieSchema(
|
||||
$this->pageNumber,
|
||||
'PDF',
|
||||
sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title of the current table,
|
||||
* title can have the dimensions of the table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
$ret = '';
|
||||
if ($this->tableDimension) {
|
||||
$ret = sprintf('%.0fx%0.f', $this->width, $this->height);
|
||||
}
|
||||
|
||||
return $ret . ' ' . $this->tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the table
|
||||
*
|
||||
* @see PMA_Schema_PDF
|
||||
*
|
||||
* @param int $fontSize The font size
|
||||
*/
|
||||
private function setWidth($fontSize): void
|
||||
{
|
||||
foreach ($this->fields as $field) {
|
||||
$this->width = max($this->width, $this->diagram->GetStringWidth($field));
|
||||
}
|
||||
|
||||
$this->width += $this->diagram->GetStringWidth(' ');
|
||||
$this->diagram->setFont($this->ff, 'B', $fontSize);
|
||||
/*
|
||||
* it is unknown what value must be added, because
|
||||
* table title is affected by the table width value
|
||||
*/
|
||||
while ($this->width < $this->diagram->GetStringWidth($this->getTitle())) {
|
||||
$this->width += 5;
|
||||
}
|
||||
|
||||
$this->diagram->setFont($this->ff, '', $fontSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the height of the table
|
||||
*/
|
||||
private function setHeight(): void
|
||||
{
|
||||
$this->height = (count($this->fields) + 1) * $this->heightCell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do draw the table
|
||||
*
|
||||
* @see Schema\Pdf
|
||||
*
|
||||
* @param int|null $fontSize The font size or null to use the default value
|
||||
* @param bool $withDoc Whether to include links to documentation
|
||||
* @param bool $setColor Whether to display color
|
||||
*/
|
||||
public function tableDraw(?int $fontSize, bool $withDoc, bool $setColor = false): void
|
||||
{
|
||||
$this->diagram->setXyScale($this->x, $this->y);
|
||||
$this->diagram->setFont($this->ff, 'B', $fontSize);
|
||||
if ($setColor) {
|
||||
$this->diagram->setTextColor(200);
|
||||
$this->diagram->setFillColor(0, 0, 128);
|
||||
}
|
||||
|
||||
if ($withDoc) {
|
||||
$this->diagram->setLink($this->diagram->customLinks['RT'][$this->tableName]['-'], -1);
|
||||
} else {
|
||||
$this->diagram->customLinks['doc'][$this->tableName]['-'] = '';
|
||||
}
|
||||
|
||||
$this->diagram->cellScale(
|
||||
$this->width,
|
||||
$this->heightCell,
|
||||
$this->getTitle(),
|
||||
1,
|
||||
1,
|
||||
'C',
|
||||
$setColor,
|
||||
$this->diagram->customLinks['doc'][$this->tableName]['-']
|
||||
);
|
||||
$this->diagram->setXScale($this->x);
|
||||
$this->diagram->setFont($this->ff, '', $fontSize);
|
||||
$this->diagram->setTextColor(0);
|
||||
$this->diagram->setFillColor(255);
|
||||
|
||||
foreach ($this->fields as $field) {
|
||||
if ($setColor) {
|
||||
if (in_array($field, $this->primary)) {
|
||||
$this->diagram->setFillColor(215, 121, 123);
|
||||
}
|
||||
|
||||
if ($field == $this->displayfield) {
|
||||
$this->diagram->setFillColor(142, 159, 224);
|
||||
}
|
||||
}
|
||||
|
||||
if ($withDoc) {
|
||||
$this->diagram->setLink($this->diagram->customLinks['RT'][$this->tableName][$field], -1);
|
||||
} else {
|
||||
$this->diagram->customLinks['doc'][$this->tableName][$field] = '';
|
||||
}
|
||||
|
||||
$this->diagram->cellScale(
|
||||
$this->width,
|
||||
$this->heightCell,
|
||||
' ' . $field,
|
||||
1,
|
||||
1,
|
||||
'L',
|
||||
$setColor,
|
||||
$this->diagram->customLinks['doc'][$this->tableName][$field]
|
||||
);
|
||||
$this->diagram->setXScale($this->x);
|
||||
$this->diagram->setFillColor(255);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue