Image.php 3.0 KB

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