RelationStatsPdf.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Pdf\RelationStatsPdf class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Plugins\Schema\Pdf;
  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 PDF document.
  18. *
  19. * @name Relation_Stats_Pdf
  20. * @package PhpMyAdmin
  21. * @see PMA_Schema_PDF::SetDrawColor PMA_Schema_PDF::setLineWidthScale
  22. * Pdf::lineScale
  23. */
  24. class RelationStatsPdf extends RelationStats
  25. {
  26. /**
  27. * The "PhpMyAdmin\Plugins\Schema\Pdf\RelationStatsPdf" constructor
  28. *
  29. * @param Pdf $diagram The PDF diagram
  30. * @param string $master_table The master table name
  31. * @param string $master_field The relation field in the master table
  32. * @param string $foreign_table The foreign table name
  33. * @param string $foreign_field The relation field in the foreign table
  34. */
  35. public function __construct(
  36. $diagram,
  37. $master_table,
  38. $master_field,
  39. $foreign_table,
  40. $foreign_field
  41. ) {
  42. $this->wTick = 5;
  43. parent::__construct(
  44. $diagram,
  45. $master_table,
  46. $master_field,
  47. $foreign_table,
  48. $foreign_field
  49. );
  50. }
  51. /**
  52. * draws relation links and arrows shows foreign key relations
  53. *
  54. * @param boolean $showColor Whether to use one color per relation or not
  55. * @param integer $i The id of the link to draw
  56. *
  57. * @access public
  58. *
  59. * @return void
  60. *
  61. * @see Pdf
  62. */
  63. public function relationDraw($showColor, $i)
  64. {
  65. if ($showColor) {
  66. $d = $i % 6;
  67. $j = ($i - $d) / 6;
  68. $j %= 4;
  69. $j++;
  70. $case = [
  71. [
  72. 1,
  73. 0,
  74. 0,
  75. ],
  76. [
  77. 0,
  78. 1,
  79. 0,
  80. ],
  81. [
  82. 0,
  83. 0,
  84. 1,
  85. ],
  86. [
  87. 1,
  88. 1,
  89. 0,
  90. ],
  91. [
  92. 1,
  93. 0,
  94. 1,
  95. ],
  96. [
  97. 0,
  98. 1,
  99. 1,
  100. ],
  101. ];
  102. list ($a, $b, $c) = $case[$d];
  103. $e = (1 - ($j - 1) / 6);
  104. $this->diagram->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
  105. } else {
  106. $this->diagram->SetDrawColor(0);
  107. }
  108. $this->diagram->setLineWidthScale(0.2);
  109. $this->diagram->lineScale(
  110. $this->xSrc,
  111. $this->ySrc,
  112. $this->xSrc + $this->srcDir * $this->wTick,
  113. $this->ySrc
  114. );
  115. $this->diagram->lineScale(
  116. $this->xDest + $this->destDir * $this->wTick,
  117. $this->yDest,
  118. $this->xDest,
  119. $this->yDest
  120. );
  121. $this->diagram->setLineWidthScale(0.1);
  122. $this->diagram->lineScale(
  123. $this->xSrc + $this->srcDir * $this->wTick,
  124. $this->ySrc,
  125. $this->xDest + $this->destDir * $this->wTick,
  126. $this->yDest
  127. );
  128. /*
  129. * Draws arrows ->
  130. */
  131. $root2 = 2 * sqrt(2);
  132. $this->diagram->lineScale(
  133. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  134. $this->ySrc,
  135. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  136. $this->ySrc + $this->wTick / $root2
  137. );
  138. $this->diagram->lineScale(
  139. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  140. $this->ySrc,
  141. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  142. $this->ySrc - $this->wTick / $root2
  143. );
  144. $this->diagram->lineScale(
  145. $this->xDest + $this->destDir * $this->wTick / 2,
  146. $this->yDest,
  147. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  148. $this->yDest + $this->wTick / $root2
  149. );
  150. $this->diagram->lineScale(
  151. $this->xDest + $this->destDir * $this->wTick / 2,
  152. $this->yDest,
  153. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  154. $this->yDest - $this->wTick / $root2
  155. );
  156. $this->diagram->SetDrawColor(0);
  157. }
  158. }