Changeset View
Changeset View
Standalone View
Standalone View
src/view/control/AphrontTableView.php
Show All 18 Lines | final class AphrontTableView extends AphrontView { | ||||
protected $sortURI; | protected $sortURI; | ||||
protected $sortParam; | protected $sortParam; | ||||
protected $sortSelected; | protected $sortSelected; | ||||
protected $sortReverse; | protected $sortReverse; | ||||
protected $sortValues = array(); | protected $sortValues = array(); | ||||
private $deviceReadyTable; | private $deviceReadyTable; | ||||
private $rowDividers = array(); | |||||
public function __construct(array $data) { | public function __construct(array $data) { | ||||
$this->data = $data; | $this->data = $data; | ||||
} | } | ||||
public function setHeaders(array $headers) { | public function setHeaders(array $headers) { | ||||
$this->headers = $headers; | $this->headers = $headers; | ||||
return $this; | return $this; | ||||
} | } | ||||
Show All 13 Lines | public function setCellClasses(array $cell_classes) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setColumnWidths(array $widths) { | public function setColumnWidths(array $widths) { | ||||
$this->columnWidths = $widths; | $this->columnWidths = $widths; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setRowDividers(array $dividers) { | |||||
$this->rowDividers = $dividers; | |||||
return $this; | |||||
} | |||||
public function setNoDataString($no_data_string) { | public function setNoDataString($no_data_string) { | ||||
$this->noDataString = $no_data_string; | $this->noDataString = $no_data_string; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setClassName($class_name) { | public function setClassName($class_name) { | ||||
$this->className = $class_name; | $this->className = $class_name; | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | foreach ($col_classes as $key => $value) { | ||||
$value = trim($value.' sorted-column'); | $value = trim($value.' sorted-column'); | ||||
} | } | ||||
if ($value !== null) { | if ($value !== null) { | ||||
$col_classes[$key] = $value; | $col_classes[$key] = $value; | ||||
} | } | ||||
} | } | ||||
$dividers = $this->rowDividers; | |||||
$data = $this->data; | $data = $this->data; | ||||
if ($data) { | if ($data) { | ||||
$row_num = 0; | $row_num = 0; | ||||
$row_idx = 0; | |||||
foreach ($data as $row) { | foreach ($data as $row) { | ||||
$is_divider = !empty($dividers[$row_num]); | |||||
$row_size = count($row); | $row_size = count($row); | ||||
while (count($row) > count($col_classes)) { | while (count($row) > count($col_classes)) { | ||||
$col_classes[] = null; | $col_classes[] = null; | ||||
} | } | ||||
while (count($row) > count($visibility)) { | while (count($row) > count($visibility)) { | ||||
$visibility[] = true; | $visibility[] = true; | ||||
} | } | ||||
while (count($row) > count($device_visibility)) { | while (count($row) > count($device_visibility)) { | ||||
Show All 11 Lines | if ($data) { | ||||
$class = $col_classes[$col_num]; | $class = $col_classes[$col_num]; | ||||
if (empty($device_visibility[$col_num])) { | if (empty($device_visibility[$col_num])) { | ||||
$class = trim($class.' aphront-table-view-nodevice'); | $class = trim($class.' aphront-table-view-nodevice'); | ||||
} | } | ||||
if (!empty($this->cellClasses[$row_num][$col_num])) { | if (!empty($this->cellClasses[$row_num][$col_num])) { | ||||
$class = trim($class.' '.$this->cellClasses[$row_num][$col_num]); | $class = trim($class.' '.$this->cellClasses[$row_num][$col_num]); | ||||
} | } | ||||
if ($is_divider) { | |||||
$tr[] = phutil_tag( | |||||
'td', | |||||
array( | |||||
'class' => 'row-divider', | |||||
'colspan' => count($headers), | |||||
), | |||||
$value); | |||||
$row_idx = -1; | |||||
break; | |||||
} | |||||
$tr[] = phutil_tag( | $tr[] = phutil_tag( | ||||
'td', | 'td', | ||||
array( | array( | ||||
'class' => $class, | 'class' => $class, | ||||
), | ), | ||||
$value); | $value); | ||||
++$col_num; | ++$col_num; | ||||
} | } | ||||
$class = idx($this->rowClasses, $row_num); | $class = idx($this->rowClasses, $row_num); | ||||
if ($this->zebraStripes && ($row_num % 2)) { | if ($this->zebraStripes && ($row_idx % 2)) { | ||||
if ($class !== null) { | if ($class !== null) { | ||||
$class = 'alt alt-'.$class; | $class = 'alt alt-'.$class; | ||||
} else { | } else { | ||||
$class = 'alt'; | $class = 'alt'; | ||||
} | } | ||||
} | } | ||||
$table[] = phutil_tag('tr', array('class' => $class), $tr); | $table[] = phutil_tag('tr', array('class' => $class), $tr); | ||||
++$row_num; | ++$row_num; | ||||
++$row_idx; | |||||
} | } | ||||
} else { | } else { | ||||
$colspan = max(count(array_filter($visibility)), 1); | $colspan = max(count(array_filter($visibility)), 1); | ||||
$table[] = phutil_tag( | $table[] = phutil_tag( | ||||
'tr', | 'tr', | ||||
array('class' => 'no-data'), | array('class' => 'no-data'), | ||||
phutil_tag( | phutil_tag( | ||||
'td', | 'td', | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |