1: <?php
2: /**
3: * Pry Framework
4: *
5: * LICENSE
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: *
10: * @version $Revision: 276 $
11: */
12:
13: /**
14: * Element numeric stepper
15: * @category Pry
16: * @package Form
17: * @subpackage Form_Element
18: * @version 1.1.0
19: * @author Olivier ROGER <oroger.fr>
20: */
21: class Form_Element_NumericStepper extends Form_Element_Text
22: {
23: /**
24: * Valeur maxi autorisée
25: *
26: * @var mixed
27: * @access private
28: */
29: private $max;
30:
31: /**
32: * Valeur mini autorisée
33: *
34: * @var mixed
35: * @access private
36: */
37: private $min;
38:
39: /**
40: * Valeur de pas
41: *
42: * @var mixed
43: * @access public
44: */
45: private $step;
46:
47: /**
48: * Valeur de départ
49: *
50: * @var mixed
51: * @access private
52: */
53: private $start;
54:
55: /**
56: * Chemin vers le sprite contenant les boutons
57: * @var string
58: */
59: private $sprite;
60:
61: /**
62: * Constructeur. Initialise les valeurs par défaut
63: *
64: * @param string $nom
65: * @param Form_Form $form
66: */
67: public function __construct($nom,$form)
68: {
69: parent::__construct($nom,$form);
70: $this->max = 99;
71: $this->min = 0;
72: $this->step = 1;
73: $this->start = 0;
74: $this->sprite = 'spinbox-sprite.png';
75: $this->container = '';
76: $this->value = $this->start;
77: }
78:
79: /**
80: * Défini la valeur max
81: *
82: * @param mixed $value
83: * @access public
84: * @return Form_Element_NumericStepper
85: */
86: public function setMax($value)
87: {
88: $this->max = $value;
89: return $this;
90: }
91:
92: /**
93: * Défini la valeur mini
94: *
95: * @param mixed $value
96: * @access public
97: * @return Form_Element_NumericStepper
98: */
99: public function setMin($value)
100: {
101: $this->min = $value;
102: return $this;
103: }
104:
105: /**
106: * Défini la valeur de pas
107: *
108: * @param mixed $value
109: * @access public
110: * @return Form_Element_NumericStepper
111: */
112: public function setStep($value)
113: {
114: $this->step = $value;
115: return $this;
116: }
117:
118: /**
119: * Défini la valeur de départ
120: *
121: * @param mixed $value
122: * @access public
123: * @return Form_Element_NumericStepper
124: */
125: public function startAt($value)
126: {
127: $this->startAt($value);
128: $this->value($value);
129: return $this;
130: }
131:
132: /**
133: * Défini le chemin des images des boutons.
134: * Chemins relatifs à la page web
135: *
136: * @param string $up
137: * @param string $down
138: * @access public
139: * @return Form_Element_NumericStepper
140: */
141: public function setSprite($path)
142: {
143: $this->sprite = $path;
144: return $this;
145: }
146:
147: /**
148: * Valide la donnée recue
149: *
150: * @param mixed $value
151: * @access public
152: * @return boolean
153: */
154: public function isValid($value)
155: {
156: if(parent::isValid($value))
157: {
158: if(!is_numeric($value))
159: {
160: $this->errorMsg = Form_Error::NUMERIC;
161: return false;
162: }
163: }
164: return true;
165: }
166:
167: /**
168: * Ecrit l'objet
169: *
170: * @access public
171: * @return string
172: */
173: public function __toString()
174: {
175: //$this->check();
176: $field = '';
177: $field.= parent::__toString();
178: $this->form->javascript .= '$("#'.$this->attrs['id'].'").spinbox({min:'.$this->min.',max:'.$this->max.',step:'.$this->step.'});';
179: return $field;
180: }
181: }
182: ?>