Merge branch 'feature/own_vote_edition_in_session' into 'develop'
Feature / Own vote edition in session Dans le cas ou chaque utilisateur ne peut modifier que son propre vote, le dernier vote d'un utilisateur est gardé en session pour qu'il n'ait pas à utiliser l'URL personnelle tout de suite. Fix #118 See merge request !95
This commit is contained in:
commit
5c895cca22
@ -395,5 +395,6 @@ $smarty->assign('admin', true);
|
|||||||
$smarty->assign('hidden', false);
|
$smarty->assign('hidden', false);
|
||||||
$smarty->assign('accessGranted', true);
|
$smarty->assign('accessGranted', true);
|
||||||
$smarty->assign('resultPubliclyVisible', true);
|
$smarty->assign('resultPubliclyVisible', true);
|
||||||
|
$smarty->assign('editedVoteUniqueId', '');
|
||||||
|
|
||||||
$smarty->display('studs.tpl');
|
$smarty->display('studs.tpl');
|
||||||
|
53
app/classes/Framadate/Services/SessionService.php
Normal file
53
app/classes/Framadate/Services/SessionService.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Framadate\Services;
|
||||||
|
|
||||||
|
|
||||||
|
class SessionService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value of $key in $section, or $defaultValue
|
||||||
|
*
|
||||||
|
* @param $section
|
||||||
|
* @param $key
|
||||||
|
* @param null $defaultValue
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get($section, $key, $defaultValue=null) {
|
||||||
|
assert(!empty($key));
|
||||||
|
assert(!empty($section));
|
||||||
|
|
||||||
|
$this->initSectionIfNeeded($section);
|
||||||
|
|
||||||
|
$returnValue = $defaultValue;
|
||||||
|
if (isset($_SESSION[$section][$key])) {
|
||||||
|
$returnValue = $_SESSION[$section][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a $value for $key in $section
|
||||||
|
*
|
||||||
|
* @param $section
|
||||||
|
* @param $key
|
||||||
|
* @param $value
|
||||||
|
*/
|
||||||
|
public function set($section, $key, $value) {
|
||||||
|
assert(!empty($key));
|
||||||
|
assert(!empty($section));
|
||||||
|
|
||||||
|
$this->initSectionIfNeeded($section);
|
||||||
|
|
||||||
|
$_SESSION[$section][$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function initSectionIfNeeded($section) {
|
||||||
|
if (!isset($_SESSION[$section])) {
|
||||||
|
$_SESSION[$section] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
studs.php
20
studs.php
@ -22,12 +22,19 @@ use Framadate\Services\InputService;
|
|||||||
use Framadate\Services\MailService;
|
use Framadate\Services\MailService;
|
||||||
use Framadate\Services\NotificationService;
|
use Framadate\Services\NotificationService;
|
||||||
use Framadate\Services\SecurityService;
|
use Framadate\Services\SecurityService;
|
||||||
|
use Framadate\Services\SessionService;
|
||||||
use Framadate\Message;
|
use Framadate\Message;
|
||||||
use Framadate\Utils;
|
use Framadate\Utils;
|
||||||
use Framadate\Editable;
|
use Framadate\Editable;
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
|
/* Constantes */
|
||||||
|
/* ---------- */
|
||||||
|
|
||||||
|
const USER_REMEMBER_VOTES_KEY = 'UserVotes';
|
||||||
|
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
/* --------- */
|
/* --------- */
|
||||||
|
|
||||||
@ -40,7 +47,6 @@ $resultPubliclyVisible = true;
|
|||||||
$slots = array();
|
$slots = array();
|
||||||
$votes = array();
|
$votes = array();
|
||||||
$comments = array();
|
$comments = array();
|
||||||
$editedVoteUniqueId = null;
|
|
||||||
|
|
||||||
/* Services */
|
/* Services */
|
||||||
/*----------*/
|
/*----------*/
|
||||||
@ -51,6 +57,7 @@ $inputService = new InputService();
|
|||||||
$mailService = new MailService($config['use_smtp']);
|
$mailService = new MailService($config['use_smtp']);
|
||||||
$notificationService = new NotificationService($mailService);
|
$notificationService = new NotificationService($mailService);
|
||||||
$securityService = new SecurityService();
|
$securityService = new SecurityService();
|
||||||
|
$sessionService = new SessionService();
|
||||||
|
|
||||||
|
|
||||||
/* PAGE */
|
/* PAGE */
|
||||||
@ -69,6 +76,8 @@ if (!$poll) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$editedVoteUniqueId = $sessionService->get(USER_REMEMBER_VOTES_KEY, $poll_id, '');
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// Password verification
|
// Password verification
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
@ -127,8 +136,9 @@ if ($accessGranted) {
|
|||||||
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices);
|
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
||||||
$editedVoteUniqId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
$editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
||||||
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqId);
|
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
||||||
|
$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);
|
$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 {
|
} else {
|
||||||
$message = new Message('success', __('studs', 'Update vote succeeded'));
|
$message = new Message('success', __('studs', 'Update vote succeeded'));
|
||||||
@ -154,7 +164,9 @@ if ($accessGranted) {
|
|||||||
$result = $pollService->addVote($poll_id, $name, $choices);
|
$result = $pollService->addVote($poll_id, $name, $choices);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
|
||||||
$urlEditVote = Utils::getUrlSondage($poll_id, false, $result->uniqId);
|
$editedVoteUniqueId = $result->uniqId;
|
||||||
|
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
|
||||||
|
$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);
|
$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 {
|
} else {
|
||||||
$message = new Message('success', __('studs', 'Adding the vote succeeded'));
|
$message = new Message('success', __('studs', 'Adding the vote succeeded'));
|
||||||
|
Loading…
Reference in New Issue
Block a user