Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Admin/Profile/ActionIndex.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Admin\Profile;
4
5
use Apps\ActiveRecord\Profile;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionIndex
12
 * @package Apps\Controller\Admin\Profile
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionIndex
18
{
19
    /**
20
     * List all user profiles
21
     * @return null|string
22
     */
23
    public function index(): ?string
24
    {
25
        // init Active Record
26
        $query = Profile::with(['user']);
27
28
        // set current page and offset
29
        $page = (int)$this->request->query->get('page');
30
        $offset = $page * self::ITEM_PER_PAGE;
0 ignored issues
show
The constant Apps\Controller\Admin\Pr...ionIndex::ITEM_PER_PAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
32
        // count total items count for pagination builder
33
        $total = $query->count();
34
35
        // build listing objects
36
        $records = $query->orderBy('id', 'desc')
37
            ->skip($offset)
38
            ->take(self::ITEM_PER_PAGE)
39
            ->get();
40
41
        // display viewer
42
        return $this->view->render('profile/index', [
43
            'records' => $records,
44
            'pagination' => [
45
                'url' => ['profile/index'],
46
                'page' => $page,
47
                'step' => self::ITEM_PER_PAGE,
48
                'total' => $total
49
            ]
50
        ]);
51
    }
52
}
53