diff --git a/adminstuds.php b/adminstuds.php index f0bc76c..676922d 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -55,6 +55,7 @@ if (!$poll) { // ------------------------------- // Update poll info // ------------------------------- + if (isset($_POST['update_poll_info'])) { $updated = false; $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'comment', 'rules']); @@ -107,6 +108,19 @@ if (isset($_POST['update_poll_info'])) { } } +// ------------------------------- +// Delete a comment +// ------------------------------- +if (!empty($_POST['delete_comment'])) { + $comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT); + + if ($pollService->deleteComment($poll_id, $comment_id)) { + $message = new Message('success', _('Comment deleted.')); + } else { + $message = new Message('danger', _('Failed to delete the comment.')); + } +} + // Retrieve data $slots = $pollService->allSlotsByPollId($poll_id); $votes = $pollService->allUserVotesByPollId($poll_id); diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 8978772..f20f80e 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -112,4 +112,9 @@ class FramaDB return $prepared->execute([$poll_id, $name, $comment]); } + function deleteComment($poll_id, $comment_id) { + $prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ? AND id_comment = ?'); + return $prepared->execute([$poll_id, $comment_id]); + } + } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 9256b27..d1fb923 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -64,6 +64,10 @@ class PollService { return $this->connect->insertComment($poll_id, $name, $comment); } + function deleteComment($poll_id, $comment_id) { + return $this->connect->deleteComment($poll_id, $comment_id); + } + function computeBestMoments($votes) { $result = []; foreach ($votes as $vote) { diff --git a/tpl/part/comments.tpl b/tpl/part/comments.tpl index 4e9f09c..a9bb572 100644 --- a/tpl/part/comments.tpl +++ b/tpl/part/comments.tpl @@ -1,36 +1,40 @@ +
-{* Comment list *} + {* Comment list *} -{if $comments|count > 0} - {foreach $comments as $comment} -
- {$comment->usercomment}  - {nl2br($comment->comment)} + {if $comments|count > 0} +

{_("Comments of polled people")}

+ {foreach $comments as $comment} +
+ {if $admin} + + {/if} + {$comment->usercomment}  + {nl2br($comment->comment)} +
+ {/foreach} + {/if} + + {* Add comment form *} + {if $active} +
+
+
{_("Add a comment to the poll")} +
+ + +
+
+ + +
+
+ +
+
+
+
- {/foreach} -{/if} - -{* Add comment form *} -{if $active} -
- -
-
{_("Add a comment to the poll")} -
- - -
-
- - -
-
- -
-
-
-
- -
-{/if} \ No newline at end of file + {/if} + \ No newline at end of file