Completed
Push — master ( a08399...bacbcd )
by André
01:28
created

CommentsController::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Anax\Comments;
4
5
use \Anax\DI\InjectionAwareInterface;
6
use \Anax\DI\InjectionAwareTrait;
7
8
class CommentsController implements InjectionAwareInterface
9
{
10
    use InjectionAwareTrait;
11
12
    private $db;
13
    private $session;
14
    private $response;
15
16 1
    public function init($database)
17
    {
18 1
        $this->db = $database;
19 1
        $this->response = $this->di->get("response");
20 1
    }
21
22 1
    public function inject($session)
23
    {
24 1
        $this->session = $session;
25 1
        return $this;
26
    }
27
28 1
    public function add()
29
    {
30 1
        $user = $this->session->get("user");
31 1
        $this->di->get("comments")->addComment($_POST, $this->db, $user);
32
        // $this->response->redirect("comments");
33 1
    }
34
35 1
    public function delete()
36
    {
37 1
        $this->di->get("comments")->deleteComment($_GET['id'], $this->db);
38
        // $this->response->redirect("comments");
39 1
    }
40
41 1
    public function edit()
42
    {
43 1
        $this->di->get("comments")->editComment($_POST['id'], $_POST['comment'], $this->db);
44
        // $this->response->redirect("comments");
45 1
    }
46
47 1
    public function get($id)
48
    {
49 1
        return $this->di->get("comments")->getComment($id, $this->db);
50
    }
51
52 1
    public function addCommentSection()
53
    {
54 1
        $url = $this->di->get("url")->create('post_comment');
55 1
        $del = $this->di->get("url")->create('delete_comment');
56 1
        $edit = $this->di->get("url")->create('preview');
57 1
        $this->di->get("comments")->commentSection($url, $del, $edit, $this->di->get("session"));
58 1
    }
59
60
    public function renderMain()
61
    {
62
        $this->di->get("view")->add("comments/comments");
63
        $this->di->get("pageRender")->renderPage([
64
            "title" => "Comments"
65
        ]);
66
    }
67
68
    public function renderEdit()
69
    {
70
        $this->di->get("view")->add("comments/edit_comment");
71
        $this->di->get("pageRender")->renderPage([
72
            "title" => "Edit Comment"
73
        ]);
74
    }
75
}
76