2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * hold the PMA_List base class
11 * @since phpMyAdmin 2.9.10
14 abstract class PMA_List
extends ArrayObject
17 * @var mixed empty item
19 protected $item_empty = '';
21 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
23 parent
::__construct($array, $flags, $iterator_class);
27 * returns item only if there is only one in the list
31 * @uses PMA_List::getEmpty() to return it
34 public function getSingleItem()
36 if (count($this) === 1) {
40 return $this->getEmpty();
44 * defines what is an empty item (0, '', false or null)
46 * @uses PMA_List::$item_empty as return value
47 * @return mixed an empty item
49 public function getEmpty()
51 return $this->item_empty
;
55 * checks if the given db names exists in the current list, if there is
56 * missing at least one item it returns false otherwise true
58 * @uses PMA_List::$items to check for existence of specific item
59 * @uses func_get_args()
60 * @uses in_array() to check if given arguments exists in PMA_List::$items
61 * @param string $db_name,.. one or more mysql result resources
62 * @return boolean true if all items exists, otheriwse false
64 public function exists()
66 $this_elements = $this->getArrayCopy();
67 foreach (func_get_args() as $result) {
68 if (! in_array($result, $this_elements)) {
77 * returns HTML <option>-tags to be used inside <select></select>
79 * @uses PMA_List::$items to build up the option items
80 * @uses PMA_List::getDefault() to mark this as selected if requested
81 * @uses htmlspecialchars() to escape items
82 * @param mixed $selected the selected db or true for selecting current db
83 * @param boolean $include_information_schema
84 * @return string HTML option tags
86 public function getHtmlOptions($selected = '', $include_information_schema = true)
88 if (true === $selected) {
89 $selected = $this->getDefault();
93 foreach ($this as $each_item) {
94 if (false === $include_information_schema && 'information_schema' === $each_item) {
97 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
98 if ($selected === $each_item) {
99 $options .= ' selected="selected"';
101 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
108 * returns default item
110 * @uses PMA_List::getEmpty() as fallback
111 * @return string default item
113 public function getDefault()
115 return $this->getEmpty();
122 abstract public function build();