Svg_Relation_Schema.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Classes to create relation schema in SVG format.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. require_once 'Export_Relation_Schema.class.php';
  12. require_once 'libraries/Font.class.php';
  13. /**
  14. * This Class inherits the XMLwriter class and
  15. * helps in developing structure of SVG Schema Export
  16. *
  17. * @package PhpMyAdmin
  18. * @access public
  19. * @see http://php.net/manual/en/book.xmlwriter.php
  20. */
  21. class PMA_SVG extends XMLWriter
  22. {
  23. public $title;
  24. public $author;
  25. public $font;
  26. public $fontSize;
  27. /**
  28. * The "PMA_SVG" constructor
  29. *
  30. * Upon instantiation This starts writing the Svg XML document
  31. *
  32. * @see XMLWriter::openMemory(),XMLWriter::setIndent(),XMLWriter::startDocument()
  33. */
  34. function __construct()
  35. {
  36. $this->openMemory();
  37. /*
  38. * Set indenting using three spaces,
  39. * so output is formatted
  40. */
  41. $this->setIndent(true);
  42. $this->setIndentString(' ');
  43. /*
  44. * Create the XML document
  45. */
  46. $this->startDocument('1.0', 'UTF-8');
  47. $this->startDtd(
  48. 'svg', '-//W3C//DTD SVG 1.1//EN',
  49. 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'
  50. );
  51. $this->endDtd();
  52. }
  53. /**
  54. * Set document title
  55. *
  56. * @param string $value sets the title text
  57. *
  58. * @return void
  59. * @access public
  60. */
  61. function setTitle($value)
  62. {
  63. $this->title = $value;
  64. }
  65. /**
  66. * Set document author
  67. *
  68. * @param string $value sets the author
  69. *
  70. * @return void
  71. * @access public
  72. */
  73. function setAuthor($value)
  74. {
  75. $this->author = $value;
  76. }
  77. /**
  78. * Set document font
  79. *
  80. * @param string $value sets the font e.g Arial, Sans-serif etc
  81. *
  82. * @return void
  83. * @access public
  84. */
  85. function setFont($value)
  86. {
  87. $this->font = $value;
  88. }
  89. /**
  90. * Get document font
  91. *
  92. * @return string returns the font name
  93. * @access public
  94. */
  95. function getFont()
  96. {
  97. return $this->font;
  98. }
  99. /**
  100. * Set document font size
  101. *
  102. * @param string $value sets the font size in pixels
  103. *
  104. * @return void
  105. * @access public
  106. */
  107. function setFontSize($value)
  108. {
  109. $this->fontSize = $value;
  110. }
  111. /**
  112. * Get document font size
  113. *
  114. * @return string returns the font size
  115. * @access public
  116. */
  117. function getFontSize()
  118. {
  119. return $this->fontSize;
  120. }
  121. /**
  122. * Starts Svg Document
  123. *
  124. * svg document starts by first initializing svg tag
  125. * which contains all the attributes and namespace that needed
  126. * to define the svg document
  127. *
  128. * @param integer $width total width of the Svg document
  129. * @param integer $height total height of the Svg document
  130. *
  131. * @return void
  132. * @access public
  133. *
  134. * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
  135. */
  136. function startSvgDoc($width,$height)
  137. {
  138. $this->startElement('svg');
  139. $this->writeAttribute('width', $width);
  140. $this->writeAttribute('height', $height);
  141. $this->writeAttribute('xmlns', 'http://www.w3.org/2000/svg');
  142. $this->writeAttribute('version', '1.1');
  143. }
  144. /**
  145. * Ends Svg Document
  146. *
  147. * @return void
  148. * @access public
  149. * @see XMLWriter::endElement(),XMLWriter::endDocument()
  150. */
  151. function endSvgDoc()
  152. {
  153. $this->endElement();
  154. $this->endDocument();
  155. }
  156. /**
  157. * output Svg Document
  158. *
  159. * svg document prompted to the user for download
  160. * Svg document saved in .svg extension and can be
  161. * easily changeable by using any svg IDE
  162. *
  163. * @param string $fileName file name
  164. *
  165. * @return void
  166. * @access public
  167. * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
  168. */
  169. function showOutput($fileName)
  170. {
  171. //ob_get_clean();
  172. $output = $this->flush();
  173. PMA_Response::getInstance()->disable();
  174. PMA_downloadHeader($fileName . '.svg', 'image/svg+xml', strlen($output));
  175. print $output;
  176. }
  177. /**
  178. * Draws Svg elements
  179. *
  180. * SVG has some predefined shape elements like rectangle & text
  181. * and other elements who have x,y co-ordinates are drawn.
  182. * specify their width and height and can give styles too.
  183. *
  184. * @param string $name Svg element name
  185. * @param integer $x The x attr defines the left position of the element
  186. * (e.g. x="0" places the element 0 pixels from the left of the browser window)
  187. * @param integer $y The y attribute defines the top position of the element
  188. * (e.g. y="0" places the element 0 pixels from the top of the browser window)
  189. * @param integer $width The width attribute defines the width the element
  190. * @param integer $height The height attribute defines the height the element
  191. * @param string $text The text attribute defines the text the element
  192. * @param string $styles The style attribute defines the style the element
  193. * styles can be defined like CSS styles
  194. *
  195. * @return void
  196. * @access public
  197. *
  198. * @see XMLWriter::startElement(), XMLWriter::writeAttribute(),
  199. * XMLWriter::text(), XMLWriter::endElement()
  200. */
  201. function printElement($name, $x, $y, $width = '', $height = '',
  202. $text = '', $styles = ''
  203. ) {
  204. $this->startElement($name);
  205. $this->writeAttribute('width', $width);
  206. $this->writeAttribute('height', $height);
  207. $this->writeAttribute('x', $x);
  208. $this->writeAttribute('y', $y);
  209. $this->writeAttribute('style', $styles);
  210. if (isset($text)) {
  211. $this->writeAttribute('font-family', $this->font);
  212. $this->writeAttribute('font-size', $this->fontSize);
  213. $this->text($text);
  214. }
  215. $this->endElement();
  216. }
  217. /**
  218. * Draws Svg Line element
  219. *
  220. * Svg line element is drawn for connecting the tables.
  221. * arrows are also drawn by specify its start and ending
  222. * co-ordinates
  223. *
  224. * @param string $name Svg element name i.e line
  225. * @param integer $x1 Defines the start of the line on the x-axis
  226. * @param integer $y1 Defines the start of the line on the y-axis
  227. * @param integer $x2 Defines the end of the line on the x-axis
  228. * @param integer $y2 Defines the end of the line on the y-axis
  229. * @param string $styles The style attribute defines the style the element
  230. * styles can be defined like CSS styles
  231. *
  232. * @return void
  233. * @access public
  234. *
  235. * @see XMLWriter::startElement(), XMLWriter::writeAttribute(),
  236. * XMLWriter::endElement()
  237. */
  238. function printElementLine($name,$x1,$y1,$x2,$y2,$styles)
  239. {
  240. $this->startElement($name);
  241. $this->writeAttribute('x1', $x1);
  242. $this->writeAttribute('y1', $y1);
  243. $this->writeAttribute('x2', $x2);
  244. $this->writeAttribute('y2', $y2);
  245. $this->writeAttribute('style', $styles);
  246. $this->endElement();
  247. }
  248. }
  249. require_once './libraries/schema/TableStats.class.php';
  250. /**
  251. * Table preferences/statistics
  252. *
  253. * This class preserves the table co-ordinates,fields
  254. * and helps in drawing/generating the Tables in SVG XML document.
  255. *
  256. * @package PhpMyAdmin
  257. * @name Table_Stats_Svg
  258. * @see PMA_SVG
  259. */
  260. class Table_Stats_Svg extends TableStats
  261. {
  262. /**
  263. * Defines properties
  264. */
  265. public $height;
  266. public $currentCell = 0;
  267. /**
  268. * The "Table_Stats_Svg" constructor
  269. *
  270. * @param string $tableName The table name
  271. * @param string $font Font face
  272. * @param integer $fontSize The font size
  273. * @param integer $pageNumber Page number
  274. * @param integer &$same_wide_width The max. with among tables
  275. * @param boolean $showKeys Whether to display keys or not
  276. * @param boolean $showInfo Whether to display table position or not
  277. *
  278. * @global object $svg The current SVG image document
  279. * @global integer The current page number (from the
  280. * $cfg['Servers'][$i]['table_coords'] table)
  281. * @global array $cfgRelation The relations settings
  282. * @global string $db The current db name
  283. *
  284. * @access private
  285. *
  286. * @see PMA_SVG, Table_Stats_Svg::Table_Stats_setWidth,
  287. * Table_Stats_Svg::Table_Stats_setHeight
  288. */
  289. function __construct(
  290. $tableName, $font, $fontSize, $pageNumber,
  291. &$same_wide_width, $showKeys = false, $showInfo = false
  292. ) {
  293. global $svg, $cfgRelation, $db;
  294. parent::__construct(
  295. $svg, $db, $pageNumber, $tableName, $showKeys, $showInfo
  296. );
  297. // height and width
  298. $this->_setHeightTable($fontSize);
  299. // setWidth must me after setHeight, because title
  300. // can include table height which changes table width
  301. $this->_setWidthTable($font, $fontSize);
  302. if ($same_wide_width < $this->width) {
  303. $same_wide_width = $this->width;
  304. }
  305. }
  306. /**
  307. * Displays an error when the table cannot be found.
  308. *
  309. * @return void
  310. */
  311. protected function showMissingTableError()
  312. {
  313. $this->diagram->dieSchema(
  314. $this->pageNumber,
  315. "SVG",
  316. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  317. );
  318. }
  319. /**
  320. * Displays an error on missing coordinates
  321. *
  322. * @return void
  323. */
  324. protected function showMissingCoordinatesError()
  325. {
  326. $this->diagram->dieSchema(
  327. $this->pageNumber,
  328. "SVG",
  329. sprintf(
  330. __('Please configure the coordinates for table %s'),
  331. $this->tableName
  332. )
  333. );
  334. }
  335. /**
  336. * Sets the width of the table
  337. *
  338. * @param string $font The font size
  339. * @param integer $fontSize The font size
  340. *
  341. * @global object $svg The current SVG image document
  342. *
  343. * @return void
  344. * @access private
  345. *
  346. * @see PMA_SVG
  347. */
  348. private function _setWidthTable($font,$fontSize)
  349. {
  350. foreach ($this->fields as $field) {
  351. $this->width = max(
  352. $this->width,
  353. PMA_Font::getStringWidth($field, $font, $fontSize)
  354. );
  355. }
  356. $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
  357. /*
  358. * it is unknown what value must be added, because
  359. * table title is affected by the tabe width value
  360. */
  361. while ($this->width
  362. < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
  363. ) {
  364. $this->width += 7;
  365. }
  366. }
  367. /**
  368. * Sets the height of the table
  369. *
  370. * @param integer $fontSize font size
  371. *
  372. * @return void
  373. * @access private
  374. */
  375. function _setHeightTable($fontSize)
  376. {
  377. $this->heightCell = $fontSize + 4;
  378. $this->height = (count($this->fields) + 1) * $this->heightCell;
  379. }
  380. /**
  381. * draw the table
  382. *
  383. * @param boolean $showColor Whether to display color
  384. *
  385. * @global object $svg The current SVG image document
  386. *
  387. * @access public
  388. * @return void
  389. *
  390. * @see PMA_SVG,PMA_SVG::printElement
  391. */
  392. public function tableDraw($showColor)
  393. {
  394. global $svg;
  395. //echo $this->tableName.'<br />';
  396. $svg->printElement(
  397. 'rect', $this->x, $this->y, $this->width,
  398. $this->heightCell, null, 'fill:red;stroke:black;'
  399. );
  400. $svg->printElement(
  401. 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
  402. $this->getTitle(), 'fill:none;stroke:black;'
  403. );
  404. foreach ($this->fields as $field) {
  405. $this->currentCell += $this->heightCell;
  406. $showColor = 'none';
  407. if ($showColor) {
  408. if (in_array($field, $this->primary)) {
  409. $showColor = '#0c0';
  410. }
  411. if ($field == $this->displayfield) {
  412. $showColor = 'none';
  413. }
  414. }
  415. $svg->printElement(
  416. 'rect', $this->x, $this->y + $this->currentCell, $this->width,
  417. $this->heightCell, null, 'fill:' . $showColor . ';stroke:black;'
  418. );
  419. $svg->printElement(
  420. 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
  421. $this->width, $this->heightCell, $field, 'fill:none;stroke:black;'
  422. );
  423. }
  424. }
  425. }
  426. /**
  427. * Relation preferences/statistics
  428. *
  429. * This class fetches the table master and foreign fields positions
  430. * and helps in generating the Table references and then connects
  431. * master table's master field to foreign table's foreign key
  432. * in SVG XML document.
  433. *
  434. * @package PhpMyAdmin
  435. * @name Relation_Stats_Svg
  436. * @see PMA_SVG::printElementLine
  437. */
  438. class Relation_Stats_Svg
  439. {
  440. /**
  441. * Defines properties
  442. */
  443. public $xSrc, $ySrc;
  444. public $srcDir ;
  445. public $destDir;
  446. public $xDest, $yDest;
  447. public $wTick = 10;
  448. /**
  449. * The "Relation_Stats_Svg" constructor
  450. *
  451. * @param string $master_table The master table name
  452. * @param string $master_field The relation field in the master table
  453. * @param string $foreign_table The foreign table name
  454. * @param string $foreign_field The relation field in the foreign table
  455. *
  456. * @see Relation_Stats_Svg::_getXy
  457. */
  458. function __construct($master_table, $master_field, $foreign_table,
  459. $foreign_field
  460. ) {
  461. $src_pos = $this->_getXy($master_table, $master_field);
  462. $dest_pos = $this->_getXy($foreign_table, $foreign_field);
  463. /*
  464. * [0] is x-left
  465. * [1] is x-right
  466. * [2] is y
  467. */
  468. $src_left = $src_pos[0] - $this->wTick;
  469. $src_right = $src_pos[1] + $this->wTick;
  470. $dest_left = $dest_pos[0] - $this->wTick;
  471. $dest_right = $dest_pos[1] + $this->wTick;
  472. $d1 = abs($src_left - $dest_left);
  473. $d2 = abs($src_right - $dest_left);
  474. $d3 = abs($src_left - $dest_right);
  475. $d4 = abs($src_right - $dest_right);
  476. $d = min($d1, $d2, $d3, $d4);
  477. if ($d == $d1) {
  478. $this->xSrc = $src_pos[0];
  479. $this->srcDir = -1;
  480. $this->xDest = $dest_pos[0];
  481. $this->destDir = -1;
  482. } elseif ($d == $d2) {
  483. $this->xSrc = $src_pos[1];
  484. $this->srcDir = 1;
  485. $this->xDest = $dest_pos[0];
  486. $this->destDir = -1;
  487. } elseif ($d == $d3) {
  488. $this->xSrc = $src_pos[0];
  489. $this->srcDir = -1;
  490. $this->xDest = $dest_pos[1];
  491. $this->destDir = 1;
  492. } else {
  493. $this->xSrc = $src_pos[1];
  494. $this->srcDir = 1;
  495. $this->xDest = $dest_pos[1];
  496. $this->destDir = 1;
  497. }
  498. $this->ySrc = $src_pos[2];
  499. $this->yDest = $dest_pos[2];
  500. }
  501. /**
  502. * Gets arrows coordinates
  503. *
  504. * @param string $table The current table name
  505. * @param string $column The relation column name
  506. *
  507. * @return array Arrows coordinates
  508. * @access private
  509. */
  510. function _getXy($table, $column)
  511. {
  512. $pos = array_search($column, $table->fields);
  513. // x_left, x_right, y
  514. return array(
  515. $table->x,
  516. $table->x + $table->width,
  517. $table->y + ($pos + 1.5) * $table->heightCell
  518. );
  519. }
  520. /**
  521. * draws relation links and arrows shows foreign key relations
  522. *
  523. * @param boolean $changeColor Whether to use one color per relation or not
  524. *
  525. * @global object $svg The current SVG image document
  526. *
  527. * @return void
  528. * @access public
  529. *
  530. * @see PMA_SVG
  531. */
  532. public function relationDraw($changeColor)
  533. {
  534. global $svg;
  535. if ($changeColor) {
  536. $listOfColors = array(
  537. 'red',
  538. 'grey',
  539. 'black',
  540. 'yellow',
  541. 'green',
  542. 'cyan',
  543. ' orange'
  544. );
  545. shuffle($listOfColors);
  546. $color = $listOfColors[0];
  547. } else {
  548. $color = 'black';
  549. }
  550. $svg->printElementLine(
  551. 'line', $this->xSrc, $this->ySrc,
  552. $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
  553. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  554. );
  555. $svg->printElementLine(
  556. 'line', $this->xDest + $this->destDir * $this->wTick,
  557. $this->yDest, $this->xDest, $this->yDest,
  558. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  559. );
  560. $svg->printElementLine(
  561. 'line', $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
  562. $this->xDest + $this->destDir * $this->wTick, $this->yDest,
  563. 'fill:' . $color . ';stroke:' . $color . ';stroke-width:1;'
  564. );
  565. $root2 = 2 * sqrt(2);
  566. $svg->printElementLine(
  567. 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
  568. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  569. $this->ySrc + $this->wTick / $root2,
  570. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  571. );
  572. $svg->printElementLine(
  573. 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
  574. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  575. $this->ySrc - $this->wTick / $root2,
  576. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  577. );
  578. $svg->printElementLine(
  579. 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
  580. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  581. $this->yDest + $this->wTick / $root2,
  582. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  583. );
  584. $svg->printElementLine(
  585. 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
  586. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  587. $this->yDest - $this->wTick / $root2,
  588. 'fill:' . $color . ';stroke:black;stroke-width:2;'
  589. );
  590. }
  591. }
  592. /*
  593. * end of the "Relation_Stats_Svg" class
  594. */
  595. /**
  596. * Svg Relation Schema Class
  597. *
  598. * Purpose of this class is to generate the SVG XML Document because
  599. * SVG defines the graphics in XML format which is used for representing
  600. * the database diagrams as vector image. This class actually helps
  601. * in preparing SVG XML format.
  602. *
  603. * SVG XML is generated by using XMLWriter php extension and this class
  604. * inherits Export_Relation_Schema class has common functionality added
  605. * to this class
  606. *
  607. * @package PhpMyAdmin
  608. * @name Svg_Relation_Schema
  609. */
  610. class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
  611. {
  612. private $_tables = array();
  613. private $_relations = array();
  614. private $_xMax = 0;
  615. private $_yMax = 0;
  616. private $_xMin = 100000;
  617. private $_yMin = 100000;
  618. private $_tablewidth;
  619. /**
  620. * The "PMA_Svg_Relation_Schema" constructor
  621. *
  622. * Upon instantiation This starts writing the SVG XML document
  623. * user will be prompted for download as .svg extension
  624. *
  625. * @see PMA_SVG
  626. */
  627. function __construct()
  628. {
  629. global $svg,$db;
  630. $this->setPageNumber($_POST['pdf_page_number']);
  631. $this->setShowColor(isset($_POST['show_color']));
  632. $this->setShowKeys(isset($_POST['show_keys']));
  633. $this->setTableDimension(isset($_POST['show_table_dimension']));
  634. $this->setAllTablesSameWidth(isset($_POST['all_tables_same_width']));
  635. $this->setExportType($_POST['export_type']);
  636. $svg = new PMA_SVG();
  637. $svg->setTitle(
  638. sprintf(
  639. __('Schema of the %s database - Page %s'),
  640. $db,
  641. $this->pageNumber
  642. )
  643. );
  644. $svg->SetAuthor('phpMyAdmin ' . PMA_VERSION);
  645. $svg->setFont('Arial');
  646. $svg->setFontSize('16px');
  647. $svg->startSvgDoc('1000px', '1000px');
  648. $alltables = $this->getAllTables($db, $this->pageNumber);
  649. foreach ($alltables as $table) {
  650. if (! isset($this->_tables[$table])) {
  651. $this->_tables[$table] = new Table_Stats_Svg(
  652. $table, $svg->getFont(), $svg->getFontSize(), $this->pageNumber,
  653. $this->_tablewidth, $this->showKeys, $this->tableDimension
  654. );
  655. }
  656. if ($this->sameWide) {
  657. $this->_tables[$table]->width = $this->_tablewidth;
  658. }
  659. $this->_setMinMax($this->_tables[$table]);
  660. }
  661. $seen_a_relation = false;
  662. foreach ($alltables as $one_table) {
  663. $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
  664. if ($exist_rel) {
  665. $seen_a_relation = true;
  666. foreach ($exist_rel as $master_field => $rel) {
  667. /* put the foreign table on the schema only if selected
  668. * by the user
  669. * (do not use array_search() because we would have to
  670. * to do a === false and this is not PHP3 compatible)
  671. */
  672. if (in_array($rel['foreign_table'], $alltables)) {
  673. $this->_addRelation(
  674. $one_table, $svg->getFont(), $svg->getFontSize(),
  675. $master_field, $rel['foreign_table'],
  676. $rel['foreign_field'], $this->tableDimension
  677. );
  678. }
  679. }
  680. }
  681. }
  682. if ($seen_a_relation) {
  683. $this->_drawRelations($this->showColor);
  684. }
  685. $this->_drawTables($this->showColor);
  686. $svg->endSvgDoc();
  687. }
  688. /**
  689. * Output Svg Document for download
  690. *
  691. * @return void
  692. * @access public
  693. */
  694. function showOutput()
  695. {
  696. global $svg,$db;
  697. $svg->showOutput($db . '-' . $this->pageNumber);
  698. }
  699. /**
  700. * Sets X and Y minimum and maximum for a table cell
  701. *
  702. * @param string $table The table name
  703. *
  704. * @return void
  705. * @access private
  706. */
  707. private function _setMinMax($table)
  708. {
  709. $this->_xMax = max($this->_xMax, $table->x + $table->width);
  710. $this->_yMax = max($this->_yMax, $table->y + $table->height);
  711. $this->_xMin = min($this->_xMin, $table->x);
  712. $this->_yMin = min($this->_yMin, $table->y);
  713. }
  714. /**
  715. * Defines relation objects
  716. *
  717. * @param string $masterTable The master table name
  718. * @param string $font The font face
  719. * @param int $fontSize Font size
  720. * @param string $masterField The relation field in the master table
  721. * @param string $foreignTable The foreign table name
  722. * @param string $foreignField The relation field in the foreign table
  723. * @param boolean $showInfo Whether to display table position or not
  724. *
  725. * @access private
  726. * @return void
  727. *
  728. * @see _setMinMax,Table_Stats_Svg::__construct(),
  729. * Relation_Stats_Svg::__construct()
  730. */
  731. private function _addRelation(
  732. $masterTable,$font,$fontSize, $masterField,
  733. $foreignTable, $foreignField, $showInfo
  734. ) {
  735. if (! isset($this->_tables[$masterTable])) {
  736. $this->_tables[$masterTable] = new Table_Stats_Svg(
  737. $masterTable, $font, $fontSize, $this->pageNumber,
  738. $this->_tablewidth, false, $showInfo
  739. );
  740. $this->_setMinMax($this->_tables[$masterTable]);
  741. }
  742. if (! isset($this->_tables[$foreignTable])) {
  743. $this->_tables[$foreignTable] = new Table_Stats_Svg(
  744. $foreignTable, $font, $fontSize, $this->pageNumber,
  745. $this->_tablewidth, false, $showInfo
  746. );
  747. $this->_setMinMax($this->_tables[$foreignTable]);
  748. }
  749. $this->_relations[] = new Relation_Stats_Svg(
  750. $this->_tables[$masterTable], $masterField,
  751. $this->_tables[$foreignTable], $foreignField
  752. );
  753. }
  754. /**
  755. * Draws relation arrows and lines
  756. * connects master table's master field to
  757. * foreign table's forein field
  758. *
  759. * @param boolean $changeColor Whether to use one color per relation or not
  760. *
  761. * @return void
  762. * @access private
  763. *
  764. * @see Relation_Stats_Svg::relationDraw()
  765. */
  766. private function _drawRelations($changeColor)
  767. {
  768. foreach ($this->_relations as $relation) {
  769. $relation->relationDraw($changeColor);
  770. }
  771. }
  772. /**
  773. * Draws tables
  774. *
  775. * @param boolean $changeColor Whether to show color for primary fields or not
  776. *
  777. * @return void
  778. * @access private
  779. *
  780. * @see Table_Stats_Svg::Table_Stats_tableDraw()
  781. */
  782. private function _drawTables($changeColor)
  783. {
  784. foreach ($this->_tables as $table) {
  785. $table->tableDraw($changeColor);
  786. }
  787. }
  788. }
  789. ?>