You are here

public function QPList::appendTable in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/Extension/QPList.php \QPList::appendTable()
  2. 7.2 QueryPath/Extension/QPList.php \QPList::appendTable()

File

QueryPath/Extension/QPList.php, line 15

Class

QPList

Code

public function appendTable($items, $options = array()) {
  $opts = $options + array(
    'table class' => 'qptable',
  );
  $base = '<?xml version="1.0"?>
    <table>
    <tbody>
      <tr></tr>
    </tbody>
    </table>';
  $qp = qp($base, 'table')
    ->addClass($opts['table class'])
    ->find('tr');
  if ($items instanceof TableAble) {
    $headers = $items
      ->getHeaders();
    $rows = $items
      ->getRows();
  }
  elseif ($items instanceof Traversable) {
    $headers = array();
    $rows = $items;
  }
  else {
    $headers = $items['headers'];
    $rows = $items['rows'];
  }
  foreach ($headers as $header) {
    $qp
      ->append('<th>' . $header . '</th>');
  }
  $qp
    ->top()
    ->find('tr:last');
  foreach ($rows as $row) {
    $qp
      ->after('<tr/>')
      ->next();
    foreach ($row as $cell) {
      $qp
        ->append('<td>' . $cell . '</td>');
    }
  }
  $this->qp
    ->append($qp
    ->top());
  return $this->qp;
}