Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Entries | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| card | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Panel\Dashboard; |
| 6 | |
| 7 | use Celema\Quma\Database; |
| 8 | use Cosray\Collection\AllContent; |
| 9 | use Cosray\Collection\Ref; |
| 10 | use Cosray\Contract\DashboardCard; |
| 11 | use Cosray\Navigation; |
| 12 | use Override; |
| 13 | |
| 14 | final readonly class Entries implements DashboardCard |
| 15 | { |
| 16 | public function __construct( |
| 17 | private Database $db, |
| 18 | private Navigation $navigation, |
| 19 | ) {} |
| 20 | |
| 21 | #[Override] |
| 22 | public function card(): Card |
| 23 | { |
| 24 | $row = $this->db->dashboard->entries()->one(); |
| 25 | // The built-in overview lists everything the others do, so it is not |
| 26 | // a collection of its own here. |
| 27 | $collections = count(array_filter( |
| 28 | $this->navigation->refs(), |
| 29 | static fn(Ref $ref): bool => $ref->class !== AllContent::class, |
| 30 | )); |
| 31 | |
| 32 | return new Card( |
| 33 | label: __('dashboard:entries'), |
| 34 | value: (int) ($row['total'] ?? 0), |
| 35 | note: __n( |
| 36 | 'dashboard:collection-count', |
| 37 | 'dashboard:collection-count-plural', |
| 38 | $collections, |
| 39 | ), |
| 40 | ); |
| 41 | } |
| 42 | } |