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

FrontendController::lastTeams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.9332
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