Index: trunk/phase3/includes/Xml.php |
— | — | @@ -660,6 +660,47 @@ |
661 | 661 | |
662 | 662 | return $form; |
663 | 663 | } |
| 664 | + |
| 665 | + /** |
| 666 | + * Build a table of data |
| 667 | + * @param array $rows An array of arrays of strings, each to be a row in a table |
| 668 | + * @param array $attribs Attributes to apply to the table tag [optional] |
| 669 | + * @param array $headers An array of strings to use as table headers [optional] |
| 670 | + * @return string |
| 671 | + */ |
| 672 | + public static function buildTable( $rows, $attribs = array(), $headers = null ) { |
| 673 | + $s = Xml::openElement( 'table', $attribs ); |
| 674 | + if ( is_array( $headers ) ) { |
| 675 | + foreach( $headers as $id => $header ) { |
| 676 | + $attribs = array(); |
| 677 | + if ( is_string( $id ) ) $attribs['id'] = $id; |
| 678 | + $s .= Xml::element( 'th', $attribs, $header ); |
| 679 | + } |
| 680 | + } |
| 681 | + foreach( $rows as $id => $row ) { |
| 682 | + $attribs = array(); |
| 683 | + if ( is_string( $id ) ) $attribs['id'] = $id; |
| 684 | + $s .= Xml::buildTableRow( $attribs, $row ); |
| 685 | + } |
| 686 | + $s .= Xml::closeElement( 'table' ); |
| 687 | + return $s; |
| 688 | + } |
| 689 | + |
| 690 | + /** |
| 691 | + * Build a row for a table |
| 692 | + * @param array $cells An array of strings to put in <td> |
| 693 | + * @return string |
| 694 | + */ |
| 695 | + public static function buildTableRow( $attribs, $cells ) { |
| 696 | + $s = Xml::openElement( 'tr', $attribs ); |
| 697 | + foreach( $cells as $id => $cell ) { |
| 698 | + $attribs = array(); |
| 699 | + if ( is_string( $id ) ) $attribs['id'] = $id; |
| 700 | + $s .= Xml::element( 'td', $attribs, $cell ); |
| 701 | + } |
| 702 | + $s .= Xml::closeElement( 'tr' ); |
| 703 | + return $s; |
| 704 | + } |
664 | 705 | } |
665 | 706 | |
666 | 707 | class XmlSelect { |