1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin\Comments; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\CommentPost; |
6
|
|
|
use Ffcms\Core\Arch\View; |
7
|
|
|
use Ffcms\Core\Helper\HTML\SimplePagination; |
8
|
|
|
use Ffcms\Core\Network\Request; |
9
|
|
|
use Ffcms\Core\Network\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Trait ActionIndex |
13
|
|
|
* @package Apps\Controller\Admin\Comments |
14
|
|
|
* @property Request $request |
15
|
|
|
* @property Response $response |
16
|
|
|
* @property View $view |
17
|
|
|
*/ |
18
|
|
|
trait ActionIndex |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* List user comments with pagination |
22
|
|
|
* @return string |
23
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
24
|
|
|
*/ |
25
|
|
|
public function index(): ?string |
26
|
|
|
{ |
27
|
|
|
// set current page and offset |
28
|
|
|
$page = (int)$this->request->query->get('page'); |
29
|
|
|
$offset = $page * self::ITEM_PER_PAGE; |
30
|
|
|
|
31
|
|
|
// initialize active record model |
32
|
|
|
$query = new CommentPost(); |
33
|
|
|
|
34
|
|
|
// make pagination |
35
|
|
|
$pagination = new SimplePagination([ |
36
|
|
|
'url' => ['comments/index'], |
37
|
|
|
'page' => $page, |
38
|
|
|
'step' => self::ITEM_PER_PAGE, |
39
|
|
|
'total' => $query->count() |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
// get result as active records object with offset |
43
|
|
|
$records = $query->orderBy('id', 'desc') |
44
|
|
|
->skip($offset) |
45
|
|
|
->take(self::ITEM_PER_PAGE) |
46
|
|
|
->get(); |
47
|
|
|
|
48
|
|
|
// render output view |
49
|
|
|
return $this->view->render('index', [ |
50
|
|
|
'records' => $records, |
51
|
|
|
'pagination' => $pagination |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|