1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Criteria; |
6
|
|
|
use Obblm\Core\Entity\Coach; |
7
|
|
|
use Obblm\Core\Security\Roles; |
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
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @Route(name="obblm_") |
15
|
|
|
*/ |
16
|
|
|
class FrontendController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Route("/", name="dashboard") |
20
|
|
|
*/ |
21
|
|
|
public function home():Response |
22
|
|
|
{ |
23
|
|
|
$this->denyAccessUnlessGranted(Roles::COACH); |
24
|
|
|
|
25
|
|
|
return $this->render('@ObblmCore/dashboard/index.html.twig'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @Route("/{_locale}", name="locale_switch") |
30
|
|
|
*/ |
31
|
|
|
public function localeSwitch(Request $request) |
32
|
|
|
{ |
33
|
|
|
if($request->headers->get('referer')) |
34
|
|
|
{ |
35
|
|
|
return $this->redirect($request->headers->get('referer')); |
36
|
|
|
} |
37
|
|
|
return $this->redirectToRoute('obblm_dashboard'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function lastTeams($max = 5):Response |
41
|
|
|
{ |
42
|
|
|
$this->denyAccessUnlessGranted(Roles::COACH); |
43
|
|
|
|
44
|
|
|
$user = $this->getUser(); |
45
|
|
|
$teams = []; |
46
|
|
|
if ($user instanceof Coach) { |
47
|
|
|
$criteria = Criteria::create() |
48
|
|
|
->setMaxResults($max) |
49
|
|
|
->orderBy(['id' => 'DESC']); |
50
|
|
|
$teams = $user->getTeams()->matching($criteria); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->render('@ObblmCore/dashboard/last-teams.html.twig', [ |
54
|
|
|
'teams' => $teams, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|