Completed
Push — fm-support ( 624fa6...b0af51 )
by Konstantinos
09:12 queued 04:41
created

VisitLogController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 0
cbo 6
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 6 2
A listAction() 0 22 2
A getQueryBuilder() 0 3 1
1
<?php
2
3
use Symfony\Component\HttpFoundation\Request;
4
5
class VisitLogController extends HTMLController
6
{
7
    public function setup()
8
    {
9
        if (!$this->getMe()->hasPermission(Permission::VIEW_VISITOR_LOG)) {
10
            throw new ForbiddenException("You are not allowed to view visitor logs.");
11
        }
12
    }
13
14
    public function listAction(Request $request)
15
    {
16
        /** @var VisitQueryBuilder $qb */
17
        $qb = $this->getQueryBuilder();
18
19
        $currentPage = $request->query->get('page', 1);
20
21
        if ($request->query->has('search')) {
22
            $qb->search($request->query->get('search'));
23
        }
24
25
        $visits = $qb->sortBy('timestamp')->reverse()
26
            ->limit(30)->fromPage($currentPage)
27
            ->getModels($fast = true);
28
29
        return array(
30
            "visits"      => $visits,
31
            "currentPage" => $currentPage,
32
            "totalPages"  => $qb->countPages(),
33
            "search"      => $request->query->get('search')
34
        );
35
    }
36
37
    public static function getQueryBuilder($type = "Visit") {
38
        return $type::getQueryBuilder();
39
    }
40
}
41