Passed
Push — Comments ( f56c48...58658e )
by Stone
02:01
created

Comment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use App\Models\CommentModel;
6
use Core\AjaxController;
7
use Core\Container;
8
9
class Comment extends AjaxController
10
{
11
    private $commentModel;
12
13
    public function __construct(Container $container)
14
    {
15
        parent::__construct($container);
16
        $this->commentModel = new CommentModel($this->container);
17
    }
18
19
    /**
20
     * Update the approved status of a comment
21
     * @throws \Core\JsonException
22
     */
23
    public function modifyApproved()
24
    {
25
        $this->onlyAdmin();
26
        $this->onlyPost();
27
        $state = (bool)($this->request->getData("state") === 'true');
28
        $commentId = (int)$this->request->getData("commentId");
29
30
        $result = array();
31
        $result["success"] = $this->commentModel->setApproved(!$state, $commentId);
32
        $result["state"] = !$state;
33
        $result["commentId"] = $commentId;
34
        echo json_encode($result);
35
    }
36
37
}