Source for file PrimitiveIO_AuthoritativeContainer.class.php

Documentation is available at PrimitiveIO_AuthoritativeContainer.class.php

  1. <?php
  2. /**
  3. * @since 5/1/06
  4. * @package polyphony.datamanager_gui
  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: PrimitiveIO_AuthoritativeContainer.class.php,v 1.7 2007/09/19 14:04:44 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * The authoritavieContainer holds multiple fields to allow for choosing from
  14. * a list or adding a new value. Its children are the list and the new value
  15. *
  16. * @since 5/1/06
  17. * @package polyphony.datamanager_gui
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: PrimitiveIO_AuthoritativeContainer.class.php,v 1.7 2007/09/19 14:04:44 adamfranco Exp $
  23. */
  24. class PrimitiveIO_AuthoritativeContainer
  25. extends WSelectOrNew
  26. {
  27. /**
  28. * Initialize our fields
  29. *
  30. * @return void
  31. * @access public
  32. * @since 6/2/06
  33. */
  34. function _init () {
  35. $this->_select->addOption('__NEW_VALUE__', (dgettext("polyphony", "* New Value *")));
  36. $this->_select->setValue(String::fromString('__NEW_VALUE__'));
  37. }
  38. /**
  39. * Set the value of the input component
  40. *
  41. * @param string $value
  42. * @access public
  43. * @return void
  44. * @since 10/21/05
  45. */
  46. function setValue ($value) {
  47. if (is_string($value))
  48. $value = String::fromString($value);
  49. if ($this->_select->isOption($value)) {
  50. $this->_select->setValue($value);
  51. $this->_new->setValue(String::fromString(''));
  52. } else {
  53. $this->_select->setValue(String::fromString('__NEW_VALUE__'));
  54. $this->_new->setValue($value);
  55. }
  56. }
  57. /**
  58. * Set the size of the new input components
  59. *
  60. * @param integer $size
  61. * @return void
  62. * @access public
  63. * @since 5/1/06
  64. */
  65. function setSize ($size) {
  66. $hasMethods = HasMethodsValidatorRule::getRule("setSize");
  67. if ($hasMethods->check($this->_new))
  68. $this->_new->setSize(40);
  69. if ($hasMethods->check($this->_select))
  70. $this->_select->setSize(40);
  71. }
  72. /**
  73. * Sets the javascript onchange attribute.
  74. * @param string $commands
  75. * @access public
  76. * @return void
  77. */
  78. function addOnChange($commands) {
  79. $this->_select->addOnChange($commands);
  80. $this->_new->addOnChange($commands);
  81. }
  82. /**
  83. * Sets the text of the field to display until the user enters the field.
  84. * @param string $text
  85. * @access public
  86. * @return void
  87. */
  88. function setStartingDisplayText ($text) {
  89. $this->_select->setStartingDisplayText($text);
  90. }
  91. /**
  92. * Add an option to our choose list
  93. *
  94. * @param object SObject $valueObject
  95. * @return void
  96. * @access public
  97. * @since 5/1/06
  98. */
  99. function addOptionFromSObject ( $valueObject ) {
  100. if (!isset($this->_select))
  101. throwError(new Error("No Select Child Available.", "datamanager GUI"));
  102. $this->_select->addOptionFromSObject($valueObject);
  103. }
  104.  
  105. /**
  106. * Sets the value of this Component to the {@link SObject} passed.
  107. * @param ref object $value The {@link SObject} value to use.
  108. *
  109. * @return void
  110. ***/
  111. function setValueFromSObject($value)
  112. {
  113. $this->setValue($value);
  114. }
  115. /**
  116. * Return true if we should be using the new value rather than the select
  117. *
  118. * @return boolean
  119. * @access public
  120. * @since 6/2/06
  121. */
  122. function isUsingNewValue () {
  123. if ($this->_select->isStartingDisplay())
  124. return false;
  125. $newOption = String::fromString('__NEW_VALUE__');
  126. $emptyOption = String::fromString('');
  127. // print "<pre>"; var_dump($this->_select->getAllValues()); print "</pre>";
  128. return (!$this->_select->getAllValues()
  129. || $newOption->isEqualTo($this->_select->getAllValues())
  130. || $emptyOption->isEqualTo($this->_select->getAllValues()));
  131. }
  132. /**
  133. * Tells the wizard component to update itself - this may include getting
  134. * form post data or validation - whatever this particular component wants to
  135. * do every pageload.
  136. * @param string $fieldName The field name to use when outputting form data or
  137. * similar parameters/information.
  138. * @access public
  139. * @return boolean - TRUE if everything is OK
  140. */
  141. function update ($fieldName) {
  142. $this->_select->update($fieldName."_select");
  143. $this->_new->update($fieldName."_new");
  144. $newValue =$this->_new->getAllValues();
  145. if ($this->isUsingNewValue() && is_object($newValue) && $newValue->asString())
  146. $this->setValue($this->_new->getAllValues());
  147. return true;
  148. }
  149. }
  150.  
  151. ?>

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