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
|
1 |
|
$this->response->redirect("comments"); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function delete() |
36
|
|
|
{ |
37
|
1 |
|
$this->di->get("comments")->deleteComment($_GET['id'], $this->db); |
38
|
1 |
|
$this->response->redirect("comments"); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public function edit() |
42
|
|
|
{ |
43
|
1 |
|
$this->di->get("comments")->editComment($_POST['id'], $_POST['comment'], $this->db); |
44
|
1 |
|
$this->response->redirect("comments"); |
45
|
|
|
} |
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
|
|
|
|