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

FrontendController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 18
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A localeSwitch() 0 7 2
A home() 0 5 1
A lastTeams() 0 15 2
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