Alpha Framework alpha--view--widgets
[ class tree: alpha--view--widgets ] [ index: alpha--view--widgets ] [ all elements ]

Source for file StringBox.inc

Documentation is available at StringBox.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/types/String.inc';
  4.  
  5. /**
  6.  * String HTML input box custom widget
  7.  * 
  8.  * @package alpha::view::widgets
  9.  * @since 1.0
  10.  * @author John Collins <dev@alphaframework.org>
  11.  * @version $Id: StringBox.inc 1341 2011-03-17 15:02:02Z johnc $
  12.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  13.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  14.  *  All rights reserved.
  15.  * 
  16.  *  <pre>
  17.  *  Redistribution and use in source and binary forms, with or
  18.  *  without modification, are permitted provided that the
  19.  *  following conditions are met:
  20.  * 
  21.  *  * Redistributions of source code must retain the above
  22.  *    copyright notice, this list of conditions and the
  23.  *    following disclaimer.
  24.  *  * Redistributions in binary form must reproduce the above
  25.  *    copyright notice, this list of conditions and the
  26.  *    following disclaimer in the documentation and/or other
  27.  *    materials provided with the distribution.
  28.  *  * Neither the name of the Alpha Framework nor the names
  29.  *    of its contributors may be used to endorse or promote
  30.  *    products derived from this software without specific
  31.  *    prior written permission.
  32.  *   
  33.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  34.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  35.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  36.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  38.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  40.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  42.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  43.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  44.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.  *  </pre>
  47.  *  
  48.  */
  49. class StringBox {
  50.     /**
  51.      * The string object that will be edited by this string box
  52.      * 
  53.      * @var String 
  54.      * @since 1.0
  55.      */
  56.     public $stringObject;
  57.     
  58.     /**
  59.      * The data label for the string object
  60.      * 
  61.      * @var string 
  62.      * @since 1.0
  63.      */
  64.     public $label;
  65.     
  66.     /**
  67.      * The name of the HTML input box
  68.      * 
  69.      * @var string 
  70.      * @since 1.0
  71.      */
  72.     public $name;
  73.     
  74.     /**
  75.      * The display size of the input box
  76.      * 
  77.      * @var integer 
  78.      * @since 1.0
  79.      * 
  80.      */
  81.     public $size;
  82.     
  83.     /**
  84.      * The constructor
  85.      * 
  86.      * @param String $string The string object that will be edited by this text box.
  87.      * @param string $label The data label for the string object.
  88.      * @param string $name The name of the HTML input box.
  89.      * @param integer $size The display size (characters).
  90.      * @since 1.0
  91.      * @throws IllegalArguementException
  92.      */
  93.     public function __construct($string$label$name$size=0{
  94.         if($string instanceof String)
  95.             $this->stringObject = $string;
  96.         else
  97.             throw new IllegalArguementException('String object passed ['.var_export($stringtrue).'] is not a valid String object!');
  98.         
  99.         $this->label = $label;
  100.         $this->name = $name;
  101.         $this->size = $size;
  102.     }
  103.     
  104.     /**
  105.      * Renders the HTML and javascript for the string box
  106.      * 
  107.      * @param bool $tableTags determines if table tags are also rendered for the StringBox
  108.      * @param bool $readOnly set to true to make the text box readonly (defaults to false)
  109.      * @return string 
  110.      * @since 1.0
  111.      */
  112.     public function render($tableTags=true$readOnly=false{
  113.         $html '';
  114.          
  115.         if ($tableTags{
  116.             $html .= '<tr><th style="width:25%;">';
  117.             $html .= $this->label;
  118.             $html .= '</th>';
  119.     
  120.             $html .= '<td>';
  121.             $html .= '<input '.($this->stringObject->checkIsPassword()'type="password"':'type="text"').($this->size == ' style="width:100%;"' ' size="'.$this->size.'"').' maxlength="'.String::MAX_SIZE.'" name="'.$this->name.'" id="'.$this->name.'" value="'.((isset($_POST[$this->name]&& $this->stringObject->getValue(== "")$_POST[$this->name$this->stringObject->getValue()).'"'.($readOnly 'readonly class="readonly"' '').'/>';
  122.             $html .= '</td></tr>';
  123.         }else{
  124.             $html .= '<input '.($this->stringObject->checkIsPassword()'type="password"':'type="text"').($this->size == ' style="width:100%;"' ' size="'.$this->size.'"').' maxlength="'.String::MAX_SIZE.'" name="'.$this->name.'" id="'.$this->name.'" value="'.((isset($_POST[$this->name]&& $this->stringObject->getValue(== "")$_POST[$this->name$this->stringObject->getValue()).'"'.($readOnly 'readonly class="readonly"' '').'/>';
  125.         }
  126.         
  127.         if($this->stringObject->getRule(!= ''{
  128.             $html .= '<input type="hidden" id="'.$this->name.'_msg" value="'.$this->stringObject->getHelper().'"/>';
  129.             $html .= '<input type="hidden" id="'.$this->name.'_rule" value="'.$this->stringObject->getRule().'"/>';
  130.         }
  131.         
  132.         return $html;
  133.     }
  134.     
  135.     /**
  136.      * Setter for string object
  137.      * 
  138.      * @param String $string 
  139.      * @since 1.0
  140.      * @throws IllegalArguementException
  141.      */
  142.     public function setStringObject($string{
  143.         if($string instanceof String)
  144.             $this->stringObject = $string;
  145.         else
  146.             throw new IllegalArguementException('String object passed ['.var_export($stringtrue).'] is not a valid String object!');
  147.     }
  148.  
  149.     /**
  150.      * Qetter for string object
  151.      * 
  152.      * @return String 
  153.      * @since 1.0
  154.      */
  155.     public function getStringObject({
  156.         return $this->stringObject;
  157.     }
  158. }
  159.  
  160. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:52 +0000 by phpDocumentor 1.4.3