Source for file WizardAction.class.php

Documentation is available at WizardAction.class.php

  1. <?php
  2. /**
  3. * @since 4/28/05
  4. * @package polyphony.AbstractActions
  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: WizardAction.class.php,v 1.15 2007/09/19 14:04:41 adamfranco Exp $
  10. */
  11. require_once(dirname(__FILE__)."/Action.class.php");
  12.  
  13. /**
  14. * This class is an abstract class that provides a structure for building actions
  15. * that contain Wizards. Decendent actions are not required to contain Wizards,
  16. * though if they do, they should implement the following methods:
  17. * - {@link saveWizard()}
  18. * - {@link createWizard()}
  19. * - {@link getReturnUrl()}
  20. *
  21. * To run the entire wizard execution sequence, only {@link runWizard()} needs
  22. * to be called. Example:
  23. * <code>
  24. * <?php
  25. * ...
  26. *
  27. * &#109;**
  28. * * Build the content for this action
  29. * *
  30. * * @return boolean
  31. * * @access public
  32. * * @since 4/26/05
  33. * *&#109;
  34. * function buildContent () {
  35. * $centerPane =$this->getCenterPane();
  36. * $assetId =$this->getAssetId();
  37. * $cacheName = 'edit_asset_wizard_'.$assetId->getIdString();
  38. *
  39. * $this->runWizard ( $cacheName, $centerPane );
  40. * }
  41. *
  42. * ...
  43. * ?>
  44. * </code>
  45. *
  46. * @since 4/28/05
  47. * @package polyphony.AbstractActions
  48. *
  49. * @copyright Copyright &copy; 2005, Middlebury College
  50. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  51. *
  52. * @version $Id: WizardAction.class.php,v 1.15 2007/09/19 14:04:41 adamfranco Exp $
  53. */
  54. class WizardAction
  55. extends Action
  56. {
  57. /**
  58. * Create a new Wizard for this action. Caching of this Wizard is handled by
  59. * {@link getWizard()} and does not need to be implemented here.
  60. *
  61. * @return object Wizard
  62. * @access public
  63. * @since 4/28/05
  64. */
  65. function createWizard () {
  66. throwError(new Error(__CLASS__."::".__FUNCTION__."() must be overridded in child classes."));
  67. }
  68. /**
  69. * Save our results. Tearing down and unsetting the Wizard is handled by
  70. * in {@link runWizard()} and does not need to be implemented here.
  71. *
  72. * @param string $cacheName
  73. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  74. * Wizard should ensue.
  75. * @access public
  76. * @since 4/28/05
  77. */
  78. function saveWizard ( $cacheName ) {
  79. throwError(new Error(__CLASS__."::".__FUNCTION__."() must be overridded in child classes."));
  80. }
  81. /**
  82. * Return the URL that this action should return to when completed.
  83. *
  84. * @return string
  85. * @access public
  86. * @since 4/28/05
  87. */
  88. function getReturnUrl () {
  89. throwError(new Error(__CLASS__."::".__FUNCTION__."() must be overridded in child classes."));
  90. }
  91. /**
  92. * Cancel from this Wizard. This will tear down the wizard and return us
  93. * to our returnUrl as specified by {@link getReturnUrl()}.
  94. *
  95. * @param string $cacheName
  96. * @return void
  97. * @access public
  98. * @since 4/28/05
  99. */
  100. function cancelWizard ( $cacheName ) {
  101. $this->closeWizard($cacheName);
  102. RequestContext::sendTo($this->getReturnUrl());
  103. }
  104. /**
  105. * Close the Wizard. This will tear down the Wizard.
  106. *
  107. * @param string $cacheName
  108. * @return void
  109. * @access public
  110. * @since 4/28/05
  111. */
  112. function closeWizard ( $cacheName ) {
  113. $cacheName = $this->cleanCacheName($cacheName);
  114. $wizard =$this->getWizard($cacheName);
  115. $wizard = NULL;
  116. unset ($_SESSION[$cacheName]);
  117. unset ($wizard);
  118. }
  119. /**
  120. * Run this Action's wizard and add it to the specified container. Cache
  121. * this Action's wizard with the specified cacheName.
  122. *
  123. * This is the only method that an Action needs to call to run itself, see
  124. * {@link editAction::buildContent()} for an example:
  125. * <code>
  126. * <?php
  127. * ...
  128. *
  129. * &#109;**
  130. * * Build the content for this action
  131. *
  132. * * @return boolean
  133. * * @access public
  134. * * @since 4/26/05
  135. * *&#109;
  136. * function buildContent () {
  137. * $centerPane =$this->getCenterPane();
  138. * $assetId =$this->getAssetId();
  139. * $cacheName = 'edit_asset_wizard_'.$assetId->getIdString();
  140. *
  141. * $this->runWizard ( $cacheName, $centerPane );
  142. * }
  143. *
  144. * ...
  145. * ?>
  146. * </code>
  147. *
  148. * @param string $cacheName The name to cache this Action's Wizard with.
  149. * @param object Container $container The container to put the Wizard's layout in.
  150. * @return void
  151. * @access public
  152. * @since 4/28/05
  153. */
  154. function runWizard ( $cacheName, $container) {
  155. $cacheName = $this->cleanCacheName($cacheName);
  156. $wizard =$this->getWizard($cacheName);
  157. $harmoni = Harmoni::instance();
  158. // tell the wizard to GO
  159. $wizard->go();
  160. $listener =$wizard->getChild("_savecancel_");
  161. if ($listener->isSaveRequested()) {
  162. if ($this->saveWizard($cacheName))
  163. $this->cancelWizard($cacheName);
  164. }
  165. else if ($listener->isCancelRequested()) {
  166. $this->cancelWizard($cacheName);
  167. }
  168. if (isset($_SESSION[$cacheName])) {
  169. $container->add($wizard->getLayout($harmoni), null, null, CENTER, TOP);
  170. }
  171. }
  172. /**
  173. * Build and/or return our Wizard. Handle caching of it in the SESSION under
  174. * the specified name.
  175. *
  176. * @param string $cacheName
  177. * @return object Wizard
  178. * @access public
  179. * @since 4/28/05
  180. */
  181. function getWizard ( $cacheName ) {
  182. $cacheName = $this->cleanCacheName($cacheName);
  183. // Create the wizard if it doesn't exist.
  184. if (!isset($_SESSION[$cacheName])) {
  185. $wizard =$this->createWizard();
  186. $wizard->addComponent("_savecancel_", new WSaveCancelListener());
  187. $wizard->setIdString($cacheName);
  188. $_SESSION[$cacheName] =$wizard;
  189. }
  190. return $_SESSION[$cacheName];
  191. }
  192. /**
  193. * Clean the cacheName
  194. *
  195. * @param string $cacheName
  196. * @return string
  197. * @access public
  198. * @since 9/28/06
  199. */
  200. function cleanCacheName ($cacheName) {
  201. // The browser will translate '.'s into '_'s, resulting in a miss-match,
  202. // so swap these now.
  203. return str_replace(".", "_", $cacheName);
  204. }
  205. }
  206.  
  207. ?>

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