+
+ /**
+ * Build a table of data
+ * @param $rows array An array of arrays of strings, each to be a row in a table
+ * @param $attribs array An array of attributes to apply to the table tag [optional]
+ * @param $headers array An array of strings to use as table headers [optional]
+ * @return string
+ */
+ public static function buildTable( $rows, $attribs = array(), $headers = null ) {
+ $s = Xml::openElement( 'table', $attribs );
+
+ if ( is_array( $headers ) ) {
+ $s .= Xml::openElement( 'thead', $attribs );
+
+ foreach( $headers as $id => $header ) {
+ $attribs = array();
+
+ if ( is_string( $id ) ) {
+ $attribs['id'] = $id;
+ }
+
+ $s .= Xml::element( 'th', $attribs, $header );
+ }
+ $s .= Xml::closeElement( 'thead' );
+ }
+
+ foreach( $rows as $id => $row ) {
+ $attribs = array();
+
+ if ( is_string( $id ) ) {
+ $attribs['id'] = $id;
+ }
+
+ $s .= Xml::buildTableRow( $attribs, $row );
+ }
+
+ $s .= Xml::closeElement( 'table' );
+
+ return $s;
+ }
+
+ /**
+ * Build a row for a table
+ * @param $attribs array An array of attributes to apply to the tr tag
+ * @param $cells array An array of strings to put in <td>
+ * @return string
+ */
+ public static function buildTableRow( $attribs, $cells ) {
+ $s = Xml::openElement( 'tr', $attribs );
+
+ foreach( $cells as $id => $cell ) {
+
+ $attribs = array();
+
+ if ( is_string( $id ) ) {
+ $attribs['id'] = $id;
+ }
+
+ $s .= Xml::element( 'td', $attribs, $cell );
+ }
+
+ $s .= Xml::closeElement( 'tr' );
+
+ return $s;
+ }