Fix #83 Stop sorting moments at poll creation

This commit is contained in:
Olivier PEREZ 2015-10-12 21:42:59 +02:00
parent 8d543f7c23
commit c6c9546669
9 changed files with 42 additions and 44 deletions

View File

@ -80,9 +80,4 @@ class Form
usort($this->choices, array('Framadate\Choice', 'compare'));
}
public function lastChoice()
{
return end($this->choices);
}
}

View File

@ -70,10 +70,8 @@ class PollService {
uasort($slots, function ($a, $b) {
return $a->title > $b->title;
});
return $slots;
} else {
return $slots;
}
return $slots;
}
public function updateVote($poll_id, $vote_id, $name, $choices) {
@ -180,4 +178,19 @@ class PollService {
return Token::getToken($length);
}
/**
* @return int The max timestamp allowed for expiry date
*/
public function maxExpiryDate() {
global $config;
return time() + (86400 * $config['default_poll_duration']);
}
/**
* @return int The min timestamp allowed for expiry date
*/
public function minExpiryDate() {
return time() + 86400;
}
}

View File

@ -53,8 +53,9 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
bandeau_pied();
} else {
$min_time = time() + 86400;
$max_time = time() + (86400 * $config['default_poll_duration']);
// Min/Max archive date
$min_expiry_time = $pollService->minExpiryDate();
$max_expiry_time = $pollService->maxExpiryDate();
// The poll format is AUTRE (other)
if ($_SESSION['form']->format !== 'A') {
@ -67,8 +68,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
// Define expiration date
$enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]);
$min_time = time() + (24 * 60 * 60);
$max_time = time() + (86400 * $config['default_poll_duration']);
$min_expiry_time = time() + (24 * 60 * 60);
if (!empty($enddate)) {
$registredate = explode('/', $enddate);
@ -76,10 +76,10 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
if (is_array($registredate) && count($registredate) == 3) {
$time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]);
if ($time < $min_time) {
$_SESSION['form']->end_date = $min_time;
} elseif ($max_time < $time) {
$_SESSION['form']->end_date = $max_time;
if ($time < $min_expiry_time) {
$_SESSION['form']->end_date = $min_expiry_time;
} elseif ($max_expiry_time < $time) {
$_SESSION['form']->end_date = $max_expiry_time;
} else {
$_SESSION['form']->end_date = $time;
}
@ -88,7 +88,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
if (empty($_SESSION['form']->end_date)) {
// By default, expiration date is 6 months after last day
$_SESSION['form']->end_date = $max_time;
$_SESSION['form']->end_date = $max_expiry_time;
}
// Insert poll in database
@ -145,7 +145,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
}
// Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date
$_SESSION['form']->end_date = time() + (86400 * $config['default_poll_duration']); //60 sec * 60 min * 24 hours * config
$_SESSION['form']->end_date = $max_expiry_time; //60 sec * 60 min * 24 hours * config
// Summary
$summary = '<ol>';
@ -180,7 +180,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
}
$summary .= '</ol>';
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_time)); //textual date
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_expiry_time)); //textual date
echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'create_classic_poll.php" method="POST" class="form-horizontal" role="form">

View File

@ -48,7 +48,9 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
$smarty->display('error.tpl');
} else {
$min_time = time() + 86400;
// Min/Max archive date
$min_expiry_time = $pollService->minExpiryDate();
$max_expiry_time = $pollService->maxExpiryDate();
// The poll format is DATE
if ($_SESSION['form']->format !== 'D') {
@ -62,10 +64,6 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
// Define expiration date
$enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]);
// Max archive date
$_SESSION['form']->sortChoices();
$last_date = $_SESSION['form']->lastChoice()->getName();
$max_archiving_date = $last_date + (86400 * $config['default_poll_duration']);
if (!empty($enddate)) {
$registredate = explode('/', $enddate);
@ -73,10 +71,10 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
if (is_array($registredate) && count($registredate) == 3) {
$time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]);
if ($time < $min_time) {
$_SESSION['form']->end_date = $min_time;
} elseif ($max_archiving_date < $time) {
$_SESSION['form']->end_date = $max_archiving_date;
if ($time < $min_expiry_time) {
$_SESSION['form']->end_date = $min_expiry_time;
} elseif ($max_expiry_time < $time) {
$_SESSION['form']->end_date = $max_expiry_time;
} else {
$_SESSION['form']->end_date = $time;
}
@ -85,7 +83,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
if (empty($_SESSION['form']->end_date)) {
// By default, expiration date is 6 months after last day
$_SESSION['form']->end_date = $max_archiving_date;
$_SESSION['form']->end_date = $max_expiry_time;
}
// Insert poll in database
@ -156,10 +154,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
Utils::print_header ( __('Step 3', 'Removal date and confirmation (3 on 3)') );
bandeau_titre(__('Step 3', 'Removal date and confirmation (3 on 3)'));
$_SESSION['form']->sortChoices();
$last_date = $_SESSION['form']->lastChoice()->getName();
$max_archiving_date = $last_date + (86400 * $config['default_poll_duration']);
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_archiving_date)); // textual date
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_expiry_time)); // textual date
// Summary
$summary = '<ul>';
@ -187,7 +182,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
'. $summary .'
</div>
<div class="alert alert-info clearfix">
<p>' . __('Step 3', 'Your poll will automatically be archived') . ' ' . $config['default_poll_duration'] . ' ' . __('Generic', 'days') . ' ' .__('Step 3', 'after the last date of your poll.') . '
<p>' . __f('Step 3', 'Your poll will be automatically archived in %d days.', $config['default_poll_duration']) . '
<br />' . __('Step 3', 'You can set a closer archiving date for it.') .'</p>
<div class="form-group">
<label for="enddate" class="col-sm-5 control-label">'. __('Step 3', 'Archiving date:') .'</label>

View File

@ -250,8 +250,7 @@
"Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.": "Wenn Sie die Erzeugung ihrer Umfrage bestätigt haben, werden sie automatisch zur Administrationsseite ihrer Umfrage weitergeleitet.",
"Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.": "Sie werden zwei E-Mails erhalten: die Eine enthält den Link zur Umfrage für die Teilnehmer, die andere den zur Administrationsseite für Ihre Umfrage.",
"Create the poll": "Umfrage erstellen",
"Your poll will automatically be archived": "Ihre Umfrage wird automatisch für",
"after the last date of your poll.": "nach dem letzten Tag der Abstimmung archiviert werden.",
"Your poll will be automatically archived in %d days.": "Ihre Umfrage wird automatisch in %d Tage archiviert werden.",
"You can set a closer archiving date for it.": "Sie können das Datum der Archivierung vorverlegen.",
"Archiving date:": "Tag der Archivierung:"
},

View File

@ -250,8 +250,7 @@
"Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.": "Once you have confirmed the creation of your poll, you will automatically be redirected to the poll's administration page.",
"Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.": "Then you will receive two emails: one containing the link of your poll for sending to the participants, the other containing the link to the poll administration page.",
"Create the poll": "Create the poll",
"Your poll will automatically be archived": "Your poll will automatically be archived",
"after the last date of your poll.": "after the last date of your poll.",
"Your poll will be automatically archived in %d days.": "Your poll will be automatically archived in %d days.",
"You can set a closer archiving date for it.": "You can set a specific expiry date for the poll.",
"Archiving date:": "Expiry date:"
},

View File

@ -250,8 +250,7 @@
"Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.": "ES_Une fois que vous aurez confirmé la création du sondage, vous serez redirigé automatiquement vers la page d'administration de votre sondage.",
"Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.": "ES_En même temps, vous recevrez deux courriels : l'un contenant le lien vers votre sondage pour le faire suivre aux futurs sondés, l'autre contenant le lien vers la page d'administration du sondage.",
"Create the poll": "Crear la encuesta",
"Your poll will automatically be archived": "ES_Votre sondage sera automatiquement archivé",
"after the last date of your poll.": "ES_après la date la plus tardive.",
"Your poll will be automatically archived in %d days.": "ES_Votre sondage sera automatiquement archivé dans %d jours.",
"You can set a closer archiving date for it.": "ES_Vous pouvez décider d'une date d'archivage plus proche.",
"Archiving date:": "ES_Date d'archivage :"
},

View File

@ -250,8 +250,7 @@
"Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.": "Une fois que vous aurez confirmé la création du sondage, vous serez redirigé automatiquement vers la page d'administration de votre sondage.",
"Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.": "En même temps, vous recevrez deux courriels : l'un contenant le lien vers votre sondage pour le faire suivre aux futurs sondés, l'autre contenant le lien vers la page d'administration du sondage.",
"Create the poll": "Créer le sondage",
"Your poll will automatically be archived": "Votre sondage sera automatiquement archivé",
"after the last date of your poll.": "après la date la plus tardive.",
"Your poll will be automatically archived in %d days.": "Votre sondage sera automatiquement archivé dans %d jours.",
"You can set a closer archiving date for it.": "Vous pouvez décider d'une date d'archivage plus proche.",
"Archiving date:": "Date d'archivage :"
},

View File

@ -250,8 +250,7 @@
"Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.": "Un volta che avrete confermato la creazione del sondaggio, sarete rediretti automaticamente sulla pagina di amministrazione del vostro sondaggio.",
"Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.": "Nello stesso momento, riceverete 2 email : una con il Link verso il vostro sondaggio da inoltrare ai partecipanti, l'altra con il Link verso la pagina di amministrazione del sondaggio.",
"Create the poll": "Creare il sondaggio",
"Your poll will automatically be archived": "La vostra indagine verrà archiviata automaticamente",
"after the last date of your poll.": "dopo l'ultima data.",
"Your poll will be automatically archived in %d days.": "Il vostro sondaggio verrà archiviata automaticamente in %d giorni.",
"You can set a closer archiving date for it.": "Si può decidere su una data più vicina di archiviazione.",
"Archiving date:": "Archivio Data:"
},