Implement comments functionnality
This commit is contained in:
parent
fcc478bb93
commit
ab5f9e013a
@ -84,4 +84,9 @@ class FramaDB
|
||||
return $prepared->execute([$choices, $poll_id, $vote_id]);
|
||||
}
|
||||
|
||||
function insertComment($poll_id, $name, $comment) {
|
||||
$prepared = $this->prepare('INSERT INTO comments (id_sondage, usercomment, comment) VALUES (?,?,?)');
|
||||
return $prepared->execute([$poll_id, $name, $comment]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ class PollService {
|
||||
return $this->connect->insertVote($poll_id, $name, $choices);
|
||||
}
|
||||
|
||||
function addComment($poll_id, $name, $comment) {
|
||||
return $this->connect->insertComment($poll_id, $name, $comment);
|
||||
}
|
||||
|
||||
function computeBestMoments($votes) {
|
||||
$result = [];
|
||||
foreach ($votes as $vote) {
|
||||
|
35
studs.php
35
studs.php
@ -18,13 +18,14 @@
|
||||
*/
|
||||
use Framadate\Services\PollService;
|
||||
use Framadate\Services\InputService;
|
||||
use Framadate\Utils;
|
||||
use Framadate\Message;
|
||||
use Framadate\Utils;
|
||||
|
||||
include_once __DIR__ . '/app/inc/init.php';
|
||||
|
||||
/* Variables */
|
||||
/* --------- */
|
||||
$poll_id = null;
|
||||
$message = null;
|
||||
|
||||
/* Services */
|
||||
@ -79,9 +80,9 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
|
||||
// Update vote
|
||||
$result = $pollService->updateVote($poll_id, $editedVote, $choices);
|
||||
if ($result) {
|
||||
$message = new Message('success', _('Update vote successfully!'));
|
||||
$message = new Message('success', _('Update vote successfully.'));
|
||||
} else {
|
||||
$message = new Message('danger', _('Update vote failed!'));
|
||||
$message = new Message('danger', _('Update vote failed.'));
|
||||
}
|
||||
}
|
||||
} elseif (isset($_POST['save'])) { // Add a new vote
|
||||
@ -99,13 +100,37 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
|
||||
// Add vote
|
||||
$result = $pollService->addVote($poll_id, $name, $choices);
|
||||
if ($result) {
|
||||
$message = new Message('success', _('Update vote successfully!'));
|
||||
$message = new Message('success', _('Update vote successfully.'));
|
||||
} else {
|
||||
$message = new Message('danger', _('Update vote failed!'));
|
||||
$message = new Message('danger', _('Update vote failed.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Add a comment
|
||||
// -------------------------------
|
||||
|
||||
if (isset($_POST['add_comment'])) {
|
||||
$name = filter_input(INPUT_POST, 'name', FILTER_VALIDATE_REGEXP, ['options'=>['regexp'=>'/^[a-z0-9_ -]+$/i']]);
|
||||
$comment = filter_input(INPUT_POST, 'comment', FILTER_DEFAULT);
|
||||
|
||||
if (empty($name)) {
|
||||
$message = new Message('danger', _('Name is incorrect.'));
|
||||
}
|
||||
|
||||
if ($message == null) {
|
||||
// Add comment
|
||||
$result = $pollService->addComment($poll_id, $name, $comment);
|
||||
if ($result) {
|
||||
$message = new Message('success', _('Comment added.'));
|
||||
} else {
|
||||
$message = new Message('danger', _('Comment failed.'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Retrieve data
|
||||
$slots = $pollService->allSlotsByPollId($poll_id);
|
||||
$votes = $pollService->allUserVotesByPollId($poll_id);
|
||||
|
@ -281,19 +281,24 @@
|
||||
{* Add comment form *}
|
||||
|
||||
<div class="hidden-print alert alert-info">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<fieldset id="add-comment"><legend>{_("Add a comment in the poll")}</legend>
|
||||
<div class="form-group">
|
||||
<p><label for="commentuser">{_("Your name")}</label><input type=text class="form-control" name="commentuser" id="commentuser" /></p>
|
||||
<form action="{$poll_id|poll_url}#comments" method="POST">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<fieldset id="add-comment"><legend>{_("Add a comment to the poll")}</legend>
|
||||
<div class="form-group">
|
||||
<label for="name" class="control-label">{_("Your name")}</label>
|
||||
<input type="text" name="name" id="name" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="comment" class="control-label">{_("Your comment")}</label>
|
||||
<textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<input type="submit" name="add_comment" value="{_("Send the comment")}" class="btn btn-success">
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<p><label for="comment">{_("Your comment")}</label><br />
|
||||
<textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea></p>
|
||||
</div>
|
||||
<p class="text-center"><input type="submit" name="ajoutcomment" value="{_("Send the comment")}" class="btn btn-success"></p>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="clearfix"></div>
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
{/block}
|
Loading…
Reference in New Issue
Block a user