* @copyright
* @license
*/
class PMA_Dia_Relation_Schema extends PMA_Export_Relation_Schema
{
/**
* Defines properties
*/
private $_tables = array();
private $_relations = array();
private $_topMargin = 2.8222000598907471;
private $_bottomMargin = 2.8222000598907471;
private $_leftMargin = 2.8222000598907471;
private $_rightMargin = 2.8222000598907471;
public static $objectId = 0;
/**
* The "PMA_Dia_Relation_Schema" constructor
*
* Upon instantiation This outputs the Dia XML document
* that user can download
*
* @return void
* @see PMA_DIA,Table_Stats,Relation_Stats
*/
function __construct()
{
global $dia,$db;
$this->setPageNumber($_POST['pdf_page_number']);
$this->setShowGrid(isset($_POST['show_grid']));
$this->setShowColor($_POST['show_color']);
$this->setShowKeys(isset($_POST['show_keys']));
$this->setOrientation(isset($_POST['orientation']));
$this->setPaper($_POST['paper']);
$this->setExportType($_POST['export_type']);
$dia = new PMA_DIA();
$dia->startDiaDoc($this->paper,$this->_topMargin,$this->_bottomMargin,$this->_leftMargin,$this->_rightMargin,$this->orientation);
$alltables = $this->getAllTables($db,$this->pageNumber);
foreach ($alltables as $table) {
if (!isset($this->tables[$table])) {
$this->tables[$table] = new Table_Stats($table, $this->pageNumber, $this->showKeys);
}
}
$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, $master_field, $rel['foreign_table'], $rel['foreign_field'],$this->showKeys);
}
}
}
}
$this->_drawTables($this->showColor);
if ($seen_a_relation) {
$this->_drawRelations($this->showColor);
}
$dia->endDiaDoc();
$dia->showOutput($db.'-'.$this->pageNumber);
exit();
print '';
print_r(get_object_vars($dia));
print_r(get_object_vars($this));
print '
';
}
/**
* 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
* @return void
* @access private
* @see Table_Stats::__construct(),Relation_Stats::__construct()
*/
private function _addRelation($masterTable, $masterField, $foreignTable, $foreignField, $showKeys)
{
if (!isset($this->tables[$masterTable])) {
$this->tables[$masterTable] = new Table_Stats($masterTable, $this->pageNumber, $showKeys);
}
if (!isset($this->tables[$foreignTable])) {
$this->tables[$foreignTable] = new Table_Stats($foreignTable, $this->pageNumber, $showKeys);
}
$this->_relations[] = new Relation_Stats($this->tables[$masterTable], $masterField, $this->tables[$foreignTable], $foreignField);
}
/**
* Draws relation references
*
* connects master table's master field to
* foreign table's forein field using Dia object
* type Database - Reference
*
* @param boolean changeColor Whether to use one color per relation or not
* @return void
* @access private
* @see Relation_Stats::relationDraw()
*/
private function _drawRelations($changeColor)
{
foreach ($this->_relations as $relation) {
$relation->relationDraw($changeColor);
}
}
/**
* Draws tables
*
* Tables are generated using Dia object type Database - Table
* primary fields are underlined and bold in tables
*
* @param boolean changeColor Whether to show color for tables text or not
* @return void
* @access private
* @see Table_Stats::tableDraw()
*/
private function _drawTables($changeColor)
{
foreach ($this->tables as $table) {
$table->tableDraw($changeColor);
}
}
}
?>