1 | <?php |
||
7 | class CommentHandler |
||
8 | { |
||
9 | private $db; |
||
10 | private $table; |
||
11 | |||
12 | 10 | public function __construct($db, $table = 'r1_comments') |
|
17 | |||
18 | /** |
||
19 | * Create a comment |
||
20 | * |
||
21 | * @param $postId |
||
22 | * @param $parentId - parent comment |
||
23 | * @param $authorId - author/user id |
||
24 | * @param $authorName - author/user name |
||
25 | * @param $text - comment text |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 6 | public function new($postId, $parentId, $authorId, $authorName, $text) |
|
34 | |||
35 | /** |
||
36 | * Get a comment |
||
37 | * |
||
38 | * @param $id - comment id |
||
39 | * |
||
40 | * @return array - the comment |
||
41 | */ |
||
42 | 4 | public function fetch($id) |
|
47 | |||
48 | /** |
||
49 | * Update a comments text. |
||
50 | * |
||
51 | * @param $id - comment id |
||
52 | * @param $text - new text |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | 2 | public function upsert($id, $text) |
|
57 | { |
||
58 | 2 | $updated = \date("Y-m-d H:i:s"); |
|
59 | 2 | $sql = "UPDATE $this->table SET `text`=?, updated=? WHERE id=?"; |
|
60 | 2 | $this->db->query($sql, [$text, $updated, $id]); |
|
61 | 2 | } |
|
62 | |||
63 | /** |
||
64 | * Delete all comments associated with a post. |
||
65 | * |
||
66 | * @param $postId |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | 4 | public function deleteComments($postId) |
|
75 | |||
76 | /** |
||
77 | * Get comments for a post. |
||
78 | * |
||
79 | * @param $id - post id |
||
80 | * |
||
81 | * @return array - comments grouped by parent comment |
||
82 | */ |
||
83 | 6 | public function commentsForPost($id) |
|
94 | } |
||
95 |