Source for file WMultiSelectList.class.php

Documentation is available at WMultiSelectList.class.php

  1. <?php
  2. /**
  3. * @since Jul 21, 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: WMultiSelectList.class.php,v 1.6 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY.'/main/library/Wizard/WizardComponent.abstract.php');
  13.  
  14. /**
  15. * This class allows for the creation of select lists where you can select multiple elements.
  16. *
  17. * @since Jul 21, 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: WMultiSelectList.class.php,v 1.6 2007/09/19 14:04:51 adamfranco Exp $
  24. */
  25. class WMultiSelectList
  26. extends WizardComponent
  27. {
  28.  
  29. var $_value = array();
  30. var $_style = null;
  31. var $_size = 2;
  32. var $_items = array();
  33. /**
  34. * Constructor
  35. * @access public
  36. * @return WMultiSelectList
  37. */
  38. function WMultiSelectList () {
  39. // do nothing
  40. }
  41. /**
  42. * sets the CSS style for the labels of the radio buttons.
  43. * @param string $style
  44. * @access public
  45. * @return void
  46. */
  47. function setStyle ($style) {
  48. $this->_style = $style;
  49. }
  50. /**
  51. * Sets the number of viewable elements in this list.
  52. * @param integer $size
  53. * @access public
  54. * @return void
  55. */
  56. function setSize ($size) {
  57. $this->_size = $size;
  58. }
  59. /**
  60. * Sets the passed value to be selected in the list.
  61. * @param string $value
  62. * @access public
  63. * @return void
  64. */
  65. function setValue ($value) {
  66. $this->_value[] = $value;
  67. $this->_value = array_unique($this->_value);
  68. }
  69. /**
  70. * Adds a radio option to this list.
  71. * @param string $value The short value that represents the displayed text.
  72. * @param string $displayText The text to show to the end user.
  73. * @access public
  74. * @return void
  75. */
  76. function addOption ($value, $displayText) {
  77. $this->_items[$value] = $displayText;
  78. }
  79. /**
  80. * Tells the wizard component to update itself - this may include getting
  81. * form post data or validation - whatever this particular component wants to
  82. * do every pageload.
  83. * @param string $fieldName The field name to use when outputting form data or
  84. * similar parameters/information.
  85. * @access public
  86. * @return boolean - TRUE if everything is OK
  87. */
  88. function update ($fieldName) {
  89. $val = RequestContext::value($fieldName);
  90. if (is_array($val)) $this->_value = $val;
  91. }
  92. /**
  93. * Returns the values of wizard-components. Should return an array if children are involved,
  94. * otherwise a whatever type of object is expected.
  95. * @access public
  96. * @return mixed
  97. */
  98. function getAllValues () {
  99. return $this->_value;
  100. }
  101. /**
  102. * Returns a block of XHTML-valid code that contains markup for this specific
  103. * component.
  104. * @param string $fieldName The field name to use when outputting form data or
  105. * similar parameters/information.
  106. * @access public
  107. * @return string
  108. */
  109. function getMarkup ($fieldName) {
  110. $name = RequestContext::name($fieldName)."[]";
  111. $style = '';
  112. if ($this->_style) $style = " style=\"".addslashes($this->_style)."\"";
  113.  
  114. $m = "<select name='$name' size='".$this->_size."' multiple$style>\n";
  115. foreach (array_keys($this->_items) as $key) {
  116. $disp = $this->_items[$key];
  117. $selected = in_array($key, $this->_value)?" selected='selected'":"";
  118. $val = htmlspecialchars($key, ENT_QUOTES);
  119. $m .= "<option value='$val'$selected>".htmlspecialchars($disp)."</option>\n";
  120. }
  121. $m .= "</select>\n";
  122. return $m;
  123. }
  124. }
  125.  
  126. ?>

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