Add OK and Cancel button for grid editing
[phpmyadmin/arisferyanto.git] / libraries / List.class.php
blob661073b27e292ac3248c5f653f0f007b6a3ac1d1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @package PhpMyAdmin
7 */
9 /**
10 * @todo add caching
11 * @since phpMyAdmin 2.9.10
12 * @abstract
13 * @package PhpMyAdmin
15 abstract class PMA_List extends ArrayObject
17 /**
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);
27 /**
28 * returns item only if there is only one in the list
30 * @return single item
32 public function getSingleItem()
34 if (count($this) === 1) {
35 return reset($this);
38 return $this->getEmpty();
41 /**
42 * defines what is an empty item (0, '', false or null)
44 * @return mixed an empty item
46 public function getEmpty()
48 return $this->item_empty;
51 /**
52 * checks if the given db names exists in the current list, if there is
53 * missing at least one item it returns false otherwise true
55 * @param string $db_name,.. one or more mysql result resources
56 * @return boolean true if all items exists, otheriwse false
58 public function exists()
60 $this_elements = $this->getArrayCopy();
61 foreach (func_get_args() as $result) {
62 if (! in_array($result, $this_elements)) {
63 return false;
67 return true;
70 /**
71 * returns HTML <option>-tags to be used inside <select></select>
73 * @param mixed $selected the selected db or true for selecting current db
74 * @param boolean $include_information_schema
75 * @return string HTML option tags
77 public function getHtmlOptions($selected = '', $include_information_schema = true)
79 if (true === $selected) {
80 $selected = $this->getDefault();
83 $options = '';
84 foreach ($this as $each_item) {
85 if (false === $include_information_schema
86 && PMA_is_system_schema($each_item)) {
87 continue;
89 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
90 if ($selected === $each_item) {
91 $options .= ' selected="selected"';
93 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
96 return $options;
99 /**
100 * returns default item
102 * @return string default item
104 public function getDefault()
106 return $this->getEmpty();
110 * builds up the list
113 abstract public function build();