UPDATE 4.4.0.0
[phpmyadmin.git] / libraries / plugins / schema / svg / TableStatsSvg.class.php
blobc82f039926423ab291678463ac4367ffda9fccee
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Contains Table_Stats_Svg class
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/plugins/schema/TableStats.class.php';
14 /**
15 * Table preferences/statistics
17 * This class preserves the table co-ordinates,fields
18 * and helps in drawing/generating the Tables in SVG XML document.
20 * @package PhpMyAdmin
21 * @name Table_Stats_Svg
22 * @see PMA_SVG
24 class Table_Stats_Svg extends TableStats
26 /**
27 * Defines properties
29 public $height;
30 public $currentCell = 0;
32 /**
33 * The "Table_Stats_Svg" constructor
35 * @param string $tableName The table name
36 * @param string $font Font face
37 * @param integer $fontSize The font size
38 * @param integer $pageNumber Page number
39 * @param integer &$same_wide_width The max. with among tables
40 * @param boolean $showKeys Whether to display keys or not
41 * @param boolean $tableDimension Whether to display table position or not
42 * @param boolean $offline Whether the coordinates are sent
43 * from the browser
45 * @global object $svg The current SVG image document
47 * @access private
49 * @see PMA_SVG, Table_Stats_Svg::Table_Stats_setWidth,
50 * Table_Stats_Svg::Table_Stats_setHeight
52 function __construct(
53 $tableName, $font, $fontSize, $pageNumber, &$same_wide_width,
54 $showKeys = false, $tableDimension = false, $offline = false
55 ) {
56 global $svg;
57 parent::__construct(
58 $svg, $GLOBALS['db'], $pageNumber, $tableName,
59 $showKeys, $tableDimension, $offline
62 // height and width
63 $this->_setHeightTable($fontSize);
64 // setWidth must me after setHeight, because title
65 // can include table height which changes table width
66 $this->_setWidthTable($font, $fontSize);
67 if ($same_wide_width < $this->width) {
68 $same_wide_width = $this->width;
72 /**
73 * Displays an error when the table cannot be found.
75 * @return void
77 protected function showMissingTableError()
79 PMA_Export_Relation_Schema::dieSchema(
80 $this->pageNumber,
81 "SVG",
82 sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
86 /**
87 * Sets the width of the table
89 * @param string $font The font size
90 * @param integer $fontSize The font size
92 * @global object $svg The current SVG image document
94 * @return void
95 * @access private
97 * @see PMA_SVG
99 private function _setWidthTable($font,$fontSize)
101 foreach ($this->fields as $field) {
102 $this->width = max(
103 $this->width,
104 PMA_Font::getStringWidth($field, $font, $fontSize)
107 $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
110 * it is unknown what value must be added, because
111 * table title is affected by the table width value
113 while ($this->width
114 < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
116 $this->width += 7;
121 * Sets the height of the table
123 * @param integer $fontSize font size
125 * @return void
126 * @access private
128 function _setHeightTable($fontSize)
130 $this->heightCell = $fontSize + 4;
131 $this->height = (count($this->fields) + 1) * $this->heightCell;
135 * draw the table
137 * @param boolean $showColor Whether to display color
139 * @global object $svg The current SVG image document
141 * @access public
142 * @return void
144 * @see PMA_SVG,PMA_SVG::printElement
146 public function tableDraw($showColor)
148 global $svg;
150 $svg->printElement(
151 'rect', $this->x, $this->y, $this->width,
152 $this->heightCell, null, 'fill:red;stroke:black;'
154 $svg->printElement(
155 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
156 $this->getTitle(), 'fill:none;stroke:black;'
158 foreach ($this->fields as $field) {
159 $this->currentCell += $this->heightCell;
160 $fillColor = 'none';
161 if ($showColor) {
162 if (in_array($field, $this->primary)) {
163 $fillColor = '#0c0';
165 if ($field == $this->displayfield) {
166 $fillColor = 'none';
169 $svg->printElement(
170 'rect', $this->x, $this->y + $this->currentCell, $this->width,
171 $this->heightCell, null, 'fill:' . $fillColor . ';stroke:black;'
173 $svg->printElement(
174 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
175 $this->width, $this->heightCell, $field, 'fill:none;stroke:black;'