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