source: mysql/libraries/PMA_List.class.php@ 5

Last change on this file since 5 was 5, checked in by george, 18 years ago

import

File size: 3.7 KB
Line 
1<?php
2/**
3 * hold the PMA_List base class
4 */
5
6/**
7 * @todo add caching
8 * @since phpMyAdmin 2.9.10
9 * @abstract
10 */
11/* abstract public */ class PMA_List
12{
13 /**
14 * @var array the list items
15 * @access public
16 */
17 var $items = array();
18
19 /**
20 * @var array details for list items
21 * @access public
22 */
23 var $details = array();
24
25 /**
26 * @var bool whether we need to re-index the database list for consistency keys
27 * @access protected
28 */
29 var $_need_to_reindex = false;
30
31 /**
32 * @var mixed empty item
33 */
34 var $item_empty = '';
35
36 /**
37 * returns first item from list
38 *
39 * @uses PMA_List::$items to get first item
40 * @uses reset() to retrive first item from PMA_List::$items array
41 * @return string value of first item
42 */
43 function getFirst()
44 {
45 return reset($this->items);
46 }
47
48 /**
49 * returns item only if there is only one in the list
50 *
51 * @uses PMA_List::count() to decide what to return
52 * @uses PMA_List::getFirst() to return it
53 * @uses PMA_List::getEmpty() to return it
54 * @return single item
55 */
56 function getSingleItem()
57 {
58 if ($this->count() === 1) {
59 return $this->getFirst();
60 }
61
62 return $this->getEmpty();
63 }
64
65 /**
66 * returns list item count
67 *
68 * @uses PMA_List::$items to count it items
69 * @uses count() to count items in PMA_List::$items
70 * @return integer PMA_List::$items count
71 */
72 function count()
73 {
74 return count($this->items);
75 }
76
77 /**
78 * defines what is an empty item (0, '', false or null)
79 *
80 * @uses PMA_List::$item_empty as return value
81 * @return mixed an empty item
82 */
83 function getEmpty()
84 {
85 return $this->item_empty;
86 }
87
88 /**
89 * checks if the given db names exists in the current list, if there is
90 * missing at least one item it reutrns false other wise true
91 *
92 * @uses PMA_List::$items to check for existence of specific item
93 * @uses func_get_args()
94 * @uses in_array() to check if given arguments exists in PMA_List::$items
95 * @param string $db_name,.. one or more mysql result resources
96 * @return boolean true if all items exists, otheriwse false
97 */
98 function exists()
99 {
100 foreach (func_get_args() as $result) {
101 if (! in_array($result, $this->items)) {
102 return false;
103 }
104 }
105
106 return true;
107 }
108
109 /**
110 * returns HTML <option>-tags to be used inside <select></select>
111 *
112 * @uses PMA_List::$items to build up the option items
113 * @uses PMA_List::getDefault() to mark this as sleected if requested
114 * @uses htmlspecialchars() to escape items
115 * @param mixed $selected the selected db or true for selecting current db
116 * @return string HTML option tags
117 */
118 function getHtmlOptions($selected = '')
119 {
120 if (true === $selected) {
121 $selected = $this->getDefault();
122 }
123
124 $options = '';
125 foreach ($this->items as $each_db) {
126 $options .= '<option value="' . htmlspecialchars($each_db) . '"';
127 if ($selected === $each_db) {
128 $options .= ' selected="selected"';
129 }
130 $options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
131 }
132
133 return $options;
134 }
135
136 /**
137 * returns default item
138 *
139 * @uses PMA_List::getEmpty() as fallback
140 * @return string default item
141 */
142 function getDefault()
143 {
144 return $this->getEmpty();
145 }
146
147 /**
148 * builds up the list
149 *
150 * @abstract
151 */
152 /* abstract public */ function build() {}
153}
154?>
Note: See TracBrowser for help on using the repository browser.