Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| OverdueEventsWidgetRenderer | |
100.00% |
15 / 15 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| 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\Modules\Dashboard\Infrastructure\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\WidgetRendererInterface; |
| 15 | use App\Modules\Dashboard\Application\Service\DashboardWidgetsServiceInterface; |
| 16 | use Psr\Http\Message\ServerRequestInterface; |
| 17 | use Throwable; |
| 18 | use Twig\Environment as TwigEnvironment; |
| 19 | |
| 20 | /** |
| 21 | * Overdue Calendar Events Widget Renderer for Gridstack Catalog. |
| 22 | * |
| 23 | * @package App\Modules\Dashboard\Infrastructure\Widget |
| 24 | */ |
| 25 | final readonly class OverdueEventsWidgetRenderer implements WidgetRendererInterface |
| 26 | { |
| 27 | /** |
| 28 | * OverdueEventsWidgetRenderer constructor. |
| 29 | * |
| 30 | * @param DashboardWidgetsServiceInterface $widgetsService Dashboard widgets service. |
| 31 | * @param TwigEnvironment $twig Twig template renderer. |
| 32 | */ |
| 33 | public function __construct( |
| 34 | private DashboardWidgetsServiceInterface $widgetsService, |
| 35 | private TwigEnvironment $twig, |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | */ |
| 42 | public function supports(WidgetMetadata $widget): bool |
| 43 | { |
| 44 | return $widget->name === 'overdue_calendar_events'; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @inheritDoc |
| 49 | */ |
| 50 | public function render( |
| 51 | RelationGridMetadata $relation, |
| 52 | ServerRequestInterface $request, |
| 53 | PermissionContext $context |
| 54 | ): string { |
| 55 | try { |
| 56 | $events = $this->widgetsService->getOverdueCalendarEvents($context, 5); |
| 57 | $totalCount = $this->widgetsService->getOverdueCalendarEventsCount($context); |
| 58 | |
| 59 | return $this->twig->render('dashboard/partials/widget_overdue_events.twig', [ |
| 60 | 'relation' => $relation, |
| 61 | 'events' => $events, |
| 62 | 'total_count' => $totalCount, |
| 63 | 'limit' => 5, |
| 64 | ]); |
| 65 | } catch (Throwable $e) { |
| 66 | return sprintf( |
| 67 | '<div class="alert alert-danger m-2">Overdue events widget error: %s</div>', |
| 68 | htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | } |