Passed
Push — Comments ( 804108...f56c48 )
by Stone
02:05
created

Comments::viewComments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Admin;
4
5
use App\Models\CommentModel;
6
use Core\AdminController;
7
use Core\Constant;
8
use Core\Container;
9
use Core\Traits\StringFunctions;
10
11
class Comments extends AdminController{
12
13
    use StringFunctions;
1 ignored issue
show
Bug introduced by
The trait Core\Traits\StringFunctions requires the property $childNodes which is not provided by App\Controllers\Admin\Comments.
Loading history...
14
15
    protected $siteConfig;
16
    protected $pagination;
17
18
    private $commentModel;
19
20
    public function __construct(Container $container)
21
    {
22
        $this->loadModules[] = 'SiteConfig';
23
        $this->loadModules[] = 'pagination';
24
        parent::__construct($container);
25
        $this->commentModel = new CommentModel($this->container);
26
    }
27
28
29
    public function viewComments(string $page = "page-1", int $linesPerPage = Constant::LIST_PER_PAGE)
30
    {
31
        $this->onlyAdmin();
32
33
        $totalComments = $this->commentModel->countPendingComments();
34
        $pagination = $this->pagination->getPagination($page, $totalComments, $linesPerPage);
35
36
        if ($linesPerPage !== Constant::LIST_PER_PAGE) {
37
            $this->data['paginationPostsPerPage'] = $linesPerPage;
38
        }
39
40
        $this->data['pagination'] = $pagination;
41
        $this->data['configs'] = $this->siteConfig->getSiteConfig();
42
        $this->data["comments"] = $this->commentModel->getPendingCommentsList($pagination["offset"], $linesPerPage);
43
44
45
        $this->renderView('Admin/Comments');
46
    }
47
48
    public function pendingComments(string $page = "page-1", int $linesPerPage = Constant::LIST_PER_PAGE)
49
    {
50
        $this->onlyAdmin();
51
52
        $totalComments = $this->commentModel->countPendingComments();
53
        $pagination = $this->pagination->getPagination($page, $totalComments, $linesPerPage);
54
55
        if ($linesPerPage !== Constant::LIST_PER_PAGE) {
56
            $this->data['paginationPostsPerPage'] = $linesPerPage;
57
        }
58
59
        $this->data['pagination'] = $pagination;
60
        $this->data['configs'] = $this->siteConfig->getSiteConfig();
61
        $this->data["comments"] = $this->commentModel->getPendingCommentsList($pagination["offset"], $linesPerPage);
62
        $this->data['pendingView'] = true;
63
64
        $this->renderView('Admin/Comments');
65
66
    }
67
68
    public function moderateComment(int $commentId)
0 ignored issues
show
Unused Code introduced by
The parameter $commentId is not used and could be removed. ( Ignorable by Annotation )

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

68
    public function moderateComment(/** @scrutinizer ignore-unused */ int $commentId)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        $this->onlyAdmin();
71
72
73
        $this->renderView('Admin/ViewComment');
74
    }
75
}