Passed
Push — master ( 1b1f16...a29a7e )
by Mihail
03:34
created

ActionIndex::index()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\User;
4
5
use Ffcms\Core\Arch\View;
6
use Ffcms\Core\Helper\HTML\SimplePagination;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
use Apps\ActiveRecord\User as UserRecord;
10
11
/**
12
 * Class ActionIndex
13
 * @package Apps\Controller\Admin\User
14
 * @property Request $request
15
 * @property Response $response
16
 * @property View $view
17
 */
18
trait ActionIndex
19
{
20
    /**
21
     * List all users as table
22
     * @return string
23
     * @throws \Ffcms\Core\Exception\SyntaxException
24
     */
25
    public function index(): ?string
26
    {
27
        // init Active Record user object relation
28
        $record = new UserRecord();
29
30
        // set current page num and offset
31
        $page = (int)$this->request->query->get('page', 0);
32
        $offset = $page * self::ITEM_PER_PAGE;
33
34
        // build pagination object
35
        $pagination = new SimplePagination([
36
            'url' => ['user/index'],
37
            'page' => $page,
38
            'step' => self::ITEM_PER_PAGE,
39
            'total' => $record->count()
40
        ]);
41
42
        // build listing objects
43
        $records = $record->orderBy('id', 'desc')
44
            ->skip($offset)
45
            ->take(self::ITEM_PER_PAGE)
46
            ->get();
47
48
        // display viewer
49
        return $this->view->render('index', [
50
            'records' => $records,
51
            'pagination' => $pagination
52
        ]);
53
    }
54
}
55