static.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * HTML class for static data
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Wojciech Gdela <eltehaem@poczta.onet.pl>
  17. * @copyright 2001-2009 The PHP Group
  18. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  19. * @version CVS: $Id: static.php,v 1.8 2009/04/04 21:34:04 avb Exp $
  20. * @link http://pear.php.net/package/HTML_QuickForm
  21. */
  22. /**
  23. * HTML class for static data
  24. *
  25. * @category HTML
  26. * @package HTML_QuickForm
  27. * @author Wojciech Gdela <eltehaem@poczta.onet.pl>
  28. * @version Release: 3.2.11
  29. * @since 2.7
  30. */
  31. class HTML_QuickForm_static extends HTML_QuickForm_element
  32. {
  33. // {{{ properties
  34. /**
  35. * Display text
  36. * @var string
  37. * @access private
  38. */
  39. var $_text = null;
  40. // }}}
  41. // {{{ constructor
  42. /**
  43. * Class constructor
  44. *
  45. * @param string $elementLabel (optional)Label
  46. * @param string $text (optional)Display text
  47. * @access public
  48. * @return void
  49. */
  50. public function __construct($elementName = null, $elementLabel = null, $text = null, $attributes = null)
  51. {
  52. parent::__construct($elementName, $elementLabel, $attributes);
  53. $this->_persistantFreeze = false;
  54. $this->_type = 'static';
  55. $this->_text = $text;
  56. } //end constructor
  57. // }}}
  58. // {{{ setName()
  59. /**
  60. * Sets the element name
  61. *
  62. * @param string $name Element name
  63. * @access public
  64. * @return void
  65. */
  66. function setName($name)
  67. {
  68. $this->updateAttributes(array('name'=>$name));
  69. } //end func setName
  70. // }}}
  71. // {{{ getName()
  72. /**
  73. * Returns the element name
  74. *
  75. * @access public
  76. * @return string
  77. */
  78. function getName()
  79. {
  80. return $this->getAttribute('name');
  81. } //end func getName
  82. // }}}
  83. // {{{ setText()
  84. /**
  85. * Sets the text
  86. *
  87. * @param string $text
  88. * @access public
  89. * @return void
  90. */
  91. function setText($text)
  92. {
  93. $this->_text = $text;
  94. } // end func setText
  95. // }}}
  96. // {{{ setValue()
  97. /**
  98. * Sets the text (uses the standard setValue call to emulate a form element.
  99. *
  100. * @param string $text
  101. * @access public
  102. * @return void
  103. */
  104. function setValue($text)
  105. {
  106. $this->setText($text);
  107. } // end func setValue
  108. // }}}
  109. // {{{ toHtml()
  110. /**
  111. * Returns the static text element in HTML
  112. *
  113. * @access public
  114. * @return string
  115. */
  116. public function toHtml()
  117. {
  118. return $this->_getTabs() . $this->_text;
  119. } //end func toHtml
  120. // }}}
  121. // {{{ getFrozenHtml()
  122. /**
  123. * Returns the value of field without HTML tags
  124. *
  125. * @access public
  126. * @return string
  127. */
  128. function getFrozenHtml()
  129. {
  130. return $this->toHtml();
  131. } //end func getFrozenHtml
  132. // }}}
  133. // {{{ onQuickFormEvent()
  134. /**
  135. * Called by HTML_QuickForm whenever form event is made on this element
  136. *
  137. * @param string $event Name of event
  138. * @param mixed $arg event arguments
  139. * @param object &$caller calling object
  140. * @since 1.0
  141. * @access public
  142. * @return void
  143. * @throws
  144. */
  145. function onQuickFormEvent($event, $arg, &$caller)
  146. {
  147. switch ($event) {
  148. case 'updateValue':
  149. // do NOT use submitted values for static elements
  150. $value = $this->_findValue($caller->_constantValues);
  151. if (null === $value) {
  152. $value = $this->_findValue($caller->_defaultValues);
  153. }
  154. if (null !== $value) {
  155. $this->setValue($value);
  156. }
  157. break;
  158. default:
  159. parent::onQuickFormEvent($event, $arg, $caller);
  160. }
  161. return true;
  162. } // end func onQuickFormEvent
  163. // }}}
  164. // {{{ exportValue()
  165. /**
  166. * We override this here because we don't want any values from static elements
  167. */
  168. function exportValue(&$submitValues, $assoc = false)
  169. {
  170. return null;
  171. }
  172. }