Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DataTableRenderer
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 render
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 renderItem
n/a
0 / 0
n/a
0 / 0
0
 renderHeader
n/a
0 / 0
n/a
0 / 0
1
1<?php
2
3abstract class DataTableRenderer
4{
5    public function __construct($urlParams, $name, $caption)
6    {
7        $this->name = $name;
8        $this->caption = $caption;
9        $this->page = isset($urlParams[$this->name]) ? max(1, (int) $urlParams[$this->name]) : 1;
10        $this->pageCount = intval(ceil($this->count / self::$PAGE_SIZE));
11        $this->offset = ($this->page - 1) * self::$PAGE_SIZE;
12    }
13
14    public function render()
15    {
16        echo '<h3 id="' . $this->name . '_header">' . $this->caption . ' (' . $this->count . ')</h3>';
17        echo PaginationHelper::render($this->page, $this->pageCount, $this->name);
18        echo '<table border="0" class="statsTable" style="border-collapse:collapse;">';
19        $this->renderHeader();
20        foreach ($this->data as $index => $item)
21        {
22            echo '<tr>';
23            $this->renderItem($index, $item);
24            echo '</tr>';
25        }
26        echo '</table>';
27        echo PaginationHelper::render($this->page, $this->pageCount, $this->name);
28    }
29
30    abstract protected function renderItem(int $index, array $item): void;
31    protected function renderHeader(): void {}
32
33    protected string $name;
34    protected string $caption;
35    protected static $PAGE_SIZE = 100;
36
37    protected array $data = [];
38    protected int $page;
39    protected int $pageCount;
40    protected int $count;
41    protected int $offset;
42}