FrontendController::home()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
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
            return $this->redirect($request->headers->get('referer'));
35
        }
36
        return $this->redirectToRoute('obblm_dashboard');
37
    }
38
39
    public function lastTeams($max = 5):Response
40
    {
41
        $this->denyAccessUnlessGranted(Roles::COACH);
42
43
        $user = $this->getUser();
44
        $teams = [];
45
        if ($user instanceof Coach) {
46
            $criteria = Criteria::create()
47
                ->setMaxResults($max)
48
                ->orderBy(['id' => 'DESC']);
49
            $teams = $user->getTeams()->matching($criteria);
50
        }
51
52
        return $this->render('@ObblmCore/dashboard/last-teams.html.twig', [
53
            'teams' => $teams,
54
        ]);
55
    }
56
}
57