Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / List.class.php
blobf87c89dfff06fc569ad31224ece39e7df4d19cda
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * @todo add caching
14 * @abstract
15 * @package PhpMyAdmin
16 * @since phpMyAdmin 2.9.10
18 abstract class PMA_List extends ArrayObject
20 /**
21 * @var mixed empty item
23 protected $item_empty = '';
25 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
27 parent::__construct($array, $flags, $iterator_class);
30 /**
31 * returns item only if there is only one in the list
33 * @return single item
35 public function getSingleItem()
37 if (count($this) === 1) {
38 return reset($this);
41 return $this->getEmpty();
44 /**
45 * defines what is an empty item (0, '', false or null)
47 * @return mixed an empty item
49 public function getEmpty()
51 return $this->item_empty;
54 /**
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 * @return boolean true if all items exists, otheriwse false
60 public function exists()
62 $this_elements = $this->getArrayCopy();
63 foreach (func_get_args() as $result) {
64 if (! in_array($result, $this_elements)) {
65 return false;
69 return true;
72 /**
73 * returns HTML <option>-tags to be used inside <select></select>
75 * @param mixed $selected the selected db or true for
76 * selecting current db
77 * @param boolean $include_information_schema whether include information schema
79 * @return string HTML option tags
81 public function getHtmlOptions($selected = '', $include_information_schema = true)
83 if (true === $selected) {
84 $selected = $this->getDefault();
87 $options = '';
88 foreach ($this as $each_item) {
89 if (false === $include_information_schema
90 && PMA_is_system_schema($each_item)
91 ) {
92 continue;
94 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
95 if ($selected === $each_item) {
96 $options .= ' selected="selected"';
98 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
101 return $options;
105 * returns default item
107 * @return string default item
109 public function getDefault()
111 return $this->getEmpty();
115 * builds up the list
117 * @return void
119 abstract public function build();