From 65c0691c7e4e17f816d09006c197dc5f8e0c40a5 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 11 Nov 2019 12:38:11 +0100 Subject: [PATCH] Rename ValueMax to value_max Signed-off-by: Thomas Citharel --- app/classes/Framadate/Form.php | 4 +- .../Migrations/Version20191111110000.php | 87 +++++++++++++++++++ .../Framadate/Repositories/PollRepository.php | 2 +- .../Framadate/Services/PollService.php | 2 +- app/inc/i18n.php | 6 +- create_poll.php | 32 +++---- js/app/create_poll.js | 8 +- studs.php | 2 +- tpl/part/create_poll/value_max.tpl | 18 ++-- tpl/part/vote_table_classic.tpl | 2 +- tpl/part/vote_table_date.tpl | 2 +- 11 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 app/classes/Framadate/Migrations/Version20191111110000.php diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index b35e925..a05f601 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -40,7 +40,7 @@ class Form public $creation_date; public $choix_sondage; - public $ValueMax; + public $value_max; public $errors = []; /** @@ -63,7 +63,7 @@ class Form * If true, only the poll maker can see the poll's results * @var boolean */ - public $use_ValueMax; + public $use_value_max; /** * if true, there will be a limit of voters per option diff --git a/app/classes/Framadate/Migrations/Version20191111110000.php b/app/classes/Framadate/Migrations/Version20191111110000.php new file mode 100644 index 0000000..745d62e --- /dev/null +++ b/app/classes/Framadate/Migrations/Version20191111110000.php @@ -0,0 +1,87 @@ +getTable(Utils::table('poll')); + $pollTable->addColumn('value_max', 'smallint', ['default' => null, 'notnull' => false]); + } + + /** + * @param Schema $schema + * @throws DBALException + */ + public function postUp(Schema $schema): void + { + $pollTable = $schema->getTable(Utils::table('poll')); + $this->addSql('UPDATE ' . Utils::table('poll') . ' SET value_max = ValueMax'); + $pollTable->dropColumn('ValueMax'); + } + + /** + * @param Schema $schema + * @throws SchemaException + */ + public function down(Schema $schema): void + { + $pollTable = $schema->getTable(Utils::table('poll')); + $pollTable->addColumn('ValueMax', 'smallint', ['default' => null, 'notnull' => false]); + } + + /** + * @param Schema $schema + * @throws DBALException + */ + public function postDown(Schema $schema): void + { + $pollTable = $schema->getTable(Utils::table('poll')); + $this->addSql('UPDATE ' . Utils::table('poll') . ' SET ValueMax = value_max'); + $pollTable->dropColumn('value_max'); + } +} diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php index 78d0860..9d7b0f2 100644 --- a/app/classes/Framadate/Repositories/PollRepository.php +++ b/app/classes/Framadate/Repositories/PollRepository.php @@ -33,7 +33,7 @@ class PollRepository extends AbstractRepository { 'hidden' => $form->hidden ? 1 : 0, 'password_hash' => $form->password_hash, 'results_publicly_visible' => $form->results_publicly_visible ? 1 : 0, - 'ValueMax' => $form->ValueMax, + 'value_max' => $form->value_max, 'collect_users_mail' => ($form->collect_users_mail >= 0 && $form->collect_users_mail <= 3) ? $form->collect_users_mail : 0, ]); } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 130669c..2b896b8 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -482,7 +482,7 @@ class PollService { $best_choices = $this->computeBestChoices($votes, $poll); foreach ($best_choices['y'] as $i => $nb_choice) { // if for this option we have reached maximum value and user wants to add itself too - if ($poll->ValueMax !== null && $nb_choice >= $poll->ValueMax && $user_choice[$i] === "2") { + if ($poll->value_max !== null && $nb_choice >= $poll->value_max && $user_choice[$i] === "2") { throw new ConcurrentVoteException(); } } diff --git a/app/inc/i18n.php b/app/inc/i18n.php index 85872fa..cb4abac 100644 --- a/app/inc/i18n.php +++ b/app/inc/i18n.php @@ -35,10 +35,10 @@ if (isset($_SESSION['lang'])) { $wanted_locale = $_SESSION['lang']; } else { $http_lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? DEFAULT_LANGUAGE; - $wanted_locale = locale_accept_from_http($http_lang); + $wanted_locale = Locale::acceptFromHttp($http_lang); } // Use the best available locale. -$locale = locale_lookup(array_keys($ALLOWED_LANGUAGES), $wanted_locale, false, DEFAULT_LANGUAGE); +$locale = Locale::lookup(array_keys($ALLOWED_LANGUAGES), $wanted_locale, false, DEFAULT_LANGUAGE); /** * Formats a DateTime according to the IntlDateFormatter @@ -120,7 +120,9 @@ use Symfony\Component\Translation\Loader\PoFileLoader; use Symfony\Component\Translation\Translator; class __i18n { + /* @var Translator */ private static $translator; + /* @var Translator */ private static $fallbacktranslator; public static function init($locale) { diff --git a/create_poll.php b/create_poll.php index 167208e..fb3c171 100644 --- a/create_poll.php +++ b/create_poll.php @@ -54,8 +54,8 @@ $goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['op if ($goToStep2) { $title = $inputService->filterTitle($_POST['title']); - $use_ValueMax = isset($_POST['use_ValueMax']) ? $inputService->filterBoolean($_POST['use_ValueMax']) : false; - $ValueMax = $use_ValueMax === true ? $inputService->filterValueMax($_POST['ValueMax']) : null; + $use_value_max = isset($_POST['use_value_max']) ? $inputService->filterBoolean($_POST['use_value_max']) : false; + $value_max = $use_value_max === true ? $inputService->filterValueMax($_POST['value_max']) : null; $use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false; $customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null; @@ -81,13 +81,13 @@ if ($goToStep2) { $error_on_password = false; $error_on_password_repeat = false; $error_on_customized_url = false; - $error_on_ValueMax = false; + $error_on_value_max = false; $form->title = $title; $form->id = $customized_url; $form->use_customized_url = $use_customized_url; - $form->use_ValueMax = $use_ValueMax; - $form->ValueMax = $ValueMax; + $form->use_value_max = $use_value_max; + $form->value_max = $value_max; $form->admin_name = $name; $form->admin_mail = $mail; $form->description = $description; @@ -119,8 +119,8 @@ if ($goToStep2) { } } - if ($use_ValueMax && $ValueMax === false) { - $error_on_ValueMax = true; + if ($use_value_max && $value_max === false) { + $error_on_value_max = true; } if ($name !== $_POST['name']) { @@ -147,7 +147,7 @@ if ($goToStep2) { } if ($title && $name && $email_OK && !$error_on_title && !$error_on_customized_url && !$error_on_description && !$error_on_name - && !$error_on_password && !$error_on_password_repeat &&!$error_on_ValueMax + && !$error_on_password && !$error_on_password_repeat &&!$error_on_value_max ) { // If no errors, we hash the password if needed if ($form->use_password) { @@ -209,7 +209,7 @@ $errors = [ 'aria' => '', 'class' => '' ], - 'ValueMax' => [ + 'value_max' => [ 'msg' => '', 'aria' => '', 'class' => '' @@ -274,10 +274,10 @@ if (!empty($_POST[GO_TO_STEP_2])) { $errors['password_repeat']['class'] = ' has-error'; $errors['password_repeat']['msg'] = t('Error', 'Passwords do not match.'); } - if ($error_on_ValueMax) { - $errors['ValueMax']['aria'] = 'aria-describeby="poll_ValueMax" '; - $errors['ValueMax']['class'] = ' has-error'; - $errors['ValueMax']['msg'] = t('Error', 'Error on amount of votes limitation: Value must be an integer greater than 0'); + if ($error_on_value_max) { + $errors['value_max']['aria'] = 'aria-describeby="poll_value_max" '; + $errors['value_max']['class'] = ' has-error'; + $errors['value_max']['msg'] = t('Error', 'Error on amount of votes limitation: Value must be an integer greater than 0'); } } @@ -286,7 +286,7 @@ $useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']); $smarty->assign('title', $title); $smarty->assign('useRemoteUser', $useRemoteUser); $smarty->assign('errors', $errors); -$smarty->assign('advanced_errors', $goToStep2 && ($error_on_ValueMax || $error_on_customized_url || $error_on_password || $error_on_password_repeat)); +$smarty->assign('advanced_errors', $goToStep2 && ($error_on_value_max || $error_on_customized_url || $error_on_password || $error_on_password_repeat)); $smarty->assign('use_smtp', $config['use_smtp']); $smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']); $smarty->assign('goToStep2', GO_TO_STEP_2); @@ -295,8 +295,8 @@ $smarty->assign('poll_type', $poll_type); $smarty->assign('poll_title', Utils::fromPostOrDefault('title', $form->title)); $smarty->assign('customized_url', Utils::fromPostOrDefault('customized_url', $form->id)); $smarty->assign('use_customized_url', Utils::fromPostOrDefault('use_customized_url', $form->use_customized_url)); -$smarty->assign('ValueMax', Utils::fromPostOrDefault('ValueMax', $form->ValueMax)); -$smarty->assign('use_ValueMax', Utils::fromPostOrDefault('use_ValueMax', $form->use_ValueMax)); +$smarty->assign('value_max', Utils::fromPostOrDefault('value_max', $form->value_max)); +$smarty->assign('use_value_max', Utils::fromPostOrDefault('use_value_max', $form->use_value_max)); $smarty->assign('collect_users_mail', Utils::fromPostOrDefault('collect_users_mail', $form->collect_users_mail)); $smarty->assign('poll_description', !empty($_POST['description']) ? $_POST['description'] : $form->description); $smarty->assign('poll_name', Utils::fromPostOrDefault('name', $form->admin_name)); diff --git a/js/app/create_poll.js b/js/app/create_poll.js index 7368112..39ef369 100644 --- a/js/app/create_poll.js +++ b/js/app/create_poll.js @@ -56,13 +56,13 @@ $(document).ready(function () { }); /** - * Enable/Disable ValueMax options + * Enable/Disable value_max options */ - $("#use_ValueMax").change(function () { + $("#use_value_max").change(function () { if ($(this).prop("checked")) { - $("#valueMaxWrapper").removeClass("hidden"); + $("#value_max_wrapper").removeClass("hidden"); } else { - $("#valueMaxWrapper").addClass("hidden"); + $("#value_max_wrapper").addClass("hidden"); } }); diff --git a/studs.php b/studs.php index ed99ac7..87a003b 100644 --- a/studs.php +++ b/studs.php @@ -246,7 +246,7 @@ $smarty->assign('hidden', $poll->hidden); $smarty->assign('accessGranted', $accessGranted); $smarty->assign('resultPubliclyVisible', $resultPubliclyVisible); $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); -$smarty->assign('ValueMax', $poll->ValueMax); +$smarty->assign('value_max', $poll->value_max); $smarty->assign('selectedNewVotes', $selectedNewVotes); $smarty->display('studs.tpl'); diff --git a/tpl/part/create_poll/value_max.tpl b/tpl/part/create_poll/value_max.tpl index a9fecfb..67aafbc 100644 --- a/tpl/part/create_poll/value_max.tpl +++ b/tpl/part/create_poll/value_max.tpl @@ -1,26 +1,26 @@ {* Value MAX *} -
+
-
-
+
+
@@ -29,10 +29,10 @@
-{if !empty($errors['ValueMax']['msg'])} +{if !empty($errors['value_max']['msg'])}

- {$errors['ValueMax']['msg']} + {$errors['value_max']['msg']}

{/if} diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index a9c6a47..2a49a24 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -227,7 +227,7 @@ {foreach $slots as $id=>$slot}
    - {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax} + {if $poll->value_max eq NULL || $best_choices['y'][$i] lt $poll->value_max}
    • - {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax} + {if $poll->value_max eq NULL || $best_choices['y'][$i] lt $poll->value_max}