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

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

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Admin\Feedback;
4
5
use Apps\ActiveRecord\FeedbackPost;
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\Feedback
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionIndex
18
{
19
    /**
20
     * List feedback post messages with notifications
21
     * @return string
22
     */
23
    public function index(): ?string
24
    {
25
        // set current page and offset
26
        $page = (int)$this->request->query->get('page');
27
        $offset = $page * self::ITEM_PER_PAGE;
0 ignored issues
show
The constant Apps\Controller\Admin\Fe...ionIndex::ITEM_PER_PAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
29
        // get feedback posts AR table
30
        $query = FeedbackPost::with(['answers']);
31
        $totalCount = $query->count();
32
33
        // build listing objects
34
        $records = $query->orderBy('id', 'desc')
35
            ->skip($offset)
36
            ->take(self::ITEM_PER_PAGE)
37
            ->get();
38
39
        // render output
40
        return $this->view->render('feedback/index', [
41
            'records' => $records,
42
            'pagination' => [
43
                'url' => ['feedback/index'],
44
                'page' => $page,
45
                'step' => self::ITEM_PER_PAGE,
46
                'total' => $totalCount
47
            ]
48
        ]);
49
    }
50
}
51