Source for file WAddFromListRepeatableComponentCollection.class.php

Documentation is available at WAddFromListRepeatableComponentCollection.class.php

  1. <?php
  2. /**
  3. * @since Aug 1, 2005
  4. * @package polyphony.wizard.components
  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: WAddFromListRepeatableComponentCollection.class.php,v 1.4 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * This component allows for the creation of repeatable components or groups of
  14. * components. Only the newly added comonents are editable. Existing ones can only
  15. * be removed.
  16. *
  17. * @since Aug 1, 2005
  18. * @package polyphony.wizard.components
  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: WAddFromListRepeatableComponentCollection.class.php,v 1.4 2007/09/19 14:04:51 adamfranco Exp $
  24. */
  25.  
  26. class WAddFromListRepeatableComponentCollection
  27. extends WRepeatableComponentCollection
  28. {
  29. function WAddFromListRepeatableComponentCollection() {
  30. parent::WRepeatableComponentCollection();
  31. $this->_addButton = WChooseOptionButton::withLabel($this->_addLabel);
  32. $this->_addButton->setParent($this);
  33. }
  34. /**
  35. * Add an array of value collections for use when adding
  36. *
  37. * @param string $name
  38. * @param array $valueCollection
  39. * @return void
  40. * @access public
  41. * @since 11/1/05
  42. */
  43. function addOptionCollection ( $name, $valueCollection ) {
  44. $this->_addButton->addOptionValue($name, $valueCollection);
  45. }
  46. /**
  47. * Tells the wizard component to update itself - this may include getting
  48. * form post data or validation - whatever this particular component wants to
  49. * do every pageload.
  50. * @param string $fieldName The field name to use when outputting form data or
  51. * similar parameters/information.
  52. * @access public
  53. * @return boolean - TRUE if everything is OK
  54. */
  55. function update ($fieldName) {
  56. $ok = true;
  57. // $this->_removeElements(array(2));
  58. // first update all our components in the collections
  59. $toRemove = array();
  60. foreach(array_keys($this->_collections) as $key) {
  61. foreach(array_keys($this->_collections[$key]) as $name) {
  62. // print "$name in $key is a ".gettype($this->_collections[$key][$name])."<br/>";
  63. // if (!is_object($this->_collections[$key][$name])) continue;
  64. if (!$this->_collections[$key][$name]->update($fieldName."_".$key."_".$name)) $ok = false;
  65. }
  66. if ($this->_collections[$key]["_remove"]->getAllValues()) $toRemove[] = $key;
  67. }
  68. $this->_removeElements($toRemove);
  69. // then, check if any "buttons" or anything were pressed to add/remove elements
  70. $this->_addButton->update($fieldName."_add");
  71. $addButtonValues = $this->_addButton->getAllValues();
  72. if ($addButtonValues['pressed']) {
  73. // print "adding element.<br/>";
  74. if (is_array($addButtonValues['option']))
  75. $this->addValueCollection($addButtonValues['option']);
  76. else
  77. $this->_addElement();
  78. }
  79. return $ok;
  80. }
  81. }
  82. ?>

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