List.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * hold the PMA_List base class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Generic list class
  13. *
  14. * @todo add caching
  15. * @abstract
  16. * @package PhpMyAdmin
  17. * @since phpMyAdmin 2.9.10
  18. */
  19. abstract class PMA_List extends ArrayObject
  20. {
  21. /**
  22. * @var mixed empty item
  23. */
  24. protected $item_empty = '';
  25. /**
  26. * PMA_List constructor
  27. *
  28. * @param array $array The input parameter accepts an array or an
  29. * Object.
  30. * @param int $flags Flags to control the behaviour of the
  31. * ArrayObject object.
  32. * @param string $iterator_class Specify the class that will be used for
  33. * iteration of the ArrayObject object.
  34. * ArrayIterator is the default class used.
  35. */
  36. public function __construct(
  37. $array = array(), $flags = 0, $iterator_class = "ArrayIterator"
  38. ) {
  39. parent::__construct($array, $flags, $iterator_class);
  40. }
  41. /**
  42. * defines what is an empty item (0, '', false or null)
  43. *
  44. * @return mixed an empty item
  45. */
  46. public function getEmpty()
  47. {
  48. return $this->item_empty;
  49. }
  50. /**
  51. * checks if the given db names exists in the current list, if there is
  52. * missing at least one item it returns false otherwise true
  53. *
  54. * @return boolean true if all items exists, otheriwse false
  55. */
  56. public function exists()
  57. {
  58. $this_elements = $this->getArrayCopy();
  59. foreach (func_get_args() as $result) {
  60. if (! in_array($result, $this_elements)) {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. /**
  67. * returns HTML <option>-tags to be used inside <select></select>
  68. *
  69. * @param mixed $selected the selected db or true for
  70. * selecting current db
  71. * @param boolean $include_information_schema whether include information schema
  72. *
  73. * @return string HTML option tags
  74. */
  75. public function getHtmlOptions(
  76. $selected = '', $include_information_schema = true
  77. ) {
  78. if (true === $selected) {
  79. $selected = $this->getDefault();
  80. }
  81. $options = '';
  82. foreach ($this as $each_item) {
  83. if (false === $include_information_schema
  84. && $GLOBALS['dbi']->isSystemSchema($each_item)
  85. ) {
  86. continue;
  87. }
  88. $options .= '<option value="' . htmlspecialchars($each_item) . '"';
  89. if ($selected === $each_item) {
  90. $options .= ' selected="selected"';
  91. }
  92. $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
  93. }
  94. return $options;
  95. }
  96. /**
  97. * returns default item
  98. *
  99. * @return string default item
  100. */
  101. public function getDefault()
  102. {
  103. return $this->getEmpty();
  104. }
  105. /**
  106. * builds up the list
  107. *
  108. * @return void
  109. */
  110. abstract public function build();
  111. }
  112. ?>