Completed
Branch develop (defee6)
by Benjamin
06:13
created

FrontendController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
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\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
use Symfony\Contracts\Translation\TranslatorInterface;
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
    public function lastTeams($max = 5):Response
29
    {
30
        $this->denyAccessUnlessGranted(Roles::COACH);
31
32
        $user = $this->getUser();
33
        $teams = [];
34
        if ($user instanceof Coach) {
35
            $criteria = Criteria::create()
36
                ->setMaxResults($max)
37
                ->orderBy(['id' => 'DESC']);
38
            $teams = $user->getTeams()->matching($criteria);
39
        }
40
41
        return $this->render('@ObblmCore/dashboard/last-teams.html.twig', [
42
            'teams' => $teams,
43
        ]);
44
    }
45
}
46