3 * hold the PMA_List base class
8 * @since phpMyAdmin 2.9.10
11 /* abstract public */ class PMA_List
14 * @var array the list items
20 * @var array details for list items
23 var $details = array();
26 * @var bool whether we need to re-index the database list for consistency keys
29 var $_need_to_reindex = false;
32 * @var mixed empty item
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
45 return reset($this->items
);
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
56 function getSingleItem()
58 if ($this->count() === 1) {
59 return $this->getFirst();
62 return $this->getEmpty();
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
74 return count($this->items
);
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
85 return $this->item_empty
;
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
100 foreach (func_get_args() as $result) {
101 if (! in_array($result, $this->items
)) {
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();
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";
137 * returns default item
139 * @uses PMA_List::getEmpty() as fallback
140 * @return string default item
142 function getDefault()
144 return $this->getEmpty();
152 /* abstract public */ function build() {}