2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Contains abstract class to hold table preferences/statistics
8 if (! defined('PHPMYADMIN')) {
13 * Table preferences/statistics
15 * This class preserves the table co-ordinates,fields
16 * and helps in drawing/generating the tables.
21 abstract class TableStats
25 protected $pageNumber;
29 protected $tableDimension;
32 public $fields = array();
33 public $primary = array();
37 public $heightCell = 0;
44 * @param object $diagram schema diagram
45 * @param string $db current db name
46 * @param integer $pageNumber current page number (from the
47 * $cfg['Servers'][$i]['table_coords'] table)
48 * @param string $tableName table name
49 * @param boolean $showKeys whether to display keys or not
50 * @param boolean $tableDimension whether to display table position or not
51 * @param boolean $offline whether the coordinates are sent
54 public function __construct(
55 $diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline
57 $this->diagram
= $diagram;
59 $this->pageNumber
= $pageNumber;
60 $this->tableName
= $tableName;
62 $this->showKeys
= $showKeys;
63 $this->tableDimension
= $tableDimension;
65 $this->offline
= $offline;
67 // checks whether the table exists
69 $this->validateTableAndLoadFields();
70 // load table coordinates
71 $this->loadCoordinates();
72 // loads display field
73 $this->loadDisplayField();
75 $this->loadPrimaryKey();
79 * Validate whether the table exists.
83 protected function validateTableAndLoadFields()
85 $sql = 'DESCRIBE ' . PMA_Util
::backquote($this->tableName
);
86 $result = $GLOBALS['dbi']->tryQuery(
87 $sql, null, PMA_DatabaseInterface
::QUERY_STORE
89 if (! $result ||
! $GLOBALS['dbi']->numRows($result)) {
90 $this->showMissingTableError();
93 if ($this->showKeys
) {
94 $indexes = PMA_Index
::getFromTable($this->tableName
, $this->db
);
95 $all_columns = array();
96 foreach ($indexes as $index) {
97 $all_columns = array_merge(
99 array_flip(array_keys($index->getColumns()))
102 $this->fields
= array_keys($all_columns);
104 while ($row = $GLOBALS['dbi']->fetchRow($result)) {
105 $this->fields
[] = $row[0];
111 * Displays an error when the table cannot be found.
116 protected abstract function showMissingTableError();
119 * Loads coordinates of a table
123 protected function loadCoordinates()
125 foreach ($_REQUEST['t_h'] as $key => $value) {
126 if ($this->db
. '.' . $this->tableName
== $key) {
127 $this->x
= (double) $_REQUEST['t_x'][$key];
128 $this->y
= (double) $_REQUEST['t_y'][$key];
135 * Loads the table's display field
139 protected function loadDisplayField()
141 $this->displayfield
= PMA_getDisplayField($this->db
, $this->tableName
);
145 * Loads the PRIMARY key.
149 protected function loadPrimaryKey()
151 $result = $GLOBALS['dbi']->query(
152 'SHOW INDEX FROM ' . PMA_Util
::backquote($this->tableName
) . ';',
153 null, PMA_DatabaseInterface
::QUERY_STORE
155 if ($GLOBALS['dbi']->numRows($result) > 0) {
156 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
157 if ($row['Key_name'] == 'PRIMARY') {
158 $this->primary
[] = $row['Column_name'];
165 * Returns title of the current table,
166 * title can have the dimensions/co-ordinates of the table
168 * @return string title of the current table
170 protected function getTitle()
172 return ($this->tableDimension
173 ?
sprintf('%.0fx%0.f', $this->width
, $this->heightCell
)
176 . ' ' . $this->tableName
;