|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Schanihbg\Comment; |
|
4
|
|
|
|
|
5
|
|
|
use \Anax\DI\InjectionAwareInterface; |
|
6
|
|
|
use \Anax\DI\InjectionAwareTrait; |
|
7
|
|
|
use \Anax\Configure\ConfigureInterface; |
|
8
|
|
|
use \Anax\Configure\ConfigureTrait; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* REM Server. |
|
12
|
|
|
*/ |
|
13
|
|
|
class CommentModel implements ConfigureInterface, InjectionAwareInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use ConfigureTrait; |
|
16
|
|
|
use InjectionAwareTrait; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array $session inject a reference to the session. |
|
21
|
|
|
*/ |
|
22
|
|
|
private $session; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string $key to use when storing in session. |
|
28
|
|
|
*/ |
|
29
|
|
|
const KEY = "comment"; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Inject dependency to $session.. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $session object representing session. |
|
37
|
|
|
* |
|
38
|
|
|
* @return self |
|
39
|
|
|
*/ |
|
40
|
3 |
|
public function injectSession($session) |
|
41
|
|
|
{ |
|
42
|
3 |
|
$this->session = $session; |
|
43
|
3 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* View all posts |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function viewAll() |
|
53
|
|
|
{ |
|
54
|
1 |
|
$sql = "SELECT * FROM `ramverk1_comment`"; |
|
55
|
|
|
|
|
56
|
1 |
|
return $this->di->get("database")->executeFetchAll($sql); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Show one post |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function showOnePost($id) |
|
65
|
|
|
{ |
|
66
|
1 |
|
$sql = "SELECT * FROM ramverk1_comment where id = ?"; |
|
67
|
|
|
|
|
68
|
1 |
|
return $this->di->get("database")->executeFetch($sql, [$id]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Edit post |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function editPost($id) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$sql = "SELECT * FROM ramverk1_comment where id = ?"; |
|
79
|
|
|
|
|
80
|
1 |
|
return $this->di->get("database")->executeFetch($sql, [$id]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Delete post |
|
85
|
|
|
* |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
public function removePost($id) |
|
89
|
|
|
{ |
|
90
|
|
|
$sql = "DELETE FROM ramverk1_comment WHERE id = ?"; |
|
91
|
|
|
$this->di->get("database")->execute($sql, [$id]); |
|
92
|
|
|
$this->di->get("response")->redirect($this->di->get("url")->create("comment")); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|