Ignore NULL charset
[phpmyadmin-regexreplace.git] / libraries / schema / Svg_Relation_Schema.class.php
blobafafda7fb629cf49d70dc3ac6c8d2ea120a2d544
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 include_once("Export_Relation_Schema.class.php");
10 /**
11 * This Class inherits the XMLwriter class and
12 * helps in developing structure of SVG Schema Export
14 * @name PMA_SVG
15 * @copyright
16 * @license
17 * @access public
18 * @see http://php.net/manual/en/book.xmlwriter.php
21 class PMA_SVG extends XMLWriter
23 public $title;
24 public $author;
25 public $font;
26 public $fontSize;
28 /**
29 * The "PMA_SVG" constructor
31 * Upon instantiation This starts writing the Svg XML document
33 * @return void
34 * @see XMLWriter::openMemory(),XMLWriter::setIndent(),XMLWriter::startDocument()
36 function __construct()
38 $this->openMemory();
40 * Set indenting using three spaces,
41 * so output is formatted
44 $this->setIndent(TRUE);
45 $this->setIndentString(' ');
47 * Create the XML document
50 $this->startDocument('1.0','UTF-8');
51 $this->startDtd('svg','-//W3C//DTD SVG 1.1//EN','http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
52 $this->endDtd();
55 /**
56 * Set document title
58 * @param string value sets the title text
59 * @return void
60 * @access public
62 function setTitle($value)
64 $this->title = $value;
67 /**
68 * Set document author
70 * @param string value sets the author
71 * @return void
72 * @access public
74 function setAuthor($value)
76 $this->author = $value;
79 /**
80 * Set document font
82 * @param string value sets the font e.g Arial, Sans-serif etc
83 * @return void
84 * @access public
86 function setFont($value)
88 $this->font = $value;
91 /**
92 * Get document font
94 * @return string returns the font name
95 * @access public
97 function getFont()
99 return $this->font;
103 * Set document font size
105 * @param string value sets the font size in pixels
106 * @return void
107 * @access public
109 function setFontSize($value)
111 $this->fontSize = $value;
115 * Get document font size
117 * @return string returns the font size
118 * @access public
120 function getFontSize()
122 return $this->fontSize;
126 * Starts Svg Document
128 * svg document starts by first initializing svg tag
129 * which contains all the attributes and namespace that needed
130 * to define the svg document
132 * @param integer width total width of the Svg document
133 * @param integer height total height of the Svg document
134 * @return void
135 * @access public
136 * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
138 function startSvgDoc($width,$height)
140 $this->startElement('svg');
141 $this->writeAttribute('width', $width);
142 $this->writeAttribute('height', $height);
143 $this->writeAttribute('xmlns', 'http://www.w3.org/2000/svg');
144 $this->writeAttribute('version', '1.1');
148 * Ends Svg Document
150 * @return void
151 * @access public
152 * @see XMLWriter::endElement(),XMLWriter::endDocument()
154 function endSvgDoc()
156 $this->endElement();
157 $this->endDocument();
161 * output Svg Document
163 * svg document prompted to the user for download
164 * Svg document saved in .svg extension and can be
165 * easily changeable by using any svg IDE
167 * @return void
168 * @access public
169 * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
171 function showOutput($fileName)
173 //ob_get_clean();
174 header('Content-type: image/svg+xml');
175 header('Content-Disposition: attachment; filename="'.$fileName.'.svg"');
176 $output = $this->flush();
177 print $output;
181 * Draws Svg elements
183 * SVG has some predefined shape elements like rectangle & text
184 * and other elements who have x,y co-ordinates are drawn.
185 * specify their width and height and can give styles too.
187 * @param string name Svg element name
188 * @param integer x The x attribute defines the left position of the element
189 (e.g. x="0" places the element 0 pixels from the left of
190 the browser window)
191 * @param integer y The y attribute defines the top position of the element
192 (e.g. y="0" places the element 0 pixels from the top of
193 the browser window)
194 * @param integer width The width attribute defines the width the element
195 * @param integer height The height attribute defines the height the element
196 * @param string text The text attribute defines the text the element
197 * @param string styles The style attribute defines the style the element
198 styles can be defined like CSS styles
199 * @return void
200 * @access public
201 * @see XMLWriter::startElement(),XMLWriter::writeAttribute(),XMLWriter::text(),XMLWriter::endElement()
203 function printElement($name,$x,$y,$width = '',$height = '',$text = '',$styles = '')
205 $this->startElement($name);
206 $this->writeAttribute('width',$width);
207 $this->writeAttribute('height',$height);
208 $this->writeAttribute('x', $x);
209 $this->writeAttribute('y', $y);
210 $this->writeAttribute('style', $styles);
211 if(isset($text)){
212 $this->writeAttribute('font-family', $this->font);
213 $this->writeAttribute('font-size', $this->fontSize);
214 $this->text($text);
216 $this->endElement();
220 * Draws Svg Line element
222 * Svg line element is drawn for connecting the tables.
223 * arrows are also drawn by specify its start and ending
224 * co-ordinates
226 * @param string name Svg element name i.e line
227 * @param integer x1 The x1 attribute defines the start of the line on the x-axis
228 * @param integer y1 The y1 attribute defines the start of the line on the y-axis
229 * @param integer x2 The x2 attribute defines the end of the line on the x-axis
230 * @param integer y2 The y2 attribute defines the end of the line on the y-axis
231 * @param string styles The style attribute defines the style the element
232 styles can be defined like CSS styles
233 * @return void
234 * @access public
235 * @see XMLWriter::startElement(),XMLWriter::writeAttribute(),XMLWriter::endElement()
237 function printElementLine($name,$x1,$y1,$x2,$y2,$styles)
239 $this->startElement($name);
240 $this->writeAttribute('x1',$x1);
241 $this->writeAttribute('y1',$y1);
242 $this->writeAttribute('x2', $x2);
243 $this->writeAttribute('y2', $y2);
244 $this->writeAttribute('style', $styles);
245 $this->endElement();
249 * get width of string/text
251 * Svg text element width is calcualted depending on font name
252 * and font size. It is very important to know the width of text
253 * because rectangle is drawn around it.
255 * This is a bit hardcore method. I didn't found any other than this.
257 * @param string text string that width will be calculated
258 * @param integer font name of the font like Arial,sans-serif etc
259 * @param integer fontSize size of font
260 * @return integer width of the text
261 * @access public
263 function getStringWidth($text,$font,$fontSize)
266 * Start by counting the width, giving each character a modifying value
268 $count = 0;
269 $count = $count + ((strlen($text) - strlen(str_replace(array("i","j","l"),"",$text)))*0.23);//ijl
270 $count = $count + ((strlen($text) - strlen(str_replace(array("f"),"",$text)))*0.27);//f
271 $count = $count + ((strlen($text) - strlen(str_replace(array("t","I"),"",$text)))*0.28);//tI
272 $count = $count + ((strlen($text) - strlen(str_replace(array("r"),"",$text)))*0.34);//r
273 $count = $count + ((strlen($text) - strlen(str_replace(array("1"),"",$text)))*0.49);//1
274 $count = $count + ((strlen($text) - strlen(str_replace(array("c","k","s","v","x","y","z","J"),"",$text)))*0.5);//cksvxyzJ
275 $count = $count + ((strlen($text) - strlen(str_replace(array("a","b","d","e","g","h","n","o","p","q","u","L","0","2","3","4","5","6","7","8","9"),"",$text)))*0.56);//abdeghnopquL023456789
276 $count = $count + ((strlen($text) - strlen(str_replace(array("F","T","Z"),"",$text)))*0.61);//FTZ
277 $count = $count + ((strlen($text) - strlen(str_replace(array("A","B","E","K","P","S","V","X","Y"),"",$text)))*0.67);//ABEKPSVXY
278 $count = $count + ((strlen($text) - strlen(str_replace(array("w","C","D","H","N","R","U"),"",$text)))*0.73);//wCDHNRU
279 $count = $count + ((strlen($text) - strlen(str_replace(array("G","O","Q"),"",$text)))*0.78);//GOQ
280 $count = $count + ((strlen($text) - strlen(str_replace(array("m","M"),"",$text)))*0.84);//mM
281 $count = $count + ((strlen($text) - strlen(str_replace("W","",$text)))*.95);//W
282 $count = $count + ((strlen($text) - strlen(str_replace(" ","",$text)))*.28);//" "
283 $text = str_replace(" ","",$text);//remove the " "'s
284 $count = $count + (strlen(preg_replace("/[a-z0-9]/i","",$text))*0.3); //all other chrs
286 $modifier = 1;
287 $font = strtolower($font);
288 switch($font){
290 * no modifier for arial and sans-serif
292 case 'arial':
293 case 'sans-serif':
294 break;
296 * .92 modifer for time, serif, brushscriptstd, and californian fb
298 case 'times':
299 case 'serif':
300 case 'brushscriptstd':
301 case 'californian fb':
302 $modifier = .92;
303 break;
305 * 1.23 modifier for broadway
307 case 'broadway':
308 $modifier = 1.23;
309 break;
311 $textWidth = $count*$fontSize;
312 return ceil($textWidth*$modifier);
317 * Table preferences/statistics
319 * This class preserves the table co-ordinates,fields
320 * and helps in drawing/generating the Tables in SVG XML document.
322 * @name Table_Stats
323 * @copyright
324 * @license
325 * @see PMA_SVG
327 class Table_Stats
330 * Defines properties
333 private $_tableName;
334 private $_showInfo = false;
336 public $width = 0;
337 public $height;
338 public $fields = array();
339 public $heightCell = 0;
340 public $currentCell = 0;
341 public $x, $y;
342 public $primary = array();
345 * The "Table_Stats" constructor
347 * @param string table_name The table name
348 * @param integer ff The font size
349 * @param integer samewidth The max. with among tables
350 * @param boolean show_keys Whether to display keys or not
351 * @param boolean show_info Whether to display table position or not
352 * @global object The current SVG image document
353 * @global integer The current page number (from the
354 * $cfg['Servers'][$i]['table_coords'] table)
355 * @global array The relations settings
356 * @global string The current db name
357 * @access private
358 * @see PMA_SVG, Table_Stats::Table_Stats_setWidth,
359 Table_Stats::Table_Stats_setHeight
361 function __construct($tableName, $font, $fontSize, $pageNumber, &$same_wide_width, $showKeys = false, $showInfo = false)
363 global $svg, $cfgRelation, $db;
365 $this->_tableName = $tableName;
366 $sql = 'DESCRIBE ' . PMA_backquote($tableName);
367 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
368 if (!$result || !PMA_DBI_num_rows($result)) {
369 $svg->dieSchema($pageNumber,"SVG",sprintf(__('The %s table doesn\'t exist!'), $tableName));
373 * load fields
374 * check to see if it will load all fields or only the foreign keys
377 if ($showKeys) {
378 $indexes = PMA_Index::getFromTable($this->_tableName, $db);
379 $all_columns = array();
380 foreach ($indexes as $index) {
381 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
383 $this->fields = array_keys($all_columns);
384 } else {
385 while ($row = PMA_DBI_fetch_row($result)) {
386 $this->fields[] = $row[0];
390 $this->_showInfo = $showInfo;
392 // height and width
393 $this->_setHeightTable($fontSize);
395 // setWidth must me after setHeight, because title
396 // can include table height which changes table width
397 $this->_setWidthTable($font,$fontSize);
398 if ($same_wide_width < $this->width) {
399 $same_wide_width = $this->width;
402 // x and y
403 $sql = 'SELECT x, y FROM '
404 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
405 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
406 . ' AND table_name = \'' . PMA_sqlAddslashes($tableName) . '\''
407 . ' AND pdf_page_number = ' . $pageNumber;
408 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
410 if (!$result || !PMA_DBI_num_rows($result)) {
411 $svg->dieSchema($pageNumber,"SVG",sprintf(__('Please configure the coordinates for table %s'), $tableName));
413 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
414 $this->x = (double) $this->x;
415 $this->y = (double) $this->y;
416 // displayfield
417 $this->displayfield = PMA_getDisplayField($db, $tableName);
418 // index
419 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE);
420 if (PMA_DBI_num_rows($result) > 0) {
421 while ($row = PMA_DBI_fetch_assoc($result)) {
422 if ($row['Key_name'] == 'PRIMARY') {
423 $this->primary[] = $row['Column_name'];
430 * Returns title of the current table,
431 * title can have the dimensions/co-ordinates of the table
433 * @access private
435 private function _getTitle()
437 return ($this->_showInfo ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->heightCell) : '') . ' ' . $this->_tableName;
441 * Sets the width of the table
443 * @param string font The font size
444 * @param integer fontSize The font size
445 * @global object The current SVG image document
446 * @access private
447 * @see PMA_SVG
449 function _setWidthTable($font,$fontSize)
451 global $svg;
453 foreach ($this->fields as $field) {
454 $this->width = max($this->width, $svg->getStringWidth($field,$font,$fontSize));
456 $this->width += $svg->getStringWidth(' ',$font,$fontSize);
458 * it is unknown what value must be added, because
459 * table title is affected by the tabe width value
461 while ($this->width < $svg->getStringWidth($this->_getTitle(),$font,$fontSize)) {
462 $this->width += 7;
467 * Sets the height of the table
469 * @access private
471 function _setHeightTable($fontSize)
473 $this->heightCell = $fontSize + 4;
474 $this->height = (count($this->fields) + 1) * $this->heightCell;
478 * draw the table
480 * @param boolean showColor Whether to display color
481 * @global object The current SVG image document
482 * @access public
483 * @see PMA_SVG,PMA_SVG::printElement
485 public function tableDraw($showColor)
487 global $svg;
488 //echo $this->_tableName.'<br />';
489 $svg->printElement('rect',$this->x,$this->y,
490 $this->width,$this->heightCell,
491 NULL,'fill:red;stroke:black;'
493 $svg->printElement('text',$this->x + 5,$this->y+ 14,
494 $this->width,$this->heightCell,
495 $this->_getTitle(),
496 'fill:none;stroke:black;'
498 foreach ($this->fields as $field) {
499 $this->currentCell += $this->heightCell;
500 $showColor = 'none';
501 if ($showColor) {
502 if (in_array($field, $this->primary)) {
503 $showColor = '#0c0';
505 if ($field == $this->displayfield) {
506 $showColor = 'none';
509 $svg->printElement('rect', $this->x,$this->y + $this->currentCell,
510 $this->width, $this->heightCell,
511 NULL,
512 'fill:'.$showColor.';stroke:black;'
514 $svg->printElement('text', $this->x + 5, $this->y + 14 + $this->currentCell,
515 $this->width, $this->heightCell,
516 $field,
517 'fill:none;stroke:black;'
525 * Relation preferences/statistics
527 * This class fetches the table master and foreign fields positions
528 * and helps in generating the Table references and then connects
529 * master table's master field to foreign table's foreign key
530 * in SVG XML document.
532 * @name Relation_Stats
533 * @copyright
534 * @license
535 * @see PMA_SVG::printElementLine
537 class Relation_Stats
540 * Defines properties
542 public $xSrc, $ySrc;
543 public $srcDir ;
544 public $destDir;
545 public $xDest, $yDest;
546 public $wTick = 10;
549 * The "Relation_Stats" constructor
551 * @param string master_table The master table name
552 * @param string master_field The relation field in the master table
553 * @param string foreign_table The foreign table name
554 * @param string foreigh_field The relation field in the foreign table
555 * @see Relation_Stats::_getXy
557 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
559 $src_pos = $this->_getXy($master_table, $master_field);
560 $dest_pos = $this->_getXy($foreign_table, $foreign_field);
562 * [0] is x-left
563 * [1] is x-right
564 * [2] is y
566 $src_left = $src_pos[0] - $this->wTick;
567 $src_right = $src_pos[1] + $this->wTick;
568 $dest_left = $dest_pos[0] - $this->wTick;
569 $dest_right = $dest_pos[1] + $this->wTick;
571 $d1 = abs($src_left - $dest_left);
572 $d2 = abs($src_right - $dest_left);
573 $d3 = abs($src_left - $dest_right);
574 $d4 = abs($src_right - $dest_right);
575 $d = min($d1, $d2, $d3, $d4);
577 if ($d == $d1) {
578 $this->xSrc = $src_pos[0];
579 $this->srcDir = -1;
580 $this->xDest = $dest_pos[0];
581 $this->destDir = -1;
582 } elseif ($d == $d2) {
583 $this->xSrc = $src_pos[1];
584 $this->srcDir = 1;
585 $this->xDest = $dest_pos[0];
586 $this->destDir = -1;
587 } elseif ($d == $d3) {
588 $this->xSrc = $src_pos[0];
589 $this->srcDir = -1;
590 $this->xDest = $dest_pos[1];
591 $this->destDir = 1;
592 } else {
593 $this->xSrc = $src_pos[1];
594 $this->srcDir = 1;
595 $this->xDest = $dest_pos[1];
596 $this->destDir = 1;
598 $this->ySrc = $src_pos[2];
599 $this->yDest = $dest_pos[2];
603 * Gets arrows coordinates
605 * @param string table The current table name
606 * @param string column The relation column name
607 * @return array Arrows coordinates
608 * @access private
610 function _getXy($table, $column)
612 $pos = array_search($column, $table->fields);
613 // x_left, x_right, y
614 return array($table->x, $table->x + $table->width, $table->y + ($pos + 1.5) * $table->heightCell);
618 * draws relation links and arrows
619 * shows foreign key relations
621 * @param boolean changeColor Whether to use one color per relation or not
622 * @global object The current SVG image document
623 * @access public
624 * @see PMA_SVG
626 public function relationDraw($changeColor)
628 global $svg;
630 if ($changeColor) {
631 $listOfColors = array(
632 'red',
633 'grey',
634 'black',
635 'yellow',
636 'green',
637 'cyan',
638 ' orange'
640 shuffle($listOfColors);
641 $color = $listOfColors[0];
642 } else {
643 $color = 'black';
646 $svg->printElementLine('line',$this->xSrc,$this->ySrc,
647 $this->xSrc + $this->srcDir * $this->wTick,$this->ySrc,
648 'fill:'.$color.';stroke:black;stroke-width:2;'
650 $svg->printElementLine('line',$this->xDest + $this->destDir * $this->wTick, $this->yDest,
651 $this->xDest, $this->yDest,
652 'fill:'.$color.';stroke:black;stroke-width:2;'
654 $svg->printElementLine('line',$this->xSrc + $this->srcDir * $this->wTick,$this->ySrc,
655 $this->xDest + $this->destDir * $this->wTick, $this->yDest,
656 'fill:'.$color.';stroke:'.$color.';stroke-width:1;'
658 $root2 = 2 * sqrt(2);
659 $svg->printElementLine('line',$this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
660 $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick ,
661 $this->ySrc + $this->wTick / $root2 ,
662 'fill:'.$color.';stroke:black;stroke-width:2;'
664 $svg->printElementLine('line',$this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
665 $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick ,
666 $this->ySrc - $this->wTick / $root2 ,
667 'fill:'.$color.';stroke:black;stroke-width:2;'
669 $svg->printElementLine('line',$this->xDest + $this->destDir * $this->wTick / 2 , $this->yDest ,
670 $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
671 $this->yDest + $this->wTick / $root2 ,
672 'fill:'.$color.';stroke:black;stroke-width:2;');
673 $svg->printElementLine('line',$this->xDest + $this->destDir * $this->wTick / 2 ,
674 $this->yDest , $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick ,
675 $this->yDest - $this->wTick / $root2 ,
676 'fill:'.$color.';stroke:black;stroke-width:2;'
681 * end of the "Relation_Stats" class
685 * Svg Relation Schema Class
687 * Purpose of this class is to generate the SVG XML Document because
688 * SVG defines the graphics in XML format which is used for representing
689 * the database diagrams as vector image. This class actually helps
690 * in preparing SVG XML format.
692 * SVG XML is generated by using XMLWriter php extension and this class
693 * inherits Export_Relation_Schema class has common functionality added
694 * to this class
696 * @name Svg_Relation_Schema
697 * @copyright
698 * @license
700 class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
703 private $tables = array();
704 private $_relations = array();
705 private $_xMax = 0;
706 private $_yMax = 0;
707 private $scale;
708 private $_xMin = 100000;
709 private $_yMin = 100000;
710 private $t_marg = 10;
711 private $b_marg = 10;
712 private $l_marg = 10;
713 private $r_marg = 10;
714 private $_tablewidth;
717 * The "PMA_Svg_Relation_Schema" constructor
719 * Upon instantiation This starts writing the SVG XML document
720 * user will be prompted for download as .svg extension
722 * @return void
723 * @see PMA_SVG
725 function __construct()
727 global $svg,$db;
729 $this->setPageNumber($_POST['pdf_page_number']);
730 $this->setShowColor(isset($_POST['show_color']));
731 $this->setShowKeys(isset($_POST['show_keys']));
732 $this->setTableDimension(isset($_POST['show_table_dimension']));
733 $this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
734 $this->setExportType($_POST['export_type']);
736 $svg = new PMA_SVG();
737 $svg->setTitle(sprintf(__('Schema of the %s database - Page %s'), $db, $this->pageNumber));
738 $svg->SetAuthor('phpMyAdmin ' . PMA_VERSION);
739 $svg->setFont('Arial');
740 $svg->setFontSize('16px');
741 $svg->startSvgDoc('1000px','1000px');
742 $alltables = $this->getAllTables($db,$this->pageNumber);
744 foreach ($alltables AS $table) {
745 if (!isset($this->tables[$table])) {
746 $this->tables[$table] = new Table_Stats($table,$svg->getFont(),$svg->getFontSize(), $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension);
749 if ($this->sameWide) {
750 $this->tables[$table]->width = $this->_tablewidth;
752 $this->_setMinMax($this->tables[$table]);
754 $seen_a_relation = false;
755 foreach ($alltables as $one_table) {
756 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
757 if ($exist_rel) {
758 $seen_a_relation = true;
759 foreach ($exist_rel as $master_field => $rel) {
760 /* put the foreign table on the schema only if selected
761 * by the user
762 * (do not use array_search() because we would have to
763 * to do a === FALSE and this is not PHP3 compatible)
765 if (in_array($rel['foreign_table'], $alltables)) {
766 $this->_addRelation($one_table,$svg->getFont(),$svg->getFontSize(), $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
771 if ($seen_a_relation) {
772 $this->_drawRelations($this->showColor);
775 $this->_drawTables($this->showColor);
776 $svg->endSvgDoc();
777 $svg->showOutput($db.'-'.$this->pageNumber);
778 exit();
782 * Sets X and Y minimum and maximum for a table cell
784 * @param string table The table name
785 * @access private
787 private function _setMinMax($table)
789 $this->_xMax = max($this->_xMax, $table->x + $table->width);
790 $this->_yMax = max($this->_yMax, $table->y + $table->height);
791 $this->_xMin = min($this->_xMin, $table->x);
792 $this->_yMin = min($this->_yMin, $table->y);
796 * Defines relation objects
798 * @param string masterTable The master table name
799 * @param string masterField The relation field in the master table
800 * @param string foreignTable The foreign table name
801 * @param string foreignField The relation field in the foreign table
802 * @param boolean showInfo Whether to display table position or not
803 * @access private
804 * @see _setMinMax,Table_Stats::__construct(),Relation_Stats::__construct()
806 private function _addRelation($masterTable,$font,$fontSize, $masterField, $foreignTable, $foreignField, $showInfo)
808 if (!isset($this->tables[$masterTable])) {
809 $this->tables[$masterTable] = new Table_Stats($masterTable, $font, $fontSize, $this->pageNumber, $this->_tablewidth, false, $showInfo);
810 $this->_setMinMax($this->tables[$masterTable]);
812 if (!isset($this->tables[$foreignTable])) {
813 $this->tables[$foreignTable] = new Table_Stats($foreignTable,$font,$fontSize,$this->pageNumber, $this->_tablewidth, false, $showInfo);
814 $this->_setMinMax($this->tables[$foreignTable]);
816 $this->_relations[] = new Relation_Stats($this->tables[$masterTable], $masterField, $this->tables[$foreignTable], $foreignField);
820 * Draws relation arrows and lines
821 * connects master table's master field to
822 * foreign table's forein field
824 * @param boolean changeColor Whether to use one color per relation or not
825 * @access private
826 * @see Relation_Stats::relationDraw()
828 private function _drawRelations($changeColor)
830 foreach ($this->_relations as $relation) {
831 $relation->relationDraw($changeColor);
836 * Draws tables
838 * @param boolean changeColor Whether to show color for primary fields or not
839 * @access private
840 * @see Table_Stats::Table_Stats_tableDraw()
842 private function _drawTables($changeColor)
844 foreach ($this->tables as $table) {
845 $table->tableDraw($changeColor);