* @copyright
* @license
*/
class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
{
private $tables = array();
private $_relations = array();
private $_xMax = 0;
private $_yMax = 0;
private $scale;
private $_xMin = 100000;
private $_yMin = 100000;
private $t_marg = 10;
private $b_marg = 10;
private $l_marg = 10;
private $r_marg = 10;
private $_tablewidth;
/**
* The "PMA_Svg_Relation_Schema" constructor
*
* Upon instantiation This starts writing the SVG XML document
* user will be prompted for download as .svg extension
*
* @return void
* @see PMA_SVG
*/
function __construct()
{
global $svg,$db;
$this->setPageNumber($_POST['pdf_page_number']);
$this->setShowColor(isset($_POST['show_color']));
$this->setShowKeys(isset($_POST['show_keys']));
$this->setTableDimension(isset($_POST['show_table_dimension']));
$this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
$this->setExportType($_POST['export_type']);
$svg = new PMA_SVG();
$svg->setTitle(sprintf(__('Schema of the %s database - Page %s'), $db, $this->pageNumber));
$svg->SetAuthor('phpMyAdmin ' . PMA_VERSION);
$svg->setFont('Arial');
$svg->setFontSize('16px');
$svg->startSvgDoc('1000px','600px');
$alltables = $this->getAllTables($db,$this->pageNumber);
foreach ($alltables AS $table) {
if (!isset($this->tables[$table])) {
$this->tables[$table] = new Table_Stats($table,$svg->getFont(),$svg->getFontSize(), $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension);
}
if ($this->sameWide) {
$this->tables[$table]->width = $this->_tablewidth;
}
$this->_setMinMax($this->tables[$table]);
}
$seen_a_relation = false;
foreach ($alltables as $one_table) {
$exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
if ($exist_rel) {
$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 (in_array($rel['foreign_table'], $alltables)) {
$this->_addRelation($one_table,$svg->getFont(),$svg->getFontSize(), $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
}
}
}
}
if ($seen_a_relation) {
$this->_drawRelations($this->showColor);
}
$this->_drawTables($this->showColor);
$svg->endSvgDoc();
$svg->showOutput($db.'-'.$this->pageNumber);
exit();
print '';
print_r(get_object_vars($svg));
//print_r($alltables);
print_r($this);
print '
';
}
/**
* Sets X and Y minimum and maximum for a table cell
*
* @param string table The table name
* @access private
*/
private function _setMinMax($table)
{
$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
*
* @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
* @param boolean showInfo Whether to display table position or not
* @access private
* @see _setMinMax,Table_Stats::__construct(),Relation_Stats::__construct()
*/
private function _addRelation($masterTable,$font,$fontSize, $masterField, $foreignTable, $foreignField, $showInfo)
{
if (!isset($this->tables[$masterTable])) {
$this->tables[$masterTable] = new Table_Stats($masterTable, $font, $fontSize, $this->pageNumber, $this->_tablewidth, false, $showInfo);
$this->_setMinMax($this->tables[$masterTable]);
}
if (!isset($this->tables[$foreignTable])) {
$this->tables[$foreignTable] = new Table_Stats($foreignTable,$font,$fontSize,$this->pageNumber, $this->_tablewidth, false, $showInfo);
$this->_setMinMax($this->tables[$foreignTable]);
}
$this->_relations[] = new Relation_Stats($this->tables[$masterTable], $masterField, $this->tables[$foreignTable], $foreignField);
}
/**
* Draws relation arrows and lines
* connects master table's master field to
* foreign table's forein field
*
* @param boolean changeColor Whether to use one color per relation or not
* @access private
* @see Relation_Stats::relationDraw()
*/
private function _drawRelations($changeColor)
{
foreach ($this->_relations as $relation) {
$relation->relationDraw($changeColor);
}
}
/**
* Draws tables
*
* @param boolean changeColor Whether to show color for primary fields or not
* @access private
* @see Table_Stats::Table_Stats_tableDraw()
*/
private function _drawTables($changeColor)
{
foreach ($this->tables as $table) {
$table->tableDraw($changeColor);
}
}
}
?>