/**
* Build a table of data
- * @param array $rows An array of arrays of strings, each to be a row in a table
- * @param array $attribs Attributes to apply to the table tag [optional]
- * @param array $headers An array of strings to use as table headers [optional]
+ * @param $rows An array of arrays of strings, each to be a row in a table
+ * @param $attribs An array of attributes to apply to the table tag [optional]
+ * @param $headers An array of strings to use as table headers [optional]
* @return string
*/
public static function buildTable( $rows, $attribs = array(), $headers = null ) {
/**
* Build a row for a table
- * @param array $cells An array of strings to put in <td>
+ * @param $cells An array of strings to put in <td>
* @return string
*/
public static function buildTableRow( $attribs, $cells ) {
$value = ($value !== false) ? $value : $name;
$this->options[] = Xml::option( $name, $value, $value === $this->default );
}
+
+ // This accepts an array of form
+ // label => value
+ // label => ( label => value, label => value )
+ public function addOptions( $options ) {
+ $this->options[] = trim(self::formatOptions( $options, $this->default ));
+ }
+
+ // This accepts an array of form
+ // label => value
+ // label => ( label => value, label => value )
+ static function formatOptions( $options, $default = false ) {
+ $data = '';
+ foreach( $options as $label => $value ) {
+ if ( is_array( $value ) ) {
+ $contents = self::formatOptions( $value, $default );
+ $data .= Xml::tags( 'optgroup', array( 'label' => $label ), $contents ) . "\n";
+ } else {
+ $data .= Xml::option( $label, $value, $value === $default ) . "\n";
+ }
+ }
+
+ return $data;
+ }
public function getHTML() {
return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );