|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repository\ImageRepository; |
|
6
|
|
|
use App\Repository\WanderRepository; |
|
7
|
|
|
use App\Service\StatsService; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
use Symfony\Contracts\Cache\TagAwareCacheInterface; |
|
13
|
|
|
use Symfony\UX\Chartjs\Builder\ChartBuilderInterface; |
|
14
|
|
|
use Symfony\UX\Chartjs\Model\Chart; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/admin", name="admin_") |
|
18
|
|
|
*/ |
|
19
|
|
|
class AdminController extends AbstractController |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/", name="index") |
|
23
|
|
|
*/ |
|
24
|
|
|
public function index( |
|
25
|
|
|
StatsService $statsService |
|
26
|
|
|
): Response { |
|
27
|
|
|
$wanderStats = $statsService->getWanderStats(); |
|
28
|
|
|
$imageStats = $statsService->getImageStats(); |
|
29
|
|
|
|
|
30
|
|
|
return $this->render('admin/index.html.twig', [ |
|
31
|
|
|
'imageStats' => $imageStats, |
|
32
|
|
|
'wanderStats' => $wanderStats |
|
33
|
|
|
]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @Route("/clearStatsCache", name="clear_stats_cache") |
|
38
|
|
|
*/ |
|
39
|
|
|
public function clearStatsCache(Request $request, TagAwareCacheInterface $cache): Response |
|
40
|
|
|
{ |
|
41
|
|
|
if ($this->isCsrfTokenValid('admin_clear_stats_cache', (string) $request->request->get('_token'))) { |
|
42
|
|
|
$cache->invalidateTags(['stats']); |
|
43
|
|
|
$this->addFlash( |
|
44
|
|
|
'notice', |
|
45
|
|
|
'Stats Cache Cleared.' |
|
46
|
|
|
); |
|
47
|
|
|
} else { |
|
48
|
|
|
$this->addFlash( |
|
49
|
|
|
'error', |
|
50
|
|
|
'Stats not cleared. Invalid Csrf token.' |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
return $this->redirectToRoute('admin_index'); |
|
54
|
|
|
} |
|
55
|
|
|
} |