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

Source for file Select.php

Documentation is available at Select.php

  1. <?php
  2. /**
  3.  * Formagic
  4.  *
  5.  * LICENCE
  6.  *
  7.  * This source file is subject to the new BSD license that is bundled
  8.  * with this package in the file LICENSE.txt.
  9.  * It is also available through the world-wide-web at
  10.  * http://formagic.weasle.de/licence.txt
  11.  * If you did not receive a copy of the license and are unable to
  12.  * obtain it through the world-wide-web, please send an email
  13.  * to licence@weasle.de so we can send you a copy immediately.
  14.  *
  15.  * @category  Formagic
  16.  * @package   Item
  17.  * @author    Florian Sonnenburg
  18.  * @copyright Copyright (c) 2007 Florian Sonnenburg
  19.  * @license   http://formagic.weasle.de/licence.txt     New BSD License
  20.  * @revision  $Revision: 11 $
  21.  */
  22.  
  23. /**
  24.  * formagicItemSelect
  25.  *
  26.  * @category  Formagic
  27.  * @package   Item
  28.  * @author Florian Sonnenburg
  29.  * @copyright Copyright (c) 2007
  30.  * @version $Id: Select.php 11 2007-08-12 20:02:57Z meweasle $
  31.  * @access public
  32.  */
  33.  
  34.     /**
  35.      * Array containing select options
  36.      * @var     array 
  37.      * @access  private
  38.      */
  39.     private $data;
  40.  
  41.  
  42.     /**
  43.      * Generic argument handler
  44.      *
  45.      * @param string $key 
  46.      * @param mixed $arg 
  47.      * @return void 
  48.      */
  49.     protected function _handleArg($key$arg)
  50.     {
  51.         switch($key){
  52.             case 'data':
  53.                 $this->data $arg;
  54.                 break;
  55.             default:
  56.                 throw new Exception("Argument type '$keynot supported");
  57.         // switch
  58.     }
  59.  
  60.     /**
  61.      * formagicItemSelect::setData()
  62.      *
  63.      * @param mixed $arr 
  64.      * @return boolean 
  65.      */
  66.     public function setData($arr)
  67.     {
  68.         $this->data $arr;
  69.         return true;
  70.     }
  71.  
  72.     /**
  73.      * HTML representation of Formagic select item
  74.      *
  75.      * @return string 
  76.      */
  77.     public function getHtml()
  78.     {
  79.         // HTML blocked
  80.         $currVal $this->getValue();
  81.         if ($this->_isBlocked{
  82.             $str "[".$this->data[$currVal]."]";
  83.  
  84.             if ($this->isPostItem{
  85.                 $str .= '<input type="hidden" name="' $this->name .
  86.                         '" value="' $currVal '" />';
  87.             }
  88.  
  89.         // HTML default
  90.         else {
  91.             $str '<select name="' $this->name . '" id="' $this->name . '"' .
  92.                    $this->_getAttributeStr(.">\n";
  93.             foreach($this->data as $key => $value{
  94.                 $s = (string)$key == (string)$currVal ' selected="selected"' '';
  95.                 $str .= "\t<option value=\"" $key "\"$s>$value "</option>\n";
  96.             }
  97.             $str .= '</select>';
  98.         }
  99.         return $str;
  100.     }
  101.  
  102. }

Documentation generated on Thu, 23 Aug 2007 00:29:47 +0200 by phpDocumentor 1.4.0