Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ListWidgetRenderer | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supports | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| render | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Grid\Widget; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Model\PermissionContext; |
| 12 | use App\Core\Engine\Domain\Model\RelationGridMetadata; |
| 13 | use App\Core\Engine\Domain\Model\WidgetMetadata; |
| 14 | use App\Core\Grid\Widget\Application\WidgetListQueryServiceInterface; |
| 15 | use Psr\Http\Message\ServerRequestInterface; |
| 16 | use Twig\Environment as TwigEnvironment; |
| 17 | |
| 18 | /** |
| 19 | * List Widget Renderer. |
| 20 | * |
| 21 | * Renders mini data tables of filtered module records inside Gridstack tiles. |
| 22 | * |
| 23 | * @package App\Core\Grid\Widget |
| 24 | */ |
| 25 | final readonly class ListWidgetRenderer implements WidgetRendererInterface |
| 26 | { |
| 27 | /** |
| 28 | * ListWidgetRenderer constructor. |
| 29 | * |
| 30 | * @param WidgetListQueryServiceInterface $listQueryService List query service. |
| 31 | * @param TwigEnvironment $twig Twig template environment. |
| 32 | */ |
| 33 | public function __construct( |
| 34 | private WidgetListQueryServiceInterface $listQueryService, |
| 35 | private TwigEnvironment $twig |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** {@inheritdoc} */ |
| 40 | public function supports(WidgetMetadata $widget): bool |
| 41 | { |
| 42 | return $widget->name === 'custom_list' |
| 43 | || $widget->category === 'list' |
| 44 | || $widget->handlerClass === self::class |
| 45 | || $widget->handlerClass === 'App\\Core\\Grid\\Widget\\ListWidgetRenderer'; |
| 46 | } |
| 47 | |
| 48 | /** {@inheritdoc} */ |
| 49 | public function render( |
| 50 | RelationGridMetadata $relation, |
| 51 | ServerRequestInterface $request, |
| 52 | PermissionContext $context |
| 53 | ): string { |
| 54 | $listData = $this->listQueryService->fetchListWidgetData($relation->widgetParams, $context); |
| 55 | |
| 56 | return $this->twig->render('engine/partials/widget_list_tile.twig', [ |
| 57 | 'relation' => $relation, |
| 58 | 'list_data' => $listData, |
| 59 | 'icon_class' => 'bi bi-table', |
| 60 | ]); |
| 61 | } |
| 62 | } |