qp = $qp; } public function appendTable($items, $options = array()) { $opts = $options + array( 'table class' => 'qptable', ); $base = '
'; $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']; } // Add Headers: foreach ($headers as $header) { $qp->append('' . $header . ''); } $qp->top()->find('tr:last'); // Add rows and cells. foreach ($rows as $row) { $qp->after('')->next(); foreach($row as $cell) $qp->append('' . $cell . ''); } $this->qp->append($qp->top()); return $this->qp; } /** * Append a list of items into an HTML DOM using one of the HTML list structures. * This takes a one-dimensional array and converts it into an HTML UL or OL list, * or it can take an associative array and convert that into a DL list. * * In addition to arrays, this works with any Traversable or Iterator object. * * OL/UL arrays can be nested. * * @param mixed $items * An indexed array for UL and OL, or an associative array for DL. Iterator and * Traversable objects can also be used. * @param string $type * One of ul, ol, or dl. Predefined constants are available for use. * @param array $options * An associative array of configuration options. The supported options are: * - 'list class': The class that will be assigned to a list. */ public function appendList($items, $type = self::UL, $options = array()) { $opts = $options + array( 'list class' => 'qplist', ); if ($type == self::DL) { $q = qp('
', 'dl')->addClass($opts['list class']); foreach ($items as $dt => $dd) { $q->append('
' . $dt . '
' . $dd . '
'); } $q->appendTo($this->qp); } else { $q = $this->listImpl($items, $type, $opts); $this->qp->append($q->find(':root')); } return $this->qp; } /** * Internal recursive list generator for appendList. */ protected function listImpl($items, $type, $opts, $q = NULL) { $ele = '<' . $type . '/>'; if (!isset($q)) $q = qp()->append($ele)->addClass($opts['list class']); foreach ($items as $li) { if ($li instanceof QueryPath) { $q = $this->listImpl($li->get(), $type, $opts, $q); } elseif (is_array($li) || $li instanceof Traversable) { $q->append('