-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminController.php
More file actions
62 lines (55 loc) · 1.71 KB
/
AdminController.php
File metadata and controls
62 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace SyncEngine\Controller\Admin;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use SyncEngine\Attribute\MenuItem;
use SyncEngine\Controller\DefaultController;
use SyncEngine\Model\AutomationModel;
use SyncEngine\Model\TraceModel;
use SyncEngine\Repository\MessengerMessageRepository;
class AdminController extends DefaultController
{
#[Route( '/', name: 'admin_index' )]
#[MenuItem( menu: 'main', route: 'syncengine_admin_index', label: 'Dashboard', parent: 'dashboards', icon: 'dashboard', position: 0 )]
public function dashboard( MessengerMessageRepository $messageRepository ): Response
{
$query = [
'limit' => 10,
'total' => true,
'dependencies' => true,
'order' => [ 'created' => 'DESC' ],
];
$messengerItems = $messageRepository->findAll();
$totalMessenger = count( $messengerItems );
foreach ( $messengerItems as &$item ) {
$decoded = json_decode( $item['body'], true );
$item['body'] = $decoded ?: substr( $item['body'], 0, 200 ) . '...';
if ( ! empty( $item['body']['automationId'] ) ) {
$item['automation'] = AutomationModel::get( $item['body']['automationId'] )?->normalize( false, false );
}
}
return $this->render(
'admin/dashboard.html.twig',
[
'traces' => [
'query' => $query,
'items' => [],
'total' => TraceModel::getTotalCount( $query ),
],
'messenger' => [
'items' => $messengerItems,
'total' => $totalMessenger,
'query' => [
'limit' => 10,
'order' => [ 'created_at' => 'DESC' ],
],
],
]
);
}
#[Route( '/heartbeat', name: 'admin_heartbeat' )]
public function heartbeat(): Response
{
return new Response();
}
}