Source for file WizardComponentWithChildren.abstract.php

Documentation is available at WizardComponentWithChildren.abstract.php

  1. <?php
  2. /**
  3. * @since Jul 19, 2005
  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: WizardComponentWithChildren.abstract.php,v 1.13 2007/09/19 14:04:50 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Wizard/WizardComponent.abstract.php");
  13.  
  14. /**
  15. * This is an abstract class that defines a {@link WizardComponent} that can have children.
  16. *
  17. * @since Jul 19, 2005
  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: WizardComponentWithChildren.abstract.php,v 1.13 2007/09/19 14:04:50 adamfranco Exp $
  24. * @abstract
  25. */
  26. abstract class WizardComponentWithChildren
  27. extends WizardComponent
  28. {
  29.  
  30. var $_children = array();
  31. /**
  32. * Adds a {@link WizardComponent} to this component. It will return the newly added component.
  33. * @param string $name The short-string name of the component - this is used for creating form input field names and storing data.
  34. * @param ref object $component A {@link WizardComponent} to add.
  35. * @access public
  36. * @return ref object
  37. */
  38. function addComponent ($name, $component) {
  39. ArgumentValidator::validate($name,
  40. NonZeroLengthStringValidatorRule::getRule());
  41. ArgumentValidator::validate($component,
  42. ExtendsValidatorRule::getRule('WizardComponent'));
  43. $this->_children[preg_replace("/[^a-zA-Z0-9:_-]/", "_", $name)] =$component;
  44. $component->setParent($this);
  45. return $component;
  46. }
  47. /**
  48. * Returns an array of all the children of this component, keyed by name.
  49. * @access public
  50. * @return ref array
  51. */
  52. function getChildren () {
  53. return $this->_children;
  54. }
  55. /**
  56. * Returns the component specified by $name.
  57. * @param string $name
  58. * @access public
  59. * @return ref object
  60. */
  61. function getChild ($name) {
  62. return $this->_children[preg_replace("/[^a-zA-Z0-9:_-]/", "_", $name)];
  63. }
  64. /**
  65. * Removes the specified child from this component.
  66. * @param string $name
  67. * @access public
  68. * @return void
  69. */
  70. function removeChild ($name) {
  71. unset($this->_children[preg_replace("/[^a-zA-Z0-9:_-]/", "_", $name)]);
  72. }
  73. /**
  74. * Returns true if this component (and all child components if applicable) have valid values.
  75. * By default, this will just return TRUE.
  76. * @access public
  77. * @return boolean
  78. */
  79. function validate () {
  80. $children =$this->getChildren();
  81. $ok = true;
  82. foreach (array_keys($children) as $key) {
  83. if (!$children[$key]->validate()) return false;
  84. }
  85. return true;
  86. }
  87. /**
  88. * Tells the wizard component to update itself - this may include getting
  89. * form post data or validation - whatever this particular component wants to
  90. * do every pageload.
  91. * @param string $fieldName The field name to use when outputting form data or
  92. * similar parameters/information.
  93. * @access public
  94. * @return boolean - TRUE if everything is OK
  95. * @since Jul 21, 2006
  96. */
  97. function update ($fieldName) {
  98. $children =$this->getChildren();
  99. $ok = true;
  100. foreach (array_keys($children) as $key) {
  101. if (!$children[$key]->update($fieldName."_".$key)) {
  102. $ok = false;
  103. }
  104. }
  105. return $ok;
  106. }
  107. /**
  108. * Returns the values of wizard-components. Should return an array if children are involved,
  109. * otherwise a whatever type of object is expected.
  110. * @access public
  111. * @return mixed
  112. */
  113. function getAllValues () {
  114. $array = array();
  115. $children =$this->getChildren();
  116. foreach(array_keys($children) as $key) {
  117. $array[$key] = $children[$key]->getAllValues();
  118. }
  119. return $array;
  120. }
  121. /**
  122. * Sets if this component will be enabled or disabled.
  123. * @param boolean $enabled
  124. * @param boolean $sticky If true, future calls to setEnabled without sticky
  125. * will have no effect.
  126. * @access public
  127. * @return void
  128. */
  129. function setEnabled ($enabled, $sticky = false) {
  130. parent::setEnabled($enabled, $sticky);
  131. $children =$this->getChildren();
  132. foreach(array_keys($children) as $key) {
  133. $children[$key]->setEnabled($enabled, $sticky);
  134. }
  135. }
  136. }
  137.  
  138.  
  139. ?>

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