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

Source for file function.pnformfloatinput.php

Documentation is available at function.pnformfloatinput.php

  1. <?php
  2. /**
  3.  * Float input plugin
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnformfloatinput.php 24425 2008-07-02 12:13:57Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Jorn Wildt
  10.  * @package Zikula_Template_Plugins
  11.  * @subpackage Functions
  12.  */
  13.  
  14. /** Make sure to use require_once() instead of Loader::requireOnce() since "function.pnformtextinput.php"
  15.  is loaded by Smarty (the base render class) with the use of require_once(). We do not want to
  16.  get in conflict with that.*/
  17. require_once 'system/pnForm/plugins/function.pnformtextinput.php';
  18.  
  19. /**
  20.  * Floating value input
  21.  *
  22.  * Use for text inputs where you only want to accept floats. The value saved by
  23.  * {@link pnForm::pnFormGetValues()} is either null or a valid float.
  24.  *
  25.  * @package pnForm
  26.  * @subpackage Plugins
  27.  */
  28. {
  29.     /**
  30.      * Minimum value for validation
  31.      * @var float 
  32.      */
  33.     var $minValue;
  34.  
  35.     /**
  36.      * Maximum value for validation
  37.      * @var float 
  38.      */
  39.     var $maxValue;
  40.  
  41.  
  42.     function getFilename()
  43.     {
  44.         return __FILE__// FIXME: may be found in smarty's data???
  45.     }
  46.  
  47.  
  48.     function create(&$render&$params)
  49.     {
  50.         $this->maxLength 30;
  51.         $params['width''6em';
  52.         parent::create($render$params);
  53.     }
  54.  
  55.  
  56.     function validate(&$render)
  57.     {
  58.         parent::validate($render);
  59.         if (!$this->isValid)
  60.             return;
  61.  
  62.         if ($this->text != '')
  63.         {
  64.             if (!is_numeric($this->text))
  65.                 $this->setError(_NOTAVALIDNUMBER);
  66.  
  67.             $i = (float)$this->text;
  68.             if (   $this->minValue != null  &&  $i $this->minValue 
  69.                 || $this->maxValue != null  &&  $i $this->maxValue )
  70.             {
  71.                 if ($this->minValue != null  &&  $this->maxValue != null)
  72.                     $this->setError(_PNFORM_RANGEERROR " [$this->minValue,$this->maxValue]");
  73.                 else if ($this->minValue != null)
  74.                     $this->setError(pnML('_PNFORM_RANGEMINERROR'array('i' => $this->minValue)));
  75.                 else if ($this->maxValue != null)
  76.                     $this->setError(pnML('_PNFORM_RANGEMAXERROR'array('i' => $this->maxValue)));
  77.             }
  78.         }
  79.     }
  80.  
  81.  
  82.     function parseValue(&$render$text)
  83.     {
  84.         if ($text == '')
  85.             return null;
  86.         return (float)$text;
  87.     }
  88. }
  89.  
  90.  
  91. function smarty_function_pnformfloatinput($params&$render)
  92. {
  93.     return $render->pnFormRegisterPlugin('pnFormFloatInput'$params);
  94. }

Documentation generated on Fri, 18 Jul 2008 21:45:52 +0200 by phpDocumentor 1.4.1