RelationStatsPdf.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. namespace PhpMyAdmin\Plugins\Schema\Pdf;
  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 PDF document.
  17. *
  18. * @name Relation_Stats_Pdf
  19. * @package PhpMyAdmin
  20. * @see PMA_Schema_PDF::SetDrawColor PMA_Schema_PDF::setLineWidthScale
  21. * Pdf::lineScale
  22. */
  23. class RelationStatsPdf extends RelationStats
  24. {
  25. /**
  26. * The "PhpMyAdmin\Plugins\Schema\Pdf\RelationStatsPdf" constructor
  27. *
  28. * @param object $diagram The PDF 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, $master_table, $master_field, $foreign_table,
  36. $foreign_field
  37. ) {
  38. $this->wTick = 5;
  39. parent::__construct(
  40. $diagram, $master_table, $master_field, $foreign_table, $foreign_field
  41. );
  42. }
  43. /**
  44. * draws relation links and arrows shows foreign key relations
  45. *
  46. * @param boolean $showColor Whether to use one color per relation or not
  47. * @param integer $i The id of the link to draw
  48. *
  49. * @access public
  50. *
  51. * @return void
  52. *
  53. * @see Pdf
  54. */
  55. public function relationDraw($showColor, $i)
  56. {
  57. if ($showColor) {
  58. $d = $i % 6;
  59. $j = ($i - $d) / 6;
  60. $j = $j % 4;
  61. $j++;
  62. $case = array(
  63. array(1, 0, 0),
  64. array(0, 1, 0),
  65. array(0, 0, 1),
  66. array(1, 1, 0),
  67. array(1, 0, 1),
  68. array(0, 1, 1)
  69. );
  70. list ($a, $b, $c) = $case[$d];
  71. $e = (1 - ($j - 1) / 6);
  72. $this->diagram->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
  73. } else {
  74. $this->diagram->SetDrawColor(0);
  75. }
  76. $this->diagram->setLineWidthScale(0.2);
  77. $this->diagram->lineScale(
  78. $this->xSrc,
  79. $this->ySrc,
  80. $this->xSrc + $this->srcDir * $this->wTick,
  81. $this->ySrc
  82. );
  83. $this->diagram->lineScale(
  84. $this->xDest + $this->destDir * $this->wTick,
  85. $this->yDest,
  86. $this->xDest,
  87. $this->yDest
  88. );
  89. $this->diagram->setLineWidthScale(0.1);
  90. $this->diagram->lineScale(
  91. $this->xSrc + $this->srcDir * $this->wTick,
  92. $this->ySrc,
  93. $this->xDest + $this->destDir * $this->wTick,
  94. $this->yDest
  95. );
  96. /*
  97. * Draws arrows ->
  98. */
  99. $root2 = 2 * sqrt(2);
  100. $this->diagram->lineScale(
  101. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  102. $this->ySrc,
  103. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  104. $this->ySrc + $this->wTick / $root2
  105. );
  106. $this->diagram->lineScale(
  107. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  108. $this->ySrc,
  109. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  110. $this->ySrc - $this->wTick / $root2
  111. );
  112. $this->diagram->lineScale(
  113. $this->xDest + $this->destDir * $this->wTick / 2,
  114. $this->yDest,
  115. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  116. $this->yDest + $this->wTick / $root2
  117. );
  118. $this->diagram->lineScale(
  119. $this->xDest + $this->destDir * $this->wTick / 2,
  120. $this->yDest,
  121. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  122. $this->yDest - $this->wTick / $root2
  123. );
  124. $this->diagram->SetDrawColor(0);
  125. }
  126. }