Translation update done using Pootle.
[phpmyadmin/tyronm.git] / libraries / List.class.php
blob694546a0108551d870d993f0db182b5964870117
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 && 'information_schema' === $each_item) {
86 continue;
88 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
89 if ($selected === $each_item) {
90 $options .= ' selected="selected"';
92 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
95 return $options;
98 /**
99 * returns default item
101 * @return string default item
103 public function getDefault()
105 return $this->getEmpty();
109 * builds up the list
112 abstract public function build();