data = $data; } public function setHeaders(array $headers) { $this->headers = $headers; return $this; } public function setColumnClasses(array $column_classes) { $this->columnClasses = $column_classes; return $this; } public function setRowClasses(array $row_classes) { $this->rowClasses = $row_classes; return $this; } public function setNoDataString($no_data_string) { $this->noDataString = $no_data_string; return $this; } public function setClassName($class_name) { $this->className = $class_name; return $this; } public function setZebraStripes($zebra_stripes) { $this->zebraStripes = $zebra_stripes; return $this; } public function render() { $class = $this->className; if ($class !== null) { $class = ' class="aphront-table-view '.$class.'"'; } else { $class = ' class="aphront-table-view"'; } $table = array(''); $col_classes = array(); foreach ($this->columnClasses as $key => $class) { if (strlen($class)) { $col_classes[] = ' class="'.$class.'"'; } else { $col_classes[] = null; } } $headers = $this->headers; if ($headers) { $table[] = ''; foreach ($headers as $col_num => $header) { $class = idx($col_classes, $col_num); $table[] = ''.$header.''; } $table[] = ''; } $data = $this->data; if ($data) { $row_num = 0; foreach ($data as $row) { while (count($row) > count($col_classes)) { $col_classes[] = null; } $class = idx($this->rowClasses, $row_num); if ($this->zebraStripes && ($row_num % 2)) { if ($class !== null) { $class = 'alt alt-'.$class; } else { $class = 'alt'; } } if ($class !== null) { $class = ' class="'.$class.'"'; } $table[] = ''; $col_num = 0; foreach ($row as $value) { $class = $col_classes[$col_num]; if ($class !== null) { $table[] = ''; } else { $table[] = ''; } $table[] = $value.''; ++$col_num; } ++$row_num; } } else { $colspan = max(count($headers), 1); $table[] = ''. coalesce($this->noDataString, 'No data available.'). ''; } $table[] = ''; return implode('', $table); } }