home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / List.class.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  4.1 KB  |  162 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * hold the PMA_List base class
  5.  *
  6.  * @version $Id: List.class.php 10786 2007-10-14 12:23:22Z lem9 $
  7.  */
  8.  
  9. /**
  10.  * @todo add caching
  11.  * @since phpMyAdmin 2.9.10
  12.  * @abstract
  13.  */
  14. /* abstract public */ class PMA_List
  15. {
  16.     /**
  17.      * @var array   the list items
  18.      * @access public
  19.      */
  20.     var $items = array();
  21.  
  22.     /**
  23.      * @var array   details for list items
  24.      * @access public
  25.      */
  26.     var $details = array();
  27.  
  28.     /**
  29.      * @var bool    whether we need to re-index the database list for consistency keys
  30.      * @access protected
  31.      */
  32.     var $_need_to_reindex = false;
  33.  
  34.     /**
  35.      * @var mixed   empty item
  36.      */
  37.     var $item_empty = '';
  38.  
  39.     /**
  40.      * returns first item from list
  41.      *
  42.      * @uses    PMA_List::$items to get first item
  43.      * @uses    reset() to retrive first item from PMA_List::$items array
  44.      * @return  string  value of first item
  45.      */
  46.     function getFirst()
  47.     {
  48.         return reset($this->items);
  49.     }
  50.  
  51.     /**
  52.      * returns item only if there is only one in the list
  53.      *
  54.      * @uses    PMA_List::count() to decide what to return
  55.      * @uses    PMA_List::getFirst() to return it
  56.      * @uses    PMA_List::getEmpty() to return it
  57.      * @return  single item
  58.      */
  59.     function getSingleItem()
  60.     {
  61.         if ($this->count() === 1) {
  62.             return $this->getFirst();
  63.         }
  64.  
  65.         return $this->getEmpty();
  66.     }
  67.  
  68.     /**
  69.      * returns list item count
  70.      *
  71.      * @uses    PMA_List::$items to count it items
  72.      * @uses    count() to count items in PMA_List::$items
  73.      * @return  integer PMA_List::$items count
  74.      */
  75.     function count()
  76.     {
  77.         return count($this->items);
  78.     }
  79.  
  80.     /**
  81.      * defines what is an empty item (0, '', false or null)
  82.      *
  83.      * @uses    PMA_List::$item_empty as return value
  84.      * @return  mixed   an empty item
  85.      */
  86.     function getEmpty()
  87.     {
  88.         return $this->item_empty;
  89.     }
  90.  
  91.     /**
  92.      * checks if the given db names exists in the current list, if there is
  93.      * missing at least one item it reutrns false other wise true
  94.      *
  95.      * @uses    PMA_List::$items to check for existence of specific item
  96.      * @uses    func_get_args()
  97.      * @uses    in_array() to check if given arguments exists in PMA_List::$items
  98.      * @param   string  $db_name,..     one or more mysql result resources
  99.      * @return  boolean true if all items exists, otheriwse false
  100.      */
  101.     function exists()
  102.     {
  103.         foreach (func_get_args() as $result) {
  104.             if (! in_array($result, $this->items)) {
  105.                 return false;
  106.             }
  107.         }
  108.  
  109.         return true;
  110.     }
  111.  
  112.     /**
  113.      * returns HTML <option>-tags to be used inside <select></select>
  114.      *
  115.      * @uses    PMA_List::$items to build up the option items
  116.      * @uses    PMA_List::getDefault() to mark this as selected if requested
  117.      * @uses    htmlspecialchars() to escape items
  118.      * @param   mixed   $selected   the selected db or true for selecting current db
  119.      * @param   boolean $include_information_schema
  120.      * @return  string  HTML option tags
  121.      */
  122.     function getHtmlOptions($selected = '', $include_information_schema = true)
  123.     {
  124.         if (true === $selected) {
  125.             $selected = $this->getDefault();
  126.         }
  127.  
  128.         $options = '';
  129.         foreach ($this->items as $each_db) {
  130.             if (false === $include_information_schema && 'information_schema' === $each_db) {
  131.                 continue;
  132.             }
  133.             $options .= '<option value="' . htmlspecialchars($each_db) . '"';
  134.             if ($selected === $each_db) {
  135.                 $options .= ' selected="selected"';
  136.             }
  137.             $options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
  138.         }
  139.  
  140.         return $options;
  141.     }
  142.  
  143.     /**
  144.      * returns default item
  145.      *
  146.      * @uses    PMA_List::getEmpty() as fallback
  147.      * @return  string  default item
  148.      */
  149.     function getDefault()
  150.     {
  151.         return $this->getEmpty();
  152.     }
  153.  
  154.     /**
  155.      * builds up the list
  156.      *
  157.      * @abstract
  158.      */
  159.     /* abstract public */ function build() {}
  160. }
  161. ?>
  162.