2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / List.class.php
blobf375a24ec83efeeb2db744c0a2f891e201f917a6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @version $Id$
7 */
9 /**
10 * @todo add caching
11 * @since phpMyAdmin 2.9.10
12 * @abstract
14 /* abstract public */ class PMA_List
16 /**
17 * @var array the list items
18 * @access public
20 var $items = array();
22 /**
23 * @var array details for list items
24 * @access public
26 var $details = array();
28 /**
29 * @var bool whether we need to re-index the database list for consistency keys
30 * @access protected
32 var $_need_to_reindex = false;
34 /**
35 * @var mixed empty item
37 var $item_empty = '';
39 /**
40 * returns first item from list
42 * @uses PMA_List::$items to get first item
43 * @uses reset() to retrive first item from PMA_List::$items array
44 * @return string value of first item
46 function getFirst()
48 return reset($this->items);
51 /**
52 * returns item only if there is only one in the list
54 * @uses PMA_List::count() to decide what to return
55 * @uses PMA_List::getFirst() to return it
56 * @uses PMA_List::getEmpty() to return it
57 * @return single item
59 function getSingleItem()
61 if ($this->count() === 1) {
62 return $this->getFirst();
65 return $this->getEmpty();
68 /**
69 * returns list item count
71 * @uses PMA_List::$items to count it items
72 * @uses count() to count items in PMA_List::$items
73 * @return integer PMA_List::$items count
75 function count()
77 return count($this->items);
80 /**
81 * defines what is an empty item (0, '', false or null)
83 * @uses PMA_List::$item_empty as return value
84 * @return mixed an empty item
86 function getEmpty()
88 return $this->item_empty;
91 /**
92 * checks if the given db names exists in the current list, if there is
93 * missing at least one item it reutrns false other wise true
95 * @uses PMA_List::$items to check for existence of specific item
96 * @uses func_get_args()
97 * @uses in_array() to check if given arguments exists in PMA_List::$items
98 * @param string $db_name,.. one or more mysql result resources
99 * @return boolean true if all items exists, otheriwse false
101 function exists()
103 foreach (func_get_args() as $result) {
104 if (! in_array($result, $this->items)) {
105 return false;
109 return true;
113 * returns HTML <option>-tags to be used inside <select></select>
115 * @uses PMA_List::$items to build up the option items
116 * @uses PMA_List::getDefault() to mark this as sleected if requested
117 * @uses htmlspecialchars() to escape items
118 * @param mixed $selected the selected db or true for selecting current db
119 * @return string HTML option tags
121 function getHtmlOptions($selected = '')
123 if (true === $selected) {
124 $selected = $this->getDefault();
127 $options = '';
128 foreach ($this->items as $each_db) {
129 $options .= '<option value="' . htmlspecialchars($each_db) . '"';
130 if ($selected === $each_db) {
131 $options .= ' selected="selected"';
133 $options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
136 return $options;
140 * returns default item
142 * @uses PMA_List::getEmpty() as fallback
143 * @return string default item
145 function getDefault()
147 return $this->getEmpty();
151 * builds up the list
153 * @abstract
155 /* abstract public */ function build() {}