2013-07-16 15:39:47 +02:00
|
|
|
|
<?php
|
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Web\Form\Element;
|
|
|
|
|
|
2014-09-02 16:48:54 +02:00
|
|
|
|
use Zend_Form_Element;
|
2014-04-16 16:41:23 +02:00
|
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
|
/**
|
2014-09-02 16:48:54 +02:00
|
|
|
|
* A number input control
|
2013-07-16 15:39:47 +02:00
|
|
|
|
*/
|
2014-09-02 16:48:54 +02:00
|
|
|
|
class Number extends Zend_Form_Element
|
2013-07-16 15:39:47 +02:00
|
|
|
|
{
|
|
|
|
|
/**
|
2014-09-02 16:48:54 +02:00
|
|
|
|
* Disable default decorators
|
2014-04-16 16:41:23 +02:00
|
|
|
|
*
|
2014-09-02 16:48:54 +02:00
|
|
|
|
* \Icinga\Web\Form sets default decorators for elements.
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*
|
|
|
|
|
* @see \Icinga\Web\Form::__construct() For default element decorators.
|
2013-07-16 15:39:47 +02:00
|
|
|
|
*/
|
2014-09-02 16:48:54 +02:00
|
|
|
|
protected $_disableLoadDefaultDecorators = true;
|
2014-04-16 16:41:23 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2014-09-02 16:48:54 +02:00
|
|
|
|
* Form view helper to use for rendering
|
2014-04-16 16:41:23 +02:00
|
|
|
|
*
|
2014-09-02 16:48:54 +02:00
|
|
|
|
* @var string
|
2014-04-16 16:41:23 +02:00
|
|
|
|
*/
|
2014-09-02 16:48:54 +02:00
|
|
|
|
public $helper = 'formNumber';
|
2014-04-16 16:41:23 +02:00
|
|
|
|
|
2014-09-03 14:39:42 +02:00
|
|
|
|
/**
|
|
|
|
|
* The expected lower bound for the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @var float|null
|
|
|
|
|
*/
|
|
|
|
|
protected $min;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The expected upper bound for the element’s
|
|
|
|
|
*
|
|
|
|
|
* @var float|null
|
|
|
|
|
*/
|
|
|
|
|
protected $max;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The value granularity of the element’s value
|
|
|
|
|
*
|
|
|
|
|
* Normally, number input controls are limited to an accuracy of integer values.
|
|
|
|
|
*
|
|
|
|
|
* @var float|string|null
|
|
|
|
|
*/
|
|
|
|
|
protected $step;
|
|
|
|
|
|
2014-09-02 16:48:54 +02:00
|
|
|
|
/**
|
|
|
|
|
* (non-PHPDoc)
|
|
|
|
|
* @see \Zend_Form_Element::init() For the method documentation.
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
2014-09-03 14:39:42 +02:00
|
|
|
|
$this->addValidator('Float', true); // true for breaking the validator chain on failure
|
|
|
|
|
if ($this->min !== null) {
|
|
|
|
|
$this->addValidator('GreaterThan', true, array('min' => $this->min));
|
|
|
|
|
}
|
|
|
|
|
if ($this->max !== null) {
|
|
|
|
|
$this->addValidator('LessThan', true, array('max' => $this->max));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the expected lower bound for the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @param float $min
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setMin($min)
|
|
|
|
|
{
|
|
|
|
|
$this->min = (float) $min;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the expected lower bound for the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @return float|null
|
|
|
|
|
*/
|
|
|
|
|
public function getMin()
|
|
|
|
|
{
|
|
|
|
|
return $this->min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the expected upper bound for the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @param float $max
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setMax($max)
|
|
|
|
|
{
|
|
|
|
|
$this->max = (int) $max;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the expected upper bound for the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @return float|null
|
|
|
|
|
*/
|
|
|
|
|
public function getMax()
|
|
|
|
|
{
|
|
|
|
|
return $this->max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the value granularity of the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @param float|string $step
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setStep($step)
|
|
|
|
|
{
|
|
|
|
|
if ($step !== 'any') {
|
|
|
|
|
$step = (float) $step;
|
|
|
|
|
}
|
|
|
|
|
$this->step = $step;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the value granularity of the element’s value
|
|
|
|
|
*
|
|
|
|
|
* @return float|string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getStep()
|
|
|
|
|
{
|
|
|
|
|
return $this->step;
|
2014-04-16 16:41:23 +02:00
|
|
|
|
}
|
2013-07-16 15:39:47 +02:00
|
|
|
|
}
|