Source for file WGUIComponent.abstract.php

Documentation is available at WGUIComponent.abstract.php

  1. <?php
  2. /**
  3. * @since 8/14/2006
  4. * @package polyphony.guiwizardcomponents
  5. *
  6. * @copyright Copyright &copy; 2006, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WGUIComponent.abstract.php,v 1.3 2007/09/19 14:04:45 adamfranco Exp $
  10. */
  11.  
  12.  
  13.  
  14. /**
  15. * This class is an abstract class for associating StyleComponents with a wizard component.
  16. *
  17. * @since 8/14/2006
  18. * @package polyphony.guiwizardcomponents
  19. *
  20. * @copyright Copyright &copy; 2006, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: WGUIComponent.abstract.php,v 1.3 2007/09/19 14:04:45 adamfranco Exp $
  24. */
  25. class WGUIComponent
  26. extends WizardComponent
  27. {
  28.  
  29. var $_wizardComponent;
  30. var $_getThemeCallBack;
  31. var $_collection;
  32. var $_property;
  33. var $_component;
  34. /**
  35. *The default value passed in with the StyleProperty
  36. */
  37. var $_defValue;
  38.  
  39. /**
  40. * Initialize all the variables. Should be called last in the constructor.
  41. * Requires that the collection and theme are created
  42. */
  43. function init ($callBack, $collectionSelector, $styleProperty, $componentClass) {
  44. //set various variables
  45. $this->_getThemeCallBack = $callBack;
  46. $this->_collection = $collectionSelector;
  47. $this->_property = $styleProperty->getName();
  48. $this->_component = $componentClass;
  49. //get the colelction
  50. $collection =$this->getStyleCollection();
  51. //get the property, using the default one, if need be. Then check to make sure we've succeeded.
  52. $property =$collection->getStyleProperty($this->_property);
  53. if(is_null($property)){
  54. $collection->addSP($styleProperty);
  55. $property =$styleProperty;
  56. }
  57. $rule = ExtendsValidatorRule::getRule("StyleProperty");
  58. if(!$rule->check($property)){
  59. throwError(new Error("Failed to get StyleProperty","GUIWizardComponents",true));
  60. }
  61. //get the first value in case the next value is not legitamate
  62. $componentTemp =$styleProperty->getStyleComponent($componentClass);
  63. $rule = ExtendsValidatorRule::getRule("StyleComponent");
  64. if(!$rule->check($componentTemp)){
  65. throwError(new Error("Passed in Style property must have a component of given class, '".$componentClass."'","GUIWizardComponents",true));
  66. }
  67. $this->_defaultValue = $componentTemp->getValue();
  68. if(!$this->isPossibleValue($this->_defaultValue)){
  69. throwError(new Error("Passed in StyleComponent must have an acceptable value for the WizardComponent.","GUIWizardComponents",true));
  70. }
  71. //get the component, using the default one, if need be. Then check to make sure we've succeeded.
  72. $component =$property->getStyleComponent($this->_component);
  73. if(is_null($component)){
  74. $property->addSC($styleProperty->getStyleProperty($componentClass));
  75. }
  76. $this->importValue();
  77. }
  78. function useDefaultValue(){
  79. $this->_wizardComponent->setValue($this->_defValue);
  80. //@todo this actually could destroy styles made elsewhere. Of course if we don't update immeadiately, the next pageload will probably update anyway. Is there a good way to fix this?
  81. $this->exportValue();
  82. }
  83. function getStyleComponent(){
  84. //eval('$theme = '.$this->_getThemeCallBack."();");
  85. //$collection =$theme->getStyleCollection($this->_collection);eval('$theme = '.$this->_getThemeCallBack."();");
  86. $collection =$this->getStyleCollection();
  87. $property =$collection->getStyleProperty($this->_property);
  88. return $property->getStyleComponent($this->_component);
  89. }
  90. function getStyleCollection(){
  91. eval('$theme = '.$this->_getThemeCallBack."();");
  92. $rule = ExtendsValidatorRule::getRule("Theme");
  93. if(!$rule->check($theme)){
  94. throwError(new Error("Callback ".$this->_getThemeCallBack."() did not return a theme ","GUIWizardComponents",true));
  95. }
  96. $collection =$theme->getStyleCollection($this->_collection);
  97. $rule = ExtendsValidatorRule::getRule("StyleCollection");
  98. if(!$rule->check($collection)){
  99. throwError(new Error("Theme ".$theme->getDisplayName()." did not have StyleCollection ".$this->_collection,"GUIWizardComponents",true));
  100. }
  101. return $collection;
  102. }
  103. /**
  104. * Returns true if this component (and all child components if applicable) have valid values.
  105. * By default, this will just return TRUE.
  106. * @access public
  107. * @return boolean
  108. */
  109. function validate () {
  110. return $this->_wizardComponent->validate();
  111. }
  112. /**
  113. * Tells the wizard component to update itself - this may include getting
  114. * form post data or validation - whatever this particular component wants to
  115. * do every pageload.
  116. * @param string $fieldName The field name to use when outputting form data or
  117. * similar parameters/information.
  118. * @access public
  119. * @return boolean - TRUE if everything is OK
  120. */
  121. function update ($fieldName) {
  122. $this->_wizardComponent->update($fieldName);
  123. //$styleComponent =$this->getStyleComponent();
  124. //$val = $this->getAllValues();
  125. /*$rule =$styleComponent->getRule();
  126. if($rule->check($val)){
  127. $styleComponent->setValue($val);
  128. }else{
  129. print "<br />failed: '".$val."'!";
  130. }*/
  131. //$styleComponent->setValue($val);
  132.  
  133. $this->exportValue();
  134. return true;
  135. }
  136. /**
  137. * copy the value of the Wizard component to the StyleComponent
  138. */
  139. function exportValue(){
  140. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  141. }
  142. /**
  143. * copy the value from the StyleComponent to the wizard component
  144. */
  145. function importValue(){
  146. $styleComponent =$this->getStyleComponent();
  147. $val = $styleComponent->getValue();
  148. if($this->isPossibleValue($val)){
  149. $this->_wizardComponent->setValue($val);
  150. }else{
  151. $this->useDefaultValue();
  152. }
  153. }
  154. /**
  155. * Is $value a legitamate value for this wizard component?
  156. *
  157. * @param string $value the value to test
  158. * @return boolean if the value is legitimate
  159. */
  160. function isPossibleValue($value){
  161. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  162. }
  163. /**
  164. * Returns the values of wizard-components. It may return the value of the
  165. * wizard component, but this may be overridden.
  166. *
  167. * @access public
  168. * @return mixed
  169. */
  170. function getAllValues () {
  171. $ret = $this->_wizardComponent->getAllValues();
  172. return $ret;
  173. }
  174.  
  175. /**
  176. * Returns a block of XHTML-valid code that contains markup for this specific
  177. * component.
  178. * @param string $fieldName The field name to use when outputting form data or
  179. * similar parameters/information.
  180. * @access public
  181. * @return string
  182. */
  183. function getMarkup ($fieldName) {
  184. $s="";
  185. $s.= $this->_wizardComponent->getMarkup($fieldName);
  186. return $s;
  187. }
  188. }
  189.  
  190. ?>

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