Converting number of Excel column names no longer limited
[phpmyadmin/arisferyanto.git] / libraries / List.class.php
blob029b6fc3d7530f485220eae7ab6f070c3fd21553
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * @todo add caching
12 * @since phpMyAdmin 2.9.10
13 * @abstract
14 * @package phpMyAdmin
16 abstract class PMA_List extends ArrayObject
18 /**
19 * @var mixed empty item
21 protected $item_empty = '';
23 public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
25 parent::__construct($array, $flags, $iterator_class);
28 /**
29 * returns item only if there is only one in the list
31 * @uses count()
32 * @uses reset()
33 * @uses PMA_List::getEmpty() to return it
34 * @return single item
36 public function getSingleItem()
38 if (count($this) === 1) {
39 return reset($this);
42 return $this->getEmpty();
45 /**
46 * defines what is an empty item (0, '', false or null)
48 * @uses PMA_List::$item_empty as return value
49 * @return mixed an empty item
51 public function getEmpty()
53 return $this->item_empty;
56 /**
57 * checks if the given db names exists in the current list, if there is
58 * missing at least one item it returns false otherwise true
60 * @uses PMA_List::$items to check for existence of specific item
61 * @uses func_get_args()
62 * @uses in_array() to check if given arguments exists in PMA_List::$items
63 * @param string $db_name,.. one or more mysql result resources
64 * @return boolean true if all items exists, otheriwse false
66 public function exists()
68 $this_elements = $this->getArrayCopy();
69 foreach (func_get_args() as $result) {
70 if (! in_array($result, $this_elements)) {
71 return false;
75 return true;
78 /**
79 * returns HTML <option>-tags to be used inside <select></select>
81 * @uses PMA_List::$items to build up the option items
82 * @uses PMA_List::getDefault() to mark this as selected if requested
83 * @uses htmlspecialchars() to escape items
84 * @param mixed $selected the selected db or true for selecting current db
85 * @param boolean $include_information_schema
86 * @return string HTML option tags
88 public function getHtmlOptions($selected = '', $include_information_schema = true)
90 if (true === $selected) {
91 $selected = $this->getDefault();
94 $options = '';
95 foreach ($this as $each_item) {
96 if (false === $include_information_schema && 'information_schema' === $each_item) {
97 continue;
99 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
100 if ($selected === $each_item) {
101 $options .= ' selected="selected"';
103 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
106 return $options;
110 * returns default item
112 * @uses PMA_List::getEmpty() as fallback
113 * @return string default item
115 public function getDefault()
117 return $this->getEmpty();
121 * builds up the list
124 abstract public function build();