2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * hold the PMA_List base class
11 * @since phpMyAdmin 2.9.10
15 abstract class PMA_List
extends ArrayObject
18 * @var mixed empty item
20 protected $item_empty = '';
22 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
24 parent
::__construct($array, $flags, $iterator_class);
28 * returns item only if there is only one in the list
32 * @uses PMA_List::getEmpty() to return it
35 public function getSingleItem()
37 if (count($this) === 1) {
41 return $this->getEmpty();
45 * defines what is an empty item (0, '', false or null)
47 * @uses PMA_List::$item_empty as return value
48 * @return mixed an empty item
50 public function getEmpty()
52 return $this->item_empty
;
56 * checks if the given db names exists in the current list, if there is
57 * missing at least one item it returns false otherwise true
59 * @uses PMA_List::$items to check for existence of specific item
60 * @uses func_get_args()
61 * @uses in_array() to check if given arguments exists in PMA_List::$items
62 * @param string $db_name,.. one or more mysql result resources
63 * @return boolean true if all items exists, otheriwse false
65 public function exists()
67 $this_elements = $this->getArrayCopy();
68 foreach (func_get_args() as $result) {
69 if (! in_array($result, $this_elements)) {
78 * returns HTML <option>-tags to be used inside <select></select>
80 * @uses PMA_List::$items to build up the option items
81 * @uses PMA_List::getDefault() to mark this as selected if requested
82 * @uses htmlspecialchars() to escape items
83 * @param mixed $selected the selected db or true for selecting current db
84 * @param boolean $include_information_schema
85 * @return string HTML option tags
87 public function getHtmlOptions($selected = '', $include_information_schema = true)
89 if (true === $selected) {
90 $selected = $this->getDefault();
94 foreach ($this as $each_item) {
95 if (false === $include_information_schema && 'information_schema' === $each_item) {
98 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
99 if ($selected === $each_item) {
100 $options .= ' selected="selected"';
102 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
109 * returns default item
111 * @uses PMA_List::getEmpty() as fallback
112 * @return string default item
114 public function getDefault()
116 return $this->getEmpty();
123 abstract public function build();