From 54fd8464d9d4f89df278bd7556ccbb66c9bce27b Mon Sep 17 00:00:00 2001 From: m Date: Wed, 4 Apr 2018 22:18:53 +0200 Subject: [PATCH 01/11] =?UTF-8?q?Ne=20pas=20effacer=20les=20s=C3=A9lection?= =?UTF-8?q?s=20apr=C3=A8s=20l'erreur=20"Vous=20avez=20d=C3=A9j=C3=A0=20vot?= =?UTF-8?q?=C3=A9"=20https://framagit.org/framasoft/framadate/issues/194?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- studs.php | 4 ++++ tpl/part/vote_table_classic.tpl | 18 +++++++++++++----- tpl/part/vote_table_date.tpl | 23 +++++++++++++---------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/studs.php b/studs.php index f202c4a..ee8dba9 100644 --- a/studs.php +++ b/studs.php @@ -50,6 +50,8 @@ $resultPubliclyVisible = true; $slots = []; $votes = []; $comments = []; +$selectedNewVotes = []; + /* Services */ /*----------*/ @@ -180,6 +182,7 @@ if ($accessGranted) { } } catch (AlreadyExistsException $aee) { $message = new Message('danger', __('Error', 'You already voted')); + $selectedNewVotes = $choices; } catch (ConcurrentEditionException $cee) { $message = new Message('danger', __('Error', 'Poll has been updated before you vote')); } catch (ConcurrentVoteException $cve) { @@ -237,5 +240,6 @@ $smarty->assign('accessGranted', $accessGranted); $smarty->assign('resultPubliclyVisible', $resultPubliclyVisible); $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); $smarty->assign('ValueMax', $poll->ValueMax); +$smarty->assign('selectedNewVotes', $selectedNewVotes); $smarty->display('studs.tpl'); diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 1b57894..9f3193d 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -181,26 +181,34 @@ diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index db8cdce..87e3b8e 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -239,40 +239,43 @@ {foreach $slots as $slot} {foreach $slot->moments as $moment} - - - - {$i = $i+1} {/foreach} {/foreach} From 4e4e21cef240b0ec0366c6bc2d38ab557ddd03fb Mon Sep 17 00:00:00 2001 From: m Date: Wed, 4 Apr 2018 23:01:57 +0200 Subject: [PATCH 02/11] correction CI --- studs.php | 1 - 1 file changed, 1 deletion(-) diff --git a/studs.php b/studs.php index ee8dba9..7c16276 100644 --- a/studs.php +++ b/studs.php @@ -52,7 +52,6 @@ $votes = []; $comments = []; $selectedNewVotes = []; - /* Services */ /*----------*/ From 445dac2e511561f83a17ef0e5445eb5852c0b346 Mon Sep 17 00:00:00 2001 From: m Date: Wed, 4 Apr 2018 22:18:53 +0200 Subject: [PATCH 03/11] =?UTF-8?q?Ne=20pas=20effacer=20les=20s=C3=A9lection?= =?UTF-8?q?s=20apr=C3=A8s=20l'erreur=20"Vous=20avez=20d=C3=A9j=C3=A0=20vot?= =?UTF-8?q?=C3=A9"=20https://framagit.org/framasoft/framadate/issues/194?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- studs.php | 4 ++++ tpl/part/vote_table_classic.tpl | 18 +++++++++++++----- tpl/part/vote_table_date.tpl | 23 +++++++++++++---------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/studs.php b/studs.php index 6cef3ee..addce34 100644 --- a/studs.php +++ b/studs.php @@ -50,6 +50,8 @@ $resultPubliclyVisible = true; $slots = []; $votes = []; $comments = []; +$selectedNewVotes = []; + /* Services */ /*----------*/ @@ -180,6 +182,7 @@ if ($accessGranted) { } } catch (AlreadyExistsException $aee) { $message = new Message('danger', __('Error', 'You already voted')); + $selectedNewVotes = $choices; } catch (ConcurrentEditionException $cee) { $message = new Message('danger', __('Error', 'Poll has been updated before you vote')); } catch (ConcurrentVoteException $cve) { @@ -237,5 +240,6 @@ $smarty->assign('accessGranted', $accessGranted); $smarty->assign('resultPubliclyVisible', $resultPubliclyVisible); $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); $smarty->assign('ValueMax', $poll->ValueMax); +$smarty->assign('selectedNewVotes', $selectedNewVotes); $smarty->display('studs.tpl'); diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 97d3c33..ba473d3 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -180,26 +180,34 @@
    {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
  • - +
  • - +
  • {/if}
  • - -
  • - +
diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index ddfdeed..cb35ff8 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -238,40 +238,43 @@ {foreach $slots as $slot} {foreach $slot->moments as $moment} - -
    {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
  • - +
  • - +
  • - - {/if} + {/if}
  • - +
  • - +
- - {$i = $i+1} {/foreach} {/foreach} From 659cb1ec75aa945ff537408be3ef9dd169765469 Mon Sep 17 00:00:00 2001 From: m Date: Wed, 4 Apr 2018 23:01:57 +0200 Subject: [PATCH 04/11] correction CI --- studs.php | 1 - 1 file changed, 1 deletion(-) diff --git a/studs.php b/studs.php index addce34..517e482 100644 --- a/studs.php +++ b/studs.php @@ -52,7 +52,6 @@ $votes = []; $comments = []; $selectedNewVotes = []; - /* Services */ /*----------*/ From f921d383a953fd9ddeaecfac103beced7f872f2b Mon Sep 17 00:00:00 2001 From: m Date: Fri, 6 Apr 2018 14:00:20 +0200 Subject: [PATCH 05/11] bug/test-name-on-vote-edit --- adminstuds.php | 2 ++ .../Framadate/Repositories/VoteRepository.php | 15 +++++++++++++++ app/classes/Framadate/Services/PollService.php | 7 ++++++- studs.php | 4 +++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index ab2cacd..5555b82 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -223,6 +223,8 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } else { $message = new Message('danger', __('Error', 'Update vote failed')); } + } catch (AlreadyExistsException $aee) { + $message = new Message('danger', __('Error', 'The name you\'ve chosen already exist in this poll!')); } catch (ConcurrentEditionException $cee) { $message = new Message('danger', __('Error', 'Poll has been updated before you vote')); } catch (ConcurrentVoteException $cve) { diff --git a/app/classes/Framadate/Repositories/VoteRepository.php b/app/classes/Framadate/Repositories/VoteRepository.php index 1a74f5a..682357c 100644 --- a/app/classes/Framadate/Repositories/VoteRepository.php +++ b/app/classes/Framadate/Repositories/VoteRepository.php @@ -85,4 +85,19 @@ class VoteRepository extends AbstractRepository { $prepared->execute([$poll_id, $name]); return $prepared->rowCount() > 0; } + + /** + * Check if name is already used for the given poll and another vote. + * + * @param int $poll_id ID of the poll + * @param string $name Name of the vote + * @param int $vote_id ID of the current vote + * @return bool true if vote already exists + */ + public function existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id) { + $prepared = $this->prepare('SELECT 1 FROM `' . Utils::table('vote') . '` WHERE poll_id = ? AND name = ? AND id != ?'); + $prepared->execute([$poll_id, $name, $vote_id]); + return $prepared->rowCount() > 0; + } + } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index ad180b1..8e19789 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -100,7 +100,12 @@ class PollService { // Check if slots are still the same $this->checkThatSlotsDidntChanged($poll, $slots_hash); - + + // Check if vote already exists with the same name + if ($this->voteRepository->existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id)) { + throw new AlreadyExistsException(); + } + // Update vote $choices = implode($choices); return $this->voteRepository->update($poll_id, $vote_id, $name, $choices); diff --git a/studs.php b/studs.php index 6cef3ee..2d5efab 100644 --- a/studs.php +++ b/studs.php @@ -145,7 +145,9 @@ if ($accessGranted) { } else { $message = new Message('danger', __('Error', 'Update vote failed')); } - } catch (ConcurrentEditionException $cee) { + } catch (AlreadyExistsException $aee) { + $message = new Message('danger', __('Error', 'The name you\'ve chosen already exist in this poll!')); + } catch (ConcurrentEditionException $cee) { $message = new Message('danger', __('Error', 'Poll has been updated before you vote')); } catch (ConcurrentVoteException $cve) { $message = new Message('danger', __('Error', "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.")); From c4f27dc6e0380ed9713b6030715b1c2071ea9738 Mon Sep 17 00:00:00 2001 From: m Date: Fri, 6 Apr 2018 14:04:07 +0200 Subject: [PATCH 06/11] code style --- app/classes/Framadate/Repositories/VoteRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/classes/Framadate/Repositories/VoteRepository.php b/app/classes/Framadate/Repositories/VoteRepository.php index 682357c..cbbbd77 100644 --- a/app/classes/Framadate/Repositories/VoteRepository.php +++ b/app/classes/Framadate/Repositories/VoteRepository.php @@ -99,5 +99,5 @@ class VoteRepository extends AbstractRepository { $prepared->execute([$poll_id, $name, $vote_id]); return $prepared->rowCount() > 0; } - } + From 179235eaf98251af5e428541d238b342beb38c56 Mon Sep 17 00:00:00 2001 From: m Date: Fri, 6 Apr 2018 21:16:28 +0200 Subject: [PATCH 07/11] refactoring vote checks --- .../Framadate/Services/PollService.php | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 8e19789..7ccfe7b 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -88,29 +88,19 @@ class PollService { * @param $name * @param $choices * @param $slots_hash + * @throws AlreadyExistsException * @throws ConcurrentEditionException * @throws ConcurrentVoteException * @return bool */ public function updateVote($poll_id, $vote_id, $name, $choices, $slots_hash) { - $poll = $this->findById($poll_id); - - // Check that no-one voted in the meantime and it conflicts the maximum votes constraint - $this->checkMaxVotes($choices, $poll, $poll_id); - - // Check if slots are still the same - $this->checkThatSlotsDidntChanged($poll, $slots_hash); - - // Check if vote already exists with the same name - if ($this->voteRepository->existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id)) { - throw new AlreadyExistsException(); - } + $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id); // Update vote $choices = implode($choices); return $this->voteRepository->update($poll_id, $vote_id, $name, $choices); } - + /** * @param $poll_id * @param $name @@ -122,19 +112,8 @@ class PollService { * @return \stdClass */ function addVote($poll_id, $name, $choices, $slots_hash) { - $poll = $this->findById($poll_id); - - // Check that no-one voted in the meantime and it conflicts the maximum votes constraint - $this->checkMaxVotes($choices, $poll, $poll_id); - - // Check if slots are still the same - $this->checkThatSlotsDidntChanged($poll, $slots_hash); - - // Check if vote already exists - if ($this->voteRepository->existsByPollIdAndName($poll_id, $name)) { - throw new AlreadyExistsException(); - } - + $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name, NULL); + // Insert new vote $choices = implode($choices); $token = $this->random(16); @@ -145,7 +124,8 @@ class PollService { if ($this->commentRepository->exists($poll_id, $name, $comment)) { return true; } - return $this->commentRepository->insert($poll_id, $name, $comment); + + return $this->commentRepository->insert($poll_id, $name, $comment); } /** @@ -312,7 +292,38 @@ class PollService { private function random($length) { return Token::getToken($length); } - + + /** + * @param $choices + * @param $poll_id + * @param $slots_hash + * @param $name + * @param string|NULL $vote_id + * @throws AlreadyExistsException + * @throws ConcurrentVoteException + * @throws ConcurrentEditionException + */ + private function checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id) { + // Check if vote already exists with the same name + if (!isset($vote_id)) { + $exists = $this->voteRepository->existsByPollIdAndName($poll_id, $name); + } else { + $exists = $this->voteRepository->existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id); + } + + if ($exists) { + throw new AlreadyExistsException(); + } + + $poll = $this->findById($poll_id); + + // Check that no-one voted in the meantime and it conflicts the maximum votes constraint + $this->checkMaxVotes($choices, $poll, $poll_id); + + // Check if slots are still the same + $this->checkThatSlotsDidntChanged($poll, $slots_hash); + } + /** * This method checks if the hash send by the user is the same as the computed hash. * From 402f2abf64646b220e3fde35d926ef3f957f0648 Mon Sep 17 00:00:00 2001 From: m Date: Sat, 7 Apr 2018 22:24:55 +0200 Subject: [PATCH 08/11] =?UTF-8?q?ajout=20du=20message=20"Le=20sondage=20es?= =?UTF-8?q?t=20bien=20cr=C3=A9=C3=A9."=20https://framagit.org/framasoft/fr?= =?UTF-8?q?amadate/issues/62?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminstuds.php | 9 +++++++++ create_classic_poll.php | 3 +++ create_date_poll.php | 3 +++ locale/ar.json | 1 + locale/br.json | 1 + locale/de.json | 1 + locale/en.json | 1 + locale/es.json | 1 + locale/fr.json | 1 + locale/it.json | 1 + locale/nl.json | 1 + locale/oc.json | 1 + 12 files changed, 24 insertions(+) diff --git a/adminstuds.php b/adminstuds.php index ab2cacd..57e9668 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -70,6 +70,15 @@ if ($poll) { exit; } +// ------------------------------- +// creation message +// ------------------------------- + +if (isset($_SESSION["Framadate"]["messagePollCreated"])) { + unset($_SESSION["Framadate"]["messagePollCreated"]); + $message = new Message('success', __('adminstuds', 'The poll is created.')); +} + // ------------------------------- // Update poll info // ------------------------------- diff --git a/create_classic_poll.php b/create_classic_poll.php index 5e88774..2465cfe 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -108,6 +108,9 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( // Delete old polls $purgeService->purgeOldPolls(); + // creation message + $_SESSION["Framadate"]["messagePollCreated"] = TRUE; + // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); exit; diff --git a/create_date_poll.php b/create_date_poll.php index 9b0fa49..0ad2f1d 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -232,6 +232,9 @@ switch ($step) { // Delete old polls $purgeService->purgeOldPolls(); + // creation message + $_SESSION["Framadate"]["messagePollCreated"] = TRUE; + // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); exit; diff --git a/locale/ar.json b/locale/ar.json index bc1df27..716af7d 100644 --- a/locale/ar.json +++ b/locale/ar.json @@ -437,6 +437,7 @@ "Vote updated": "تم تحديث التصويت", "You can add a new scheduling date to your poll.": "You can add a new scheduling date to your poll.", "Your poll has been removed!": "Your poll has been removed!", + "The poll is created." : "The poll is created.", "and add a new column with": "and add a new column with", "remove a column or a line with": "remove a column or a line with" }, diff --git a/locale/br.json b/locale/br.json index 901335e..a49f092 100644 --- a/locale/br.json +++ b/locale/br.json @@ -437,6 +437,7 @@ "Vote updated": "Hizivaet eo bet ar vouezh", "You can add a new scheduling date to your poll.": "Gallout a rit ouzhpennañ un deiziad d'ho sontadeg.", "Your poll has been removed!": "Dilamet eo bet ar sontadeg!", + "The poll is created." : "The poll is created.", "and add a new column with": "ha m'ho peus disoñjet un dibab e c'hallit ouzhpennañ ur bann en ur glikañ war", "remove a column or a line with": "dilemel ur bann pe ul linenn gant" }, diff --git a/locale/de.json b/locale/de.json index 064f127..cf45008 100644 --- a/locale/de.json +++ b/locale/de.json @@ -437,6 +437,7 @@ "Vote updated": "Stimme aktualisiert", "You can add a new scheduling date to your poll.": "Sie können Ihrer Umfrage ein neues Datum hinzufügen.", "Your poll has been removed!": "Ihre Umfrage wurde gelöscht!", + "The poll is created." : "The poll is created.", "and add a new column with": "und neue Spalte hinzufügen mit", "remove a column or a line with": "Zeile oder Spalte entfernen mit" }, diff --git a/locale/en.json b/locale/en.json index 0a1c6f9..c8df96b 100644 --- a/locale/en.json +++ b/locale/en.json @@ -438,6 +438,7 @@ "Vote updated": "Vote updated", "You can add a new scheduling date to your poll.": "You can add a new scheduling date to your poll.", "Your poll has been removed!": "Your poll has been removed!", + "The poll is created." : "The poll is created.", "and add a new column with": "and add a new column with", "remove a column or a line with": "remove a column or a line with" }, diff --git a/locale/es.json b/locale/es.json index 88ee450..ec863f9 100644 --- a/locale/es.json +++ b/locale/es.json @@ -437,6 +437,7 @@ "Vote updated": "Voto actualizado", "You can add a new scheduling date to your poll.": "Puede añadir una nueva fecha de encuentro a su encuesta.", "Your poll has been removed!": "Su encuesta ha sido borrada", + "The poll is created." : "The poll is created.", "and add a new column with": "y se puede añadir una columna con", "remove a column or a line with": "borrar una columna o una fila con" }, diff --git a/locale/fr.json b/locale/fr.json index 3a87813..63a8d91 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -438,6 +438,7 @@ "Vote updated": "Vote mis à jour", "You can add a new scheduling date to your poll.": "Vous pouvez ajouter une date à votre sondage.", "Your poll has been removed!": "Votre sondage a été supprimé !", + "The poll is created." : "Le sondage est bien créé.", "and add a new column with": "et si vous avez oublié de saisir un choix, vous pouvez rajouter une colonne en cliquant sur", "remove a column or a line with": "effacer une colonne ou une ligne avec" }, diff --git a/locale/it.json b/locale/it.json index 3a287d2..c653d2f 100644 --- a/locale/it.json +++ b/locale/it.json @@ -437,6 +437,7 @@ "Vote updated": "Voto aggiornato", "You can add a new scheduling date to your poll.": "Potete aggiungere una data al vostro sondaggio.", "Your poll has been removed!": "Il vostro sondaggio è stato eliminato !", + "The poll is created." : "The poll is created.", "and add a new column with": "e se vi foste dimenticati di inserire una scelta, potreste aggiungere una colonna cliccando su", "remove a column or a line with": " cancellare una colonna o una riga con " }, diff --git a/locale/nl.json b/locale/nl.json index cc32c34..e65ef16 100644 --- a/locale/nl.json +++ b/locale/nl.json @@ -437,6 +437,7 @@ "Vote updated": "Stem aangepast", "You can add a new scheduling date to your poll.": "Je kan een nieuwe datum toevoegen aan je poll.", "Your poll has been removed!": "Je poll is verwijderd!", + "The poll is created." : "The poll is created.", "and add a new column with": "en voeg een nieuwe kokom toe met", "remove a column or a line with": "verwijder een kolom of regel met" }, diff --git a/locale/oc.json b/locale/oc.json index 6b59c48..4eb3951 100644 --- a/locale/oc.json +++ b/locale/oc.json @@ -437,6 +437,7 @@ "Vote updated": "Vòte mes a jorn", "You can add a new scheduling date to your poll.": "Podètz apondre una data a vòstre sondatge.", "Your poll has been removed!": "Vòstre sondatge es estat suprimit !", + "The poll is created." : "The poll is created.", "and add a new column with": "E se avètz oblidat de picar una causida, podètz tornar apondre una colomna en clicant sus", "remove a column or a line with": "escafar una colomna o una linha amb" }, From 852c2c0d2a3fab668ab2f8a3fdad067ff4a97124 Mon Sep 17 00:00:00 2001 From: m Date: Sun, 8 Apr 2018 10:46:46 +0200 Subject: [PATCH 09/11] HTML 5 and fixes --- adminstuds.php | 4 ++++ tpl/part/vote_table_classic.tpl | 8 ++++---- tpl/part/vote_table_date.tpl | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index ab2cacd..5373b5f 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -201,6 +201,8 @@ if (!empty($_GET['vote'])) { // Something to save (edit or add) // ------------------------------- +$selectedNewVotes = []; + if (!empty($_POST['save'])) { // Save edition of an old vote $name = $inputService->filterName($_POST['name']); $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT); @@ -252,6 +254,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } } catch (AlreadyExistsException $aee) { $message = new Message('danger', __('Error', 'You already voted')); + $selectedNewVotes = $choices; } catch (ConcurrentEditionException $cee) { $message = new Message('danger', __('Error', 'Poll has been updated before you vote')); } catch (ConcurrentVoteException $cve) { @@ -445,5 +448,6 @@ $smarty->assign('accessGranted', true); $smarty->assign('resultPubliclyVisible', true); $smarty->assign('editedVoteUniqueId', ''); $smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']); +$smarty->assign('selectedNewVotes', $selectedNewVotes); $smarty->display('studs.tpl'); diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index ba473d3..2ebfd4b 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -181,7 +181,7 @@ {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
  • diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index cb35ff8..21b0fd3 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -243,7 +243,7 @@ {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
  • -
  • From addaa95ce75b190f62a0e2ac59f9295dc2feb2c1 Mon Sep 17 00:00:00 2001 From: m Date: Sun, 8 Apr 2018 11:21:11 +0200 Subject: [PATCH 10/11] using SessionService --- adminstuds.php | 9 +++++++-- create_classic_poll.php | 4 +++- create_date_poll.php | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 57e9668..011500c 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -29,6 +29,7 @@ use Framadate\Services\LogService; use Framadate\Services\MailService; use Framadate\Services\NotificationService; use Framadate\Services\PollService; +use Framadate\Services\SessionService; use Framadate\Utils; include_once __DIR__ . '/app/inc/init.php'; @@ -51,6 +52,7 @@ $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options']); $notificationService = new NotificationService($mailService); +$sessionService = new SessionService(); /* PAGE */ /* ---- */ @@ -74,8 +76,11 @@ if ($poll) { // creation message // ------------------------------- -if (isset($_SESSION["Framadate"]["messagePollCreated"])) { - unset($_SESSION["Framadate"]["messagePollCreated"]); +$messagePollCreated = $sessionService->get("Framadate", "messagePollCreated", FALSE); + +if ($messagePollCreated) { + $sessionService->remove("Framadate", "messagePollCreated"); + $message = new Message('success', __('adminstuds', 'The poll is created.')); } diff --git a/create_classic_poll.php b/create_classic_poll.php index 2465cfe..920b0ae 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -21,6 +21,7 @@ use Framadate\Services\LogService; use Framadate\Services\MailService; use Framadate\Services\PollService; use Framadate\Services\PurgeService; +use Framadate\Services\SessionService; use Framadate\Utils; include_once __DIR__ . '/app/inc/init.php'; @@ -31,6 +32,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp'], $config['smtp_options']); $purgeService = new PurgeService($connect, $logService); +$sessionService = new SessionService(); if (is_file('bandeaux_local.php')) { include_once('bandeaux_local.php'); @@ -109,7 +111,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( $purgeService->purgeOldPolls(); // creation message - $_SESSION["Framadate"]["messagePollCreated"] = TRUE; + $sessionService->set("Framadate", "messagePollCreated", TRUE); // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); diff --git a/create_date_poll.php b/create_date_poll.php index 0ad2f1d..a66330d 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -22,6 +22,7 @@ use Framadate\Services\LogService; use Framadate\Services\MailService; use Framadate\Services\PollService; use Framadate\Services\PurgeService; +use Framadate\Services\SessionService; use Framadate\Utils; include_once __DIR__ . '/app/inc/init.php'; @@ -33,6 +34,7 @@ $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp'], $config['smtp_options']); $purgeService = new PurgeService($connect, $logService); $inputService = new InputService(); +$sessionService = new SessionService(); if (is_readable('bandeaux_local.php')) { include_once('bandeaux_local.php'); @@ -233,7 +235,7 @@ switch ($step) { $purgeService->purgeOldPolls(); // creation message - $_SESSION["Framadate"]["messagePollCreated"] = TRUE; + $sessionService->set("Framadate", "messagePollCreated", TRUE); // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); From 46df3b6fce418735acb36c14b326883740dd3720 Mon Sep 17 00:00:00 2001 From: m Date: Sun, 8 Apr 2018 11:29:03 +0200 Subject: [PATCH 11/11] change test --- app/classes/Framadate/Services/PollService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 7ccfe7b..d3d6590 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -112,7 +112,7 @@ class PollService { * @return \stdClass */ function addVote($poll_id, $name, $choices, $slots_hash) { - $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name, NULL); + $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name); // Insert new vote $choices = implode($choices); @@ -298,14 +298,14 @@ class PollService { * @param $poll_id * @param $slots_hash * @param $name - * @param string|NULL $vote_id + * @param string $vote_id * @throws AlreadyExistsException * @throws ConcurrentVoteException * @throws ConcurrentEditionException */ - private function checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id) { + private function checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id = FALSE) { // Check if vote already exists with the same name - if (!isset($vote_id)) { + if (FALSE === $vote_id) { $exists = $this->voteRepository->existsByPollIdAndName($poll_id, $name); } else { $exists = $this->voteRepository->existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id);