Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
CurrenciesDynamicDataProvider
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultSortColumn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 loadRows
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 fetchFacetedFilterOptions
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Currencies\Application\DataSource;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Engine\Domain\Model\ModuleMetadata;
12use App\Core\Engine\Domain\Model\PermissionContext;
13use App\Modules\About\Application\DataSource\AbstractInMemoryDataProvider;
14use App\Modules\Currencies\Domain\Repository\CurrencyRepositoryInterface;
15
16/**
17 * Dynamic Data Provider for Currencies module in DataGrid.
18 */
19final readonly class CurrenciesDynamicDataProvider extends AbstractInMemoryDataProvider
20{
21    private const string MODULE_NAME = 'currencies';
22
23    public function __construct(
24        private CurrencyRepositoryInterface $currencyRepository
25    ) {
26    }
27
28    public function supports(string $moduleName): bool
29    {
30        return $moduleName === self::MODULE_NAME;
31    }
32
33    protected function getDefaultSortColumn(): string
34    {
35        return 'sort_order';
36    }
37
38    protected function loadRows(): array
39    {
40        $entities = $this->currencyRepository->findAll();
41        $rows = [];
42        foreach ($entities as $currency) {
43            $rows[] = $currency->toArray();
44        }
45
46        return $rows;
47    }
48
49    public function fetchFacetedFilterOptions(
50        ModuleMetadata $module,
51        PermissionContext $context
52    ): array {
53        return [
54            'is_active' => [
55                ['id' => '1', 'label' => 'Aktywna'],
56                ['id' => '0', 'label' => 'Nieaktywna'],
57            ],
58            'is_base' => [
59                ['id' => '1', 'label' => 'Waluta bazowa (PLN)'],
60                ['id' => '0', 'label' => 'Waluta obca'],
61            ],
62        ];
63    }
64}