Completed
Branch v1.x-dev (6fcd50)
by Benjamin
04:47
created

FrontendController::localeSwitch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
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