Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / libraries / List.class.php
blobd18e22fe0c6812fe1129318005aabe22c3223e4f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Generic list class
15 * @todo add caching
16 * @abstract
17 * @package PhpMyAdmin
18 * @since phpMyAdmin 2.9.10
20 abstract class PMA_List extends ArrayObject
22 /**
23 * @var mixed empty item
25 protected $item_empty = '';
27 /**
28 * PMA_List constructor
30 * @param array $array The input parameter accepts an array or an
31 * Object.
32 * @param int $flags Flags to control the behaviour of the
33 * ArrayObject object.
34 * @param string $iterator_class Specify the class that will be used for
35 * iteration of the ArrayObject object.
36 * ArrayIterator is the default class used.
38 public function __construct(
39 $array = array(), $flags = 0, $iterator_class = "ArrayIterator"
40 ) {
41 parent::__construct($array, $flags, $iterator_class);
44 /**
45 * defines what is an empty item (0, '', false or null)
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 * @return boolean true if all items exists, otherwise false
60 public function exists()
62 $this_elements = $this->getArrayCopy();
63 foreach (func_get_args() as $result) {
64 if (! in_array($result, $this_elements)) {
65 return false;
69 return true;
72 /**
73 * returns HTML <option>-tags to be used inside <select></select>
75 * @param mixed $selected the selected db or true for
76 * selecting current db
77 * @param boolean $include_information_schema whether include information schema
79 * @return string HTML option tags
81 public function getHtmlOptions(
82 $selected = '', $include_information_schema = true
83 ) {
84 if (true === $selected) {
85 $selected = $this->getDefault();
88 $options = '';
89 foreach ($this as $each_item) {
90 if (false === $include_information_schema
91 && $GLOBALS['dbi']->isSystemSchema($each_item)
92 ) {
93 continue;
95 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
96 if ($selected === $each_item) {
97 $options .= ' selected="selected"';
99 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
102 return $options;
106 * returns default item
108 * @return string default item
110 public function getDefault()
112 return $this->getEmpty();
116 * builds up the list
118 * @return void
120 abstract public function build();