bug #2363919 [display] Incorrect size for view
[phpmyadmin/crack.git] / libraries / List.class.php
blob07b4f847bcea469500e034ce4937bf64fc604669
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @version $Id$
7 */
9 /**
10 * @todo add caching
11 * @since phpMyAdmin 2.9.10
12 * @abstract
14 abstract class PMA_List extends ArrayObject
16 /**
17 * @var mixed empty item
19 protected $item_empty = '';
21 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
23 parent::__construct($array, $flags, $iterator_class);
26 /**
27 * returns item only if there is only one in the list
29 * @uses count()
30 * @uses reset()
31 * @uses PMA_List::getEmpty() to return it
32 * @return single item
34 public function getSingleItem()
36 if (count($this) === 1) {
37 return reset($this);
40 return $this->getEmpty();
43 /**
44 * defines what is an empty item (0, '', false or null)
46 * @uses PMA_List::$item_empty as return value
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 * @uses PMA_List::$items to check for existence of specific item
59 * @uses func_get_args()
60 * @uses in_array() to check if given arguments exists in PMA_List::$items
61 * @param string $db_name,.. one or more mysql result resources
62 * @return boolean true if all items exists, otheriwse false
64 public function exists()
66 $this_elements = $this->getArrayCopy();
67 foreach (func_get_args() as $result) {
68 if (! in_array($result, $this_elements)) {
69 return false;
73 return true;
76 /**
77 * returns HTML <option>-tags to be used inside <select></select>
79 * @uses PMA_List::$items to build up the option items
80 * @uses PMA_List::getDefault() to mark this as selected if requested
81 * @uses htmlspecialchars() to escape items
82 * @param mixed $selected the selected db or true for selecting current db
83 * @param boolean $include_information_schema
84 * @return string HTML option tags
86 public function getHtmlOptions($selected = '', $include_information_schema = true)
88 if (true === $selected) {
89 $selected = $this->getDefault();
92 $options = '';
93 foreach ($this as $each_item) {
94 if (false === $include_information_schema && 'information_schema' === $each_item) {
95 continue;
97 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
98 if ($selected === $each_item) {
99 $options .= ' selected="selected"';
101 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
104 return $options;
108 * returns default item
110 * @uses PMA_List::getEmpty() as fallback
111 * @return string default item
113 public function getDefault()
115 return $this->getEmpty();
119 * builds up the list
122 abstract public function build();