RelationStatsEps.php 3.3 KB

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