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

Controller/Admin/Comments/ActionAnswerList.php (1 issue)

1
<?php
2
3
namespace Apps\Controller\Admin\Comments;
4
5
use Apps\ActiveRecord\CommentAnswer;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionAnswerList
12
 * @package Apps\Controller\Admin\Comments
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionAnswerList
18
{
19
    /**
20
     * List answers action
21
     * @return string
22
     */
23
    public function answerList(): ?string
24
    {
25
        // set current page and offset
26
        $page = (int)$this->request->query->get('page');
27
        $offset = $page * self::ITEM_PER_PAGE;
28
29
        // get result as active records object with offset
30
        $records = CommentAnswer::orderBy('id', 'desc')
31
            ->skip($offset)
32
            ->take(self::ITEM_PER_PAGE)
33
            ->get();
34
35
        // render output view
36
        return $this->view->render('comments/answer_list', [
37
            'records' => $records,
38
            'pagination' => [
39
                'url' => ['comments/answerlist'],
40
                'page' => $page,
41
                'step' => self::ITEM_PER_PAGE,
42
                'total' => CommentAnswer::count()
0 ignored issues
show
Bug Best Practice introduced by
The method Ffcms\Core\Arch\ActiveModel::count() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
                'total' => CommentAnswer::/** @scrutinizer ignore-call */ count()
Loading history...
43
            ]
44
        ]);
45
    }
46
}
47