Support displaying in UTC (RFE #1440386).
[phpmyadmin/last10db.git] / libraries / PMA_List.class.php
blob906218983879a89c1214a96c7c31c18e3b9dbab9
1 <?php
2 /**
3 * hold the PMA_List base class
4 */
6 /**
7 * @todo add caching
8 * @since phpMyAdmin 2.9.10
9 * @abstract
11 /* abstract public */ class PMA_List
13 /**
14 * @var array the list items
15 * @access public
17 var $items = array();
19 /**
20 * @var array details for list items
21 * @access public
23 var $details = array();
25 /**
26 * @var bool whether we need to re-index the database list for consistency keys
27 * @access protected
29 var $_need_to_reindex = false;
31 /**
32 * @var mixed empty item
34 var $item_empty = '';
36 /**
37 * returns first item from list
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
43 function getFirst()
45 return reset($this->items);
48 /**
49 * returns item only if there is only one in the list
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
56 function getSingleItem()
58 if ($this->count() === 1) {
59 return $this->getFirst();
62 return $this->getEmpty();
65 /**
66 * returns list item count
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
72 function count()
74 return count($this->items);
77 /**
78 * defines what is an empty item (0, '', false or null)
80 * @uses PMA_List::$item_empty as return value
81 * @return mixed an empty item
83 function getEmpty()
85 return $this->item_empty;
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
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
98 function exists()
100 foreach (func_get_args() as $result) {
101 if (! in_array($result, $this->items)) {
102 return false;
106 return true;
110 * returns HTML <option>-tags to be used inside <select></select>
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
118 function getHtmlOptions($selected = '')
120 if (true === $selected) {
121 $selected = $this->getDefault();
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"';
130 $options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
133 return $options;
137 * returns default item
139 * @uses PMA_List::getEmpty() as fallback
140 * @return string default item
142 function getDefault()
144 return $this->getEmpty();
148 * builds up the list
150 * @abstract
152 /* abstract public */ function build() {}