Fix after merge
This commit is contained in:
parent
0ffdbe8573
commit
284dc4e5a5
59
studs.php
59
studs.php
@ -16,6 +16,8 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
|
use Framadate\Exception\AlreadyExistsException;
|
||||||
|
use Framadate\Exception\ConcurrentEditionException;
|
||||||
use Framadate\Services\LogService;
|
use Framadate\Services\LogService;
|
||||||
use Framadate\Services\PollService;
|
use Framadate\Services\PollService;
|
||||||
use Framadate\Services\InputService;
|
use Framadate\Services\InputService;
|
||||||
@ -121,6 +123,7 @@ if ($accessGranted) {
|
|||||||
$name = $inputService->filterName($_POST['name']);
|
$name = $inputService->filterName($_POST['name']);
|
||||||
$editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT);
|
$editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT);
|
||||||
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
|
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
|
||||||
|
$slots_hash = $inputService->filterMD5($_POST['control']);
|
||||||
|
|
||||||
if (empty($editedVote)) {
|
if (empty($editedVote)) {
|
||||||
$message = new Message('danger', __('Error', 'Something is going wrong...'));
|
$message = new Message('danger', __('Error', 'Something is going wrong...'));
|
||||||
@ -131,24 +134,29 @@ if ($accessGranted) {
|
|||||||
|
|
||||||
if ($message == null) {
|
if ($message == null) {
|
||||||
// Update vote
|
// Update vote
|
||||||
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices);
|
try {
|
||||||
if ($result) {
|
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash);
|
||||||
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
if ($result) {
|
||||||
$editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
||||||
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
$editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
||||||
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
|
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
||||||
$message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
|
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
|
||||||
|
$message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
|
||||||
|
} else {
|
||||||
|
$message = new Message('success', __('studs', 'Update vote succeeded'));
|
||||||
|
}
|
||||||
|
$notificationService->sendUpdateNotification($poll, NotificationService::UPDATE_VOTE, $name);
|
||||||
} else {
|
} else {
|
||||||
$message = new Message('success', __('studs', 'Update vote succeeded'));
|
$message = new Message('danger', __('Error', 'Update vote failed'));
|
||||||
}
|
}
|
||||||
$notificationService->sendUpdateNotification($poll, NotificationService::UPDATE_VOTE, $name);
|
} catch (ConcurrentEditionException $cee) {
|
||||||
} else {
|
$message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
|
||||||
$message = new Message('danger', __('Error', 'Update vote failed'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (isset($_POST['save'])) { // Add a new vote
|
} elseif (isset($_POST['save'])) { // Add a new vote
|
||||||
$name = $inputService->filterName($_POST['name']);
|
$name = $inputService->filterName($_POST['name']);
|
||||||
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
|
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
|
||||||
|
$slots_hash = $inputService->filterMD5($_POST['control']);
|
||||||
|
|
||||||
if ($name == null) {
|
if ($name == null) {
|
||||||
$message = new Message('danger', __('Error', 'The name is invalid.'));
|
$message = new Message('danger', __('Error', 'The name is invalid.'));
|
||||||
@ -159,19 +167,25 @@ if ($accessGranted) {
|
|||||||
|
|
||||||
if ($message == null) {
|
if ($message == null) {
|
||||||
// Add vote
|
// Add vote
|
||||||
$result = $pollService->addVote($poll_id, $name, $choices);
|
try {
|
||||||
if ($result) {
|
$result = $pollService->addVote($poll_id, $name, $choices, $slots_hash);
|
||||||
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
if ($result) {
|
||||||
$editedVoteUniqueId = $result->uniqId;
|
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
||||||
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
$editedVoteUniqueId = $result->uniqId;
|
||||||
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
|
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
||||||
$message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
|
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
|
||||||
|
$message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
|
||||||
|
} else {
|
||||||
|
$message = new Message('success', __('studs', 'Adding the vote succeeded'));
|
||||||
|
}
|
||||||
|
$notificationService->sendUpdateNotification($poll, NotificationService::ADD_VOTE, $name);
|
||||||
} else {
|
} else {
|
||||||
$message = new Message('success', __('studs', 'Adding the vote succeeded'));
|
$message = new Message('danger', __('Error', 'Adding vote failed'));
|
||||||
}
|
}
|
||||||
$notificationService->sendUpdateNotification($poll, NotificationService::ADD_VOTE, $name);
|
} catch (AlreadyExistsException $aee) {
|
||||||
} else {
|
$message = new Message('danger', __('Error', 'You already voted'));
|
||||||
$message = new Message('danger', __('Error', 'Adding vote failed'));
|
} catch (ConcurrentEditionException $cee) {
|
||||||
|
$message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,6 +205,7 @@ $smarty->assign('title', __('Generic', 'Poll') . ' - ' . $poll->title);
|
|||||||
$smarty->assign('expired', strtotime($poll->end_date) < time());
|
$smarty->assign('expired', strtotime($poll->end_date) < time());
|
||||||
$smarty->assign('deletion_date', strtotime($poll->end_date) + PURGE_DELAY * 86400);
|
$smarty->assign('deletion_date', strtotime($poll->end_date) + PURGE_DELAY * 86400);
|
||||||
$smarty->assign('slots', $poll->format === 'D' ? $pollService->splitSlots($slots) : $slots);
|
$smarty->assign('slots', $poll->format === 'D' ? $pollService->splitSlots($slots) : $slots);
|
||||||
|
$smarty->assign('slots_hash', $pollService->hashSlots($slots));
|
||||||
$smarty->assign('votes', $pollService->splitVotes($votes));
|
$smarty->assign('votes', $pollService->splitVotes($votes));
|
||||||
$smarty->assign('best_choices', $pollService->computeBestChoices($votes));
|
$smarty->assign('best_choices', $pollService->computeBestChoices($votes));
|
||||||
$smarty->assign('comments', $comments);
|
$smarty->assign('comments', $comments);
|
||||||
|
Loading…
Reference in New Issue
Block a user