Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ListViewData
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace App\Shared\UI\ListView;
6
7 class ListViewData
8{
9    public int $totalPages;
10    public int $startItem;
11    public int $endItem;
12
13    /**
14     * @param array<int, array<string, mixed>>|array<int, object> $items The data items to display
15     * @param array<string, string> $columns Associative array of attribute => Label
16     * @param int $currentPage
17     * @param int $pageSize Items per page
18     * @param int $totalItems Total items count
19     * @param string|null $sortField Current sort column name
20     * @param string $sortDirection Current sort direction ('ASC' or 'DESC')
21     * @param array<string, string> $filterParams Per-column filter active values ['column' => 'term']
22     * @param array<int, int> $pageSizeOptions Page size choices [10, 25, 50, 100]
23     * @param string|null $createUrl URL for the "Create" button
24     * @param string|null $viewRoute Route name or path template for viewing items
25     * @param string|null $updateRoute Route name or path template for editing items
26     * @param string|null $deleteRoute Route name or path template for deleting items
27     * @param bool $tableExists Whether the underlying table exists in the database
28     * @param string|null $tableName The table name that was queried
29     */
30    public function __construct(
31        public array $items,
32        public array $columns,
33        public int $currentPage = 1,
34        public int $pageSize = 10,
35        public int $totalItems = 0,
36        public ?string $sortField = null,
37        public string $sortDirection = 'ASC',
38        public array $filterParams = [],
39        public array $pageSizeOptions = [10, 25, 50, 100],
40        public ?string $createUrl = null,
41        public ?string $viewRoute = null,
42        public ?string $updateRoute = null,
43        public ?string $deleteRoute = null,
44        public bool $tableExists = true,
45        public ?string $tableName = null
46    ) {
47        $this->totalPages = $totalItems > 0 ? (int) ceil($totalItems / max(1, $pageSize)) : 1;
48        $this->startItem = $totalItems > 0 ? (($currentPage - 1) * $pageSize) + 1 : 0;
49        $this->endItem = min($totalItems, $currentPage * $pageSize);
50    }
51}