Rename ValueMax to value_max

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-11-11 12:38:11 +01:00
parent 0e90422b3d
commit 65c0691c7e
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
11 changed files with 127 additions and 38 deletions

View file

@ -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

View file

@ -0,0 +1,87 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
namespace DoctrineMigrations;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Framadate\AbstractMigration;
use Framadate\Utils;
/**
* This migration renames the column ValueMax to value_max
*
* @package Framadate\Migration
* @version 1.2
*/
class Version20191111110000 extends AbstractMigration
{
/**
* This method should describe in english what is the purpose of the migration class.
*
* @return string The description of the migration class
*/
public function description()
{
return 'Rename the column ValueMax to value_max';
}
/**
* @param Schema $schema
* @throws SchemaException
* @throws DBALException
*/
public function up(Schema $schema): void
{
$pollTable = $schema->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');
}
}

View file

@ -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,
]);
}

View file

@ -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();
}
}

View file

@ -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) {

View file

@ -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));

View file

@ -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");
}
});

View file

@ -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');

View file

@ -1,26 +1,26 @@
{* Value MAX *}
<div class="form-group {$errors['ValueMax']['class']}">
<div class="form-group {$errors['value_max']['class']}">
<label for="use_valueMax" class="col-sm-4 control-label">
{t('Step 1', 'Value Max')}<br/>
</label>
<div class="col-sm-8">
<div class="checkbox">
<label>
<input id="use_ValueMax" name="use_ValueMax" type="checkbox"
{if $use_ValueMax}checked{/if}>
<input id="use_value_max" name="use_value_max" type="checkbox"
{if $use_value_max}checked{/if}>
{t('Step 1', "Limit the amount of voters per option")}
</label>
</div>
</div>
</div>
<div class="form-group {$errors['ValueMax']['class']}">
<div {if !$use_ValueMax}class="hidden"{/if} id="valueMaxWrapper">
<div class="form-group {$errors['value_max']['class']}">
<div {if !$use_value_max}class="hidden"{/if} id="value_max_wrapper">
<div class="col-sm-offset-4 col-sm-8">
<label>
<input id="ValueMax" type="number" min="1" name="ValueMax"
value="{$ValueMax|html}" {$errors['ValueMax']['aria']}>
<input id="value_max" type="number" min="1" name="value_max"
value="{$value_max|html}" {$errors['value_max']['aria']}>
{t('Step 1', 'votes per option')}
</label>
@ -29,10 +29,10 @@
</div>
</div>
{if !empty($errors['ValueMax']['msg'])}
{if !empty($errors['value_max']['msg'])}
<div class="alert alert-danger">
<p id="poll_customized_url_error">
{$errors['ValueMax']['msg']}
{$errors['value_max']['msg']}
</p>
</div>
{/if}

View file

@ -227,7 +227,7 @@
{foreach $slots as $id=>$slot}
<td class="bg-info" headers="C{$id}">
<ul class="list-unstyled choice">
{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}
<li class="yes">
<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2"
{(!isset($selectedNewVotes[$id]) || ("2" !== $selectedNewVotes[$id])) ? "" : " checked"}

View file

@ -287,7 +287,7 @@
<td class="bg-info" headers="M{$headersM[$i]} D{$headersD[$i]} H{$headersH[$i]}">
<ul class="list-unstyled choice">
{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}
<li class="yes">
<input type="radio" id="y-choice-{$i}" name="choices[{$i}]" value="2"
{(!isset($selectedNewVotes[$i]) || ("2" !== $selectedNewVotes[$i])) ? "" : " checked"}