Eps_Relation_Schema.class.php 24 KB

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