/** * Generates a XMLElement representation of a `<select>`. This uses * the private function `__SelectBuildOption()` to build XMLElements of * options given the `$options` array. * * @see toolkit.Widget::__SelectBuildOption() * @param string $name * The name attribute of the resulting `<select>` * @param array $options (optional) * An array containing the data for each `<option>` for this * `<select>`. If the array is associative, it is assumed that * `<optgroup>` are to be created, otherwise it's an array of the * containing the option data. If no options are provided an empty * `<select>` XMLElement is returned. * ` * array( * array($value, $selected, $desc, $class, $id, $attr) * ) * array( * array('label' => 'Optgroup', 'options' = array( * array($value, $selected, $desc, $class, $id, $attr) * ) * ) * ` * @param array $attributes (optional) * Any additional attributes can be included in an associative array with * the key being the name and the value being the value of the attribute. * Attributes set from this array will override existing attributes * set by previous params. * @return XMLElement */ public static function Select($name, array $options = null, array $attributes = null) { General::ensureType(array('name' => array('var' => $name, 'type' => 'string'))); $obj = new XMLElement('select'); $obj->setAttribute('name', $name); $obj->setSelfClosingTag(false); if (is_array($attributes) && !empty($attributes)) { $obj->setAttributeArray($attributes); } if (!is_array($options) || empty($options)) { if (!isset($attributes['disabled'])) { $obj->setAttribute('disabled', 'disabled'); } return $obj; } foreach ($options as $o) { // Optgroup if (isset($o['label'])) { $optgroup = new XMLElement('optgroup'); $optgroup->setAttribute('label', $o['label']); foreach ($o['options'] as $option) { $optgroup->appendChild(Widget::__SelectBuildOption($option)); } $obj->appendChild($optgroup); } else { $obj->appendChild(Widget::__SelectBuildOption($o)); } } return $obj; }
function Select($name, $options, $attributes = NULL) { $obj = new XMLElement('select'); $obj->setAttribute('name', $name); $obj->setSelfClosingTag(false); if (is_array($attributes) && !empty($attributes)) { foreach ($attributes as $key => $value) { $obj->setAttribute($key, $value); } } if (!is_array($options) || empty($options)) { if (!isset($attributes['disabled'])) { $obj->setAttribute('disabled', 'disabled'); } //$option = new XMLElement('option', ' '); //$option->setAttribute('value', ''); //$obj->appendChild($option); return $obj; } foreach ($options as $o) { ## Opt Group if (isset($o['label'])) { $optgroup = new XMLElement('optgroup'); $optgroup->setAttribute('label', $o['label']); foreach ($o['options'] as $opt) { $optgroup->appendChild(Widget::__SelectBuildOption($opt)); } $obj->appendChild($optgroup); } else { $obj->appendChild(Widget::__SelectBuildOption($o)); } } return $obj; }
public static function Select($name, $options, array $attributes = NULL) { $obj = Widget::$Symphony->createElement('select'); $attributes['name'] = $name; if (!is_null($attributes)) { $obj->setAttributeArray($attributes); } $obj->appendChild(Widget::$Symphony->createTextNode('')); if (!is_array($options) || empty($options)) { if (is_null($attributes) || !isset($attributes['disabled'])) { $obj->setAttribute('disabled', 'disabled'); } return $obj; } foreach ($options as $o) { ## Opt Group if (isset($o['label'])) { $optgroup = Widget::$Symphony->createElement('optgroup'); $optgroup->setAttribute('label', $o['label']); foreach ($o['options'] as $opt) { $optgroup->appendChild(Widget::__SelectBuildOption($opt)); } $obj->appendChild($optgroup); } else { $obj->appendChild(Widget::__SelectBuildOption($o)); } } return $obj; }