Completed
Pull Request — master (#186)
by Vladimir
16:33 queued 13:26
created

VisitLogController::getQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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
        $qb = Visit::getQueryBuilder();
17
18
        $currentPage = $this->getCurrentPage();
19
20
        if ($request->query->has('search')) {
21
            $qb->search($request->query->get('search'));
22
        }
23
24
        $visits = $qb
25
            ->orderBy('timestamp', 'DESC')
26
            ->limit(30)->fromPage($currentPage)
27
            ->getModels()
28
        ;
29
30
        return [
31
            'visits'      => $visits,
32
            'currentPage' => $currentPage,
33
            'totalPages'  => $qb->countPages(),
34
            'search'      => $request->query->get('search')
35
        ];
36
    }
37
}
38