Source for file WSaveWithChoiceButtonList.class.php

Documentation is available at WSaveWithChoiceButtonList.class.php

  1. <?php
  2. /**
  3. * @since 6/7/07
  4. * @package polyphony.wizard.components
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WSaveWithChoiceButtonList.class.php,v 1.3 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY.'/main/library/Wizard/WizardComponent.abstract.php');
  13.  
  14. /**
  15. * The WSaveWithChoiceButtonList provides a set of multiple elements similar
  16. * to the WRadioList, but triggers a save action when one of the buttons is pressed.
  17. * The value of that button is then entered as the value of the list, providing
  18. * easy determination of which button was pressed by the client code.
  19. *
  20. * @since 6/7/07
  21. * @package polyphony.wizard.components
  22. *
  23. * @copyright Copyright &copy; 2005, Middlebury College
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  25. *
  26. * @version $Id: WSaveWithChoiceButtonList.class.php,v 1.3 2007/09/19 14:04:51 adamfranco Exp $
  27. */
  28. class WSaveWithChoiceButtonList
  29. extends WizardComponent
  30. {
  31. var $_eachPre;
  32. var $_eachPost;
  33. var $_pre;
  34. var $_post;
  35. var $_value;
  36. var $_onchange;
  37. var $_style = null;
  38. var $_items = array();
  39. var $_extendedHtml = array();
  40. var $_event = "edu.middlebury.polyphony.wizard.save";
  41. /**
  42. * Virtual constructor - creates this object with the specified layout.
  43. * @param string $pre A string to prepend onto the markup block (ex, "<ul>")
  44. * @param string $eachPre A string to put at the beginning of each of the
  45. * elements (ex, "<li>")
  46. * @param string $eachPost A string to put at the end of each of the
  47. * elements (ex, "</li>")
  48. * @param string $post A string to tack onto the end of the block (ex, "</ul>")
  49. * @access public
  50. * @return ref object
  51. * @static
  52. */
  53. function withLayout ($pre, $eachPre, $eachPost, $post, $class='WSaveWithChoiceButtonList') {
  54. $obj = new $class();
  55. $obj->_pre = $pre;
  56. $obj->_post = $post;
  57. $obj->_eachPre = $eachPre;
  58. $obj->_eachPost = $eachPost;
  59. return $obj;
  60. }
  61. /**
  62. * Constructor
  63. * @access public
  64. * @return WRadioList
  65. */
  66. function WSaveWithChoiceButtonList () {
  67. $this->_pre = $this->_post = '';
  68. $this->_eachPost = "\n<br/>";
  69. }
  70. /**
  71. * sets the CSS style for the labels of the radio buttons.
  72. * @param string $style
  73. * @access public
  74. * @return void
  75. */
  76. function setStyle ($style) {
  77. $this->_style = $style;
  78. }
  79. /**
  80. * Sets the value of this radio button group.
  81. * @param string $value
  82. * @access public
  83. * @return void
  84. */
  85. function setValue ($value) {
  86. $this->_value = $value;
  87. }
  88. /**
  89. * Add commands to the javascript onchange attribute.
  90. * @param string $commands
  91. * @access public
  92. * @return void
  93. */
  94. function addOnChange($commands) {
  95. $this->_onchange .= " ".$commands;
  96. }
  97. /**
  98. * Adds a radio option to this list.
  99. * @param string $value The short value that represents the displayed text.
  100. * @param optional string $displayText The text to show to the end user. Defaults to $value.
  101. * @param optional string $extendedHtml Text to add to the item after the display text.
  102. * @access public
  103. * @return void
  104. */
  105. function addOption ($value, $displayText = null, $extendedHtml = null) {
  106. if ($displayText == null) $displayText = $value;
  107. $this->_items[$value] = $displayText;
  108. $this->_extendedHtml[$value] = $extendedHtml;
  109. }
  110. /**
  111. * Tells the wizard component to update itself - this may include getting
  112. * form post data or validation - whatever this particular component wants to
  113. * do every pageload.
  114. * @param string $fieldName The field name to use when outputting form data or
  115. * similar parameters/information.
  116. * @access public
  117. * @return boolean - TRUE if everything is OK
  118. */
  119. function update ($fieldName) {
  120. reset($this->_items);
  121. for ($i = 0; $i < count($this->_items); $i++) {
  122. if (RequestContext::value($fieldName."__".$i)) {
  123. $this->_value = key($this->_items);
  124. // trigger the save event on the wizard
  125. $wizard =$this->getWizard();
  126. $wizard->triggerLater($this->_event, $wizard);
  127. return true;
  128. }
  129. // loop through the items in sync with the indexes.
  130. next($this->_items);
  131. }
  132. }
  133. /**
  134. * Returns the values of wizard-components. Should return an array if children are involved,
  135. * otherwise a whatever type of object is expected.
  136. * @access public
  137. * @return mixed
  138. */
  139. function getAllValues () {
  140. return $this->_value;
  141. }
  142. /**
  143. * Returns a block of XHTML-valid code that contains markup for this specific
  144. * component.
  145. * @param string $fieldName The field name to use when outputting form data or
  146. * similar parameters/information.
  147. * @access public
  148. * @return string
  149. */
  150. function getMarkup ($fieldName) {
  151. ob_start();
  152. print $this->_pre;
  153. $style = '';
  154. if ($this->_style) $style = " style=\"".addslashes($this->_style)."\"";
  155. $s = array();
  156.  
  157. foreach (array_keys($this->_items) as $i => $key) {
  158. print $this->_eachPre;
  159. $display = $this->_items[$key];
  160. $extendedHtml = $this->_extendedHtml[$key];
  161. $name = RequestContext::name($fieldName."__".$i);
  162. $javascript = '';
  163. if ($this->_onchange)
  164. $javascript = " ".str_replace("\"", "\\\"", $this->_onchange)."; ";
  165. print "<input type='submit' name='$name' value=\"$display\" onclick=\"$javascript\"/>";
  166. print $extendedHtml;
  167. print $this->_eachPost;
  168. }
  169. print $this->_post;
  170. return ob_get_clean();
  171. }
  172. }
  173.  
  174. ?>

Documentation generated on Wed, 19 Sep 2007 10:28:17 -0400 by phpDocumentor 1.3.0RC3