|
1 <?php |
|
2 /** |
|
3 * Zend 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 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
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 license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Form |
|
17 * @subpackage Element |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 */ |
|
21 |
|
22 /** Zend_Form_Element_Xhtml */ |
|
23 require_once 'Zend/Form/Element/Xhtml.php'; |
|
24 |
|
25 /** |
|
26 * Image form element |
|
27 * |
|
28 * @category Zend |
|
29 * @package Zend_Form |
|
30 * @subpackage Element |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 * @version $Id: Image.php 22328 2010-05-30 15:09:06Z bittarman $ |
|
34 */ |
|
35 class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml |
|
36 { |
|
37 /** |
|
38 * What view helper to use when using view helper decorator |
|
39 * @var string |
|
40 */ |
|
41 public $helper = 'formImage'; |
|
42 |
|
43 /** |
|
44 * Image source |
|
45 * @var string |
|
46 */ |
|
47 public $src; |
|
48 |
|
49 /** |
|
50 * Image value |
|
51 * @var mixed |
|
52 */ |
|
53 protected $_imageValue; |
|
54 |
|
55 /** |
|
56 * Load default decorators |
|
57 * |
|
58 * @return void |
|
59 */ |
|
60 public function loadDefaultDecorators() |
|
61 { |
|
62 if ($this->loadDefaultDecoratorsIsDisabled()) { |
|
63 return $this; |
|
64 } |
|
65 |
|
66 $decorators = $this->getDecorators(); |
|
67 if (empty($decorators)) { |
|
68 $this->addDecorator('Tooltip') |
|
69 ->addDecorator('Image') |
|
70 ->addDecorator('Errors') |
|
71 ->addDecorator('HtmlTag', array('tag' => 'dd')) |
|
72 ->addDecorator('Label', array('tag' => 'dt')); |
|
73 } |
|
74 return $this; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Set image path |
|
79 * |
|
80 * @param string $path |
|
81 * @return Zend_Form_Element_Image |
|
82 */ |
|
83 public function setImage($path) |
|
84 { |
|
85 $this->src = (string) $path; |
|
86 return $this; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Get image path |
|
91 * |
|
92 * @return string |
|
93 */ |
|
94 public function getImage() |
|
95 { |
|
96 return $this->src; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Set image value to use when submitted |
|
101 * |
|
102 * @param mixed $value |
|
103 * @return Zend_Form_Element_Image |
|
104 */ |
|
105 public function setImageValue($value) |
|
106 { |
|
107 $this->_imageValue = $value; |
|
108 return $this; |
|
109 } |
|
110 |
|
111 /** |
|
112 * Get image value to use when submitted |
|
113 * |
|
114 * @return mixed |
|
115 */ |
|
116 public function getImageValue() |
|
117 { |
|
118 return $this->_imageValue; |
|
119 } |
|
120 |
|
121 /** |
|
122 * Was this element used to submit the form? |
|
123 * |
|
124 * @return bool |
|
125 */ |
|
126 public function isChecked() |
|
127 { |
|
128 $imageValue = $this->getImageValue(); |
|
129 return ((null !== $imageValue) && ($this->getValue() == $imageValue)); |
|
130 } |
|
131 |
|
132 } |