2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * hold the PMA_List base class
12 * @since phpMyAdmin 2.9.10
16 abstract class PMA_List
extends ArrayObject
19 * @var mixed empty item
21 protected $item_empty = '';
23 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
25 parent
::__construct($array, $flags, $iterator_class);
29 * returns item only if there is only one in the list
33 * @uses PMA_List::getEmpty() to return it
36 public function getSingleItem()
38 if (count($this) === 1) {
42 return $this->getEmpty();
46 * defines what is an empty item (0, '', false or null)
48 * @uses PMA_List::$item_empty as return value
49 * @return mixed an empty item
51 public function getEmpty()
53 return $this->item_empty
;
57 * checks if the given db names exists in the current list, if there is
58 * missing at least one item it returns false otherwise true
60 * @uses PMA_List::$items to check for existence of specific item
61 * @uses func_get_args()
62 * @uses in_array() to check if given arguments exists in PMA_List::$items
63 * @param string $db_name,.. one or more mysql result resources
64 * @return boolean true if all items exists, otheriwse false
66 public function exists()
68 $this_elements = $this->getArrayCopy();
69 foreach (func_get_args() as $result) {
70 if (! in_array($result, $this_elements)) {
79 * returns HTML <option>-tags to be used inside <select></select>
81 * @uses PMA_List::$items to build up the option items
82 * @uses PMA_List::getDefault() to mark this as selected if requested
83 * @uses htmlspecialchars() to escape items
84 * @param mixed $selected the selected db or true for selecting current db
85 * @param boolean $include_information_schema
86 * @return string HTML option tags
88 public function getHtmlOptions($selected = '', $include_information_schema = true)
90 if (true === $selected) {
91 $selected = $this->getDefault();
95 foreach ($this as $each_item) {
96 if (false === $include_information_schema && 'information_schema' === $each_item) {
99 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
100 if ($selected === $each_item) {
101 $options .= ' selected="selected"';
103 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
110 * returns default item
112 * @uses PMA_List::getEmpty() as fallback
113 * @return string default item
115 public function getDefault()
117 return $this->getEmpty();
124 abstract public function build();