Source for file WLogicStepContainer.class.php

Documentation is available at WLogicStepContainer.class.php

  1. <?php
  2. /**
  3. * @since 5/31/06
  4. * @package polyphony.wizard
  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: WLogicStepContainer.class.php,v 1.7 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Wizard/Components/WizardStepContainer.class.php");
  13.  
  14. /**
  15. * StepContainer that add steps to its stack as the wizard goes along
  16. *
  17. * @since 5/31/06
  18. * @package polyphony.wizard
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: WLogicStepContainer.class.php,v 1.7 2007/09/19 14:04:51 adamfranco Exp $
  24. */
  25. class WLogicStepContainer extends WizardStepContainer {
  26. var $_stepStack;
  27. var $_backNamesStack;
  28. var $_backStepsStack;
  29. var $_forwardNamesStack;
  30. var $_forwardStepsStack;
  31. /**
  32. * Constructor
  33. *
  34. * @return void
  35. * @access public
  36. * @since 5/31/06
  37. */
  38. function WLogicStepContainer () {
  39. parent::WizardStepContainer();
  40. $this->_currStep = null;
  41. $this->_stepStack = array();
  42. $this->_backNamesStack = array();
  43. $this->_backStepsStack = array();
  44. $this->_forwardNamesStack = array();
  45. $this->_forwardStepsStack = array();
  46. }
  47. /**
  48. * tells the wizard component to update itself... via the current step.
  49. *
  50. * @param string $fieldName
  51. * @return boolean
  52. * @access public
  53. * @since 5/31/06
  54. */
  55. function update ($fieldName) {
  56. return $this->_steps[$this->_currStep]->update($fieldName."_".
  57. $this->_stepNames[$this->_currStep]);
  58. }
  59. /**
  60. * Set the steps for this step container. Remove forward and backward capability.
  61. *
  62. * @access public
  63. * @param array $arrayOfSteps
  64. * $return void
  65. */
  66. function setRequiredSteps($arrayOfSteps) {
  67. //steps are listed backwards in a stack.
  68. $this->_stepStack = array_reverse($arrayOfSteps);
  69. $this->nextStep();
  70.  
  71. //clear forward and back
  72. $this->_backNamesStack = array();
  73. $this->_backStepsStack = array();
  74. $this->_forwardNamesStack = array();
  75. $this->_forwardStepsStack = array();
  76. }
  77.  
  78. /**
  79. * Goes to the next step, if possible, by popping the next step off the stack.
  80. * @param ref object WLogicButton $button that has logic attached
  81. * @access public
  82. * @return void
  83. */
  84. function nextStep ($button=null) {
  85. //add this step to the back stacks
  86. if(!is_null($this->_currStep)){
  87. array_push($this->_backNamesStack,$this->getCurrentStepName());
  88. array_push($this->_backStepsStack,array_values($this->_stepStack));
  89. }
  90. //clear the forward stacks
  91. $this->_forwardNamesStack = array();
  92. $this->_forwardStepsStack = array();
  93.  
  94. //if there is a WLogicButton passed in, add the appropriate steps
  95. if(func_num_args()>0){
  96. $controller =$button->getLogicRule();
  97. $this->pushSteps($controller->getRequiredSteps());
  98. }
  99. $nextStep = array_pop($this->_stepStack);
  100. $this->setStep($nextStep);
  101. }
  102. /**
  103. * Go backward in the history, if possible.
  104. * @access public
  105. * @return void
  106. */
  107. function goBack() {
  108. //aren't stacks awesome? This code is so awesome, I'll add my name--Tim
  109. //add the current step to back in case we need to return to it
  110. array_push($this->_forwardNamesStack,$this->getCurrentStepName());
  111. array_push($this->_forwardStepsStack,array_values($this->_stepStack));
  112. //remove and save the values from the back stacks
  113. $nextStep = array_pop($this->_backNamesStack);
  114. $nextStack = array_values(array_pop($this->_backStepsStack));
  115. //change to the right step
  116. $this->setStep($nextStep);
  117. $this->_stepStack = $nextStack;
  118. }
  119. /**
  120. * Go forward in the history, if possible.
  121. * @access public
  122. * @return void
  123. */
  124. function goForward() {
  125. //aren't stacks awesome? This code is so awesome, I'll my name--Tim
  126. //add the current step to forward in case we need to return to it
  127. array_push($this->_backNamesStack,$this->getCurrentStepName());
  128. array_push($this->_backStepsStack,array_values($this->_stepStack));
  129. //remove and save the values from the forward stacks
  130. $nextStep = array_pop($this->_forwardNamesStack);
  131. $nextStack = array_values(array_pop($this->_forwardStepsStack));
  132. //change to the right step
  133. $this->setStep($nextStep);
  134. $this->_stepStack = $nextStack;
  135. }
  136. /**
  137. * Returns if this StepContainer has a next forward step.
  138. * @access public
  139. * @return boolean
  140. */
  141. function canGoForward () {
  142. return (count($this->_forwardNamesStack) > 0);
  143. }
  144. /**
  145. * Returns if this StepContainer has a next forward step.
  146. * @access public
  147. * @return boolean
  148. */
  149. function canGoBack () {
  150. return (count($this->_backNamesStack) > 0);
  151. }
  152. function previousStep () {
  153. // do nothing, can't go back in logic wizard
  154. throwError(new Error("A (logic) Wizard nevers goes back on his word! (or his steps)","WLogicStepContainer",true));
  155. }
  156. /**
  157. * Returns if this StepContainer has a next step.
  158. * @access public
  159. * @return boolean
  160. */
  161. function hasNext () {
  162. return (count($this->_stepStack) > 0)?true:false;
  163. }
  164. function hasPrevious () {
  165. // do nothing, can't go back in logic wizard
  166. throwError(new Error("A (logic) Wizard nevers goes back on his word! (or his steps)","WLogicStepContainer",true));
  167. }
  168. /**
  169. * Returns true if this component (and all child components if applicable) have valid values.
  170. * By default, this will just return TRUE.
  171. *
  172. * @access public
  173. * @return boolean
  174. */
  175. function validate () {
  176. $step =$this->_steps[$this->_currStep];
  177. return $step->validate();
  178. }
  179. /**
  180. * adds the passed steps to the current step stack if they are not there
  181. *
  182. * @param array $steps
  183. * @return void
  184. * @access public
  185. * @since 5/31/06
  186. */
  187. function pushSteps ($steps) {
  188. $steps = array_reverse($steps);
  189. foreach ($steps as $step){
  190. array_push($this->_stepStack, $step);
  191. }
  192. }
  193. }
  194.  
  195. ?>

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