RelationStatsEps.php 3.5 KB

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