RelationStatsEps.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Eps\RelationStatsEps class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Plugins\Schema\Eps;
  9. use PhpMyAdmin\Plugins\Schema\RelationStats;
  10. /**
  11. * Relation preferences/statistics
  12. *
  13. * This class fetches the table master and foreign fields positions
  14. * and helps in generating the Table references and then connects
  15. * master table's master field to foreign table's foreign key
  16. * in EPS document.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Relation_Stats_Eps
  20. * @see PMA_EPS
  21. */
  22. class RelationStatsEps extends RelationStats
  23. {
  24. /**
  25. * The "PhpMyAdmin\Plugins\Schema\Eps\RelationStatsEps" constructor
  26. *
  27. * @param object $diagram The EPS diagram
  28. * @param string $master_table The master table name
  29. * @param string $master_field The relation field in the master table
  30. * @param string $foreign_table The foreign table name
  31. * @param string $foreign_field The relation field in the foreign table
  32. */
  33. public function __construct(
  34. $diagram, $master_table, $master_field, $foreign_table, $foreign_field
  35. ) {
  36. $this->wTick = 10;
  37. parent::__construct(
  38. $diagram, $master_table, $master_field, $foreign_table, $foreign_field
  39. );
  40. $this->ySrc += 10;
  41. $this->yDest += 10;
  42. }
  43. /**
  44. * draws relation links and arrows
  45. * shows foreign key relations
  46. *
  47. * @see PMA_EPS
  48. *
  49. * @return void
  50. */
  51. public function relationDraw()
  52. {
  53. // draw a line like -- to foreign field
  54. $this->diagram->line(
  55. $this->xSrc,
  56. $this->ySrc,
  57. $this->xSrc + $this->srcDir * $this->wTick,
  58. $this->ySrc,
  59. 1
  60. );
  61. // draw a line like -- to master field
  62. $this->diagram->line(
  63. $this->xDest + $this->destDir * $this->wTick,
  64. $this->yDest,
  65. $this->xDest,
  66. $this->yDest,
  67. 1
  68. );
  69. // draw a line that connects to master field line and foreign field line
  70. $this->diagram->line(
  71. $this->xSrc + $this->srcDir * $this->wTick,
  72. $this->ySrc,
  73. $this->xDest + $this->destDir * $this->wTick,
  74. $this->yDest,
  75. 1
  76. );
  77. $root2 = 2 * sqrt(2);
  78. $this->diagram->line(
  79. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  80. $this->ySrc,
  81. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  82. $this->ySrc + $this->wTick / $root2,
  83. 1
  84. );
  85. $this->diagram->line(
  86. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  87. $this->ySrc,
  88. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  89. $this->ySrc - $this->wTick / $root2,
  90. 1
  91. );
  92. $this->diagram->line(
  93. $this->xDest + $this->destDir * $this->wTick / 2,
  94. $this->yDest,
  95. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  96. $this->yDest + $this->wTick / $root2,
  97. 1
  98. );
  99. $this->diagram->line(
  100. $this->xDest + $this->destDir * $this->wTick / 2,
  101. $this->yDest,
  102. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  103. $this->yDest - $this->wTick / $root2,
  104. 1
  105. );
  106. }
  107. }