I18Nv2
[ class tree: I18Nv2 ] [ index: I18Nv2 ] [ all elements ]

Source for file HtmlSelect.php

Documentation is available at HtmlSelect.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PEAR :: I18Nv2 :: DecoratedList :: HtmlSelect                        |
  4. // +----------------------------------------------------------------------+
  5. // | This source file is subject to version 3.0 of the PHP license,       |
  6. // | that is available at http://www.php.net/license/3_0.txt              |
  7. // | If you did not receive a copy of the PHP license and are unable      |
  8. // | to obtain it through the world-wide-web, please send a note to       |
  9. // | license@php.net so we can mail you a copy immediately.               |
  10. // +----------------------------------------------------------------------+
  11. // | Copyright (c) 2004 Michael Wallner <mike@iworks.at>                  |
  12. // +----------------------------------------------------------------------+
  13. //
  14. // $Id: HtmlSelect.php,v 1.5 2004/05/03 15:01:28 mike Exp $
  15.  
  16. require_once 'I18Nv2/DecoratedList.php';
  17.  
  18. /**
  19. * I18Nv2_DecoratedList_HtmlSelect
  20. * Example:
  21. * <code>
  22. *   require_once 'I18Nv2/Country.php';
  23. *   require_once 'I18Nv2/DecoratedList/HtmlSelect.php';
  24. *   $country = &new I18Nv2_Country('de', 'iso-8859-1');
  25. *   $select  = &new I18Nv2_DecoratedList_HtmlSelect($country);
  26. *   $select->attributes['select']['name'] = 'country';
  27. *   $select->selected['DE'] = true;
  28. *   echo $select->getAllCodes();
  29. * </code>
  30. *
  31. @author       Michael Wallner <mike@php.net>
  32. @version      $Revision: 1.5 $
  33. @package      I18Nv2
  34. */
  35. {
  36.     /**
  37.     * HTML attributes of the select and the option tags
  38.     * 
  39.     * <code>
  40.     * $HtmlSelect->attributes['select']['onchange'] = 'this.form.submit()';
  41.     * </code>
  42.     * 
  43.     * @access   public
  44.     * @var      array 
  45.     */
  46.     var $attributes = array(
  47.         'select' => array(
  48.             'size' => 1,
  49.         ),
  50.         'option' => array(
  51.         )
  52.     );
  53.     
  54.     /**
  55.     * Selected option(s)
  56.     * 
  57.     * <code>
  58.     * $HtmlSelect->selected[$code] = true;
  59.     * </code>
  60.     * 
  61.     * @access   public
  62.     * @var      array 
  63.     */
  64.     var $selected = array();
  65.     
  66.     /** 
  67.     * decorate
  68.     * 
  69.     * @access   protected
  70.     * @return   string 
  71.     * @param    mixed   $value 
  72.     */
  73.     function decorate($value)
  74.     {
  75.         static $codes;
  76.         
  77.         if (is_string($value)) {
  78.             if (!isset($codes)) {
  79.                 $codes $this->list->getAllCodes();
  80.             }
  81.             $key array_search($value$codes);
  82.             return
  83.                 '<option ' $this->_optAttr($key'>' 
  84.                     $value .
  85.                 '</option>';
  86.         elseif(is_array($value)) {
  87.             return 
  88.                 '<select ' $this->_getAttr('>' 
  89.                     implode(''array_map(array(&$this'decorate')$value)) 
  90.                 '</select>';
  91.         }
  92.         return $value;
  93.     }
  94.     
  95.     /**
  96.     * Get HTML attributes for the option tag
  97.     * 
  98.     * @access   private
  99.     * @return   string 
  100.     * @param    string  $key 
  101.     */
  102.     function _optAttr($key)
  103.     {
  104.         $attributes 'value="' $key '" ' $this->_getAttr('option');
  105.         if (isset($this->selected[$key]&& $this->selected[$key]{
  106.             $attributes .= 'selected="selected"';
  107.         }
  108.         return $attributes;
  109.     }
  110.     
  111.     /**
  112.     * Get HTML attributes
  113.     * 
  114.     * @access   private
  115.     * @return   string 
  116.     * @param    string  $of 
  117.     */
  118.     function _getAttr($of 'select')
  119.     {
  120.         $attributes '';
  121.         foreach ($this->attributes[$ofas $attr => $value{
  122.             $attributes .= $attr '="' $value .'" ';
  123.         }
  124.         return $attributes;
  125.     }
  126. }
  127. ?>

Documentation generated on Mon, 11 Mar 2019 13:54:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.