Translation update done using Pootle.
[phpmyadmin/crack.git] / libraries / List.class.php
blob65ac7fc5a02658603cd04e03d059bc6a2e4ea635
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 * @uses count()
31 * @uses reset()
32 * @uses PMA_List::getEmpty() to return it
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 * @uses PMA_List::$item_empty as return value
48 * @return mixed an empty item
50 public function getEmpty()
52 return $this->item_empty;
55 /**
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)) {
70 return false;
74 return true;
77 /**
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();
93 $options = '';
94 foreach ($this as $each_item) {
95 if (false === $include_information_schema && 'information_schema' === $each_item) {
96 continue;
98 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
99 if ($selected === $each_item) {
100 $options .= ' selected="selected"';
102 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
105 return $options;
109 * returns default item
111 * @uses PMA_List::getEmpty() as fallback
112 * @return string default item
114 public function getDefault()
116 return $this->getEmpty();
120 * builds up the list
123 abstract public function build();