| 1 |
<?php |
| 2 |
namespace Mgleis\DiskUsageInsights\Frontend; |
| 3 |
|
| 4 |
class Table { |
| 5 |
|
| 6 |
private /** @var string */ $headline; |
| 7 |
private /** @var array */ $columnNames = []; |
| 8 |
private /** @var array */ $columnCss = []; |
| 9 |
private /** @var array */ $percentBar = null; // [$colDisplay, $colSource] |
| 10 |
private /** @var array */ $data = []; |
| 11 |
private /** @var array */ $vbarChart = []; |
| 12 |
private ?Pagination $pagination = null; |
| 13 |
|
| 14 |
public function __construct(string $headline, array $columnNames = [], array $columnCss = []) |
| 15 |
{ |
| 16 |
$this->headline = $headline; |
| 17 |
if ($columnNames !== null) { |
| 18 |
$this->columnNames = $columnNames; |
| 19 |
} |
| 20 |
if ($columnCss !== null) { |
| 21 |
$this->columnCss = $columnCss; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function withData(array $data): self { |
| 26 |
$this->data = $data; |
| 27 |
|
| 28 |
return $this; |
| 29 |
} |
| 30 |
|
| 31 |
public function output() { |
| 32 |
$table = $this->data; |
| 33 |
$pagination = $this->pagination; |
| 34 |
include __DIR__ . '/../../views/blocks/table.php'; |
| 35 |
} |
| 36 |
|
| 37 |
public function withPercentBar(int $colDisplay, int $colSource): self { |
| 38 |
$this->percentBar = [$colDisplay, $colSource]; |
| 39 |
|
| 40 |
return $this; |
| 41 |
} |
| 42 |
|
| 43 |
public function withVbarChart(int $colSource): self { |
| 44 |
// vbar chart |
| 45 |
$this->vbarChart = []; |
| 46 |
foreach ($this->data as $row) { |
| 47 |
$this->vbarChart[] = floatval($row[$colSource]); |
| 48 |
} |
| 49 |
|
| 50 |
return $this; |
| 51 |
} |
| 52 |
|
| 53 |
public function withPagination(Pagination $pagination): self { |
| 54 |
$this->pagination = $pagination; |
| 55 |
|
| 56 |
return $this; |
| 57 |
} |
| 58 |
|
| 59 |
public function hasPercentBar($col): bool { |
| 60 |
return $this->percentBar !== null |
| 61 |
&& $this->percentBar[0] === $col; |
| 62 |
} |
| 63 |
|
| 64 |
public function getPercentBar(int $row): float { |
| 65 |
return floatval($this->data[$row][$this->percentBar[1]]); |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|