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')); 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) { uasort($slots, function ($a, $b) {
return $a->title > $b->title; return $a->title > $b->title;
}); });
return $slots;
} else {
return $slots;
} }
return $slots;
} }
public function updateVote($poll_id, $vote_id, $name, $choices) { public function updateVote($poll_id, $vote_id, $name, $choices) {
@ -180,4 +178,19 @@ class PollService {
return Token::getToken($length); 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(); bandeau_pied();
} else { } else {
$min_time = time() + 86400; // Min/Max archive date
$max_time = time() + (86400 * $config['default_poll_duration']); $min_expiry_time = $pollService->minExpiryDate();
$max_expiry_time = $pollService->maxExpiryDate();
// The poll format is AUTRE (other) // The poll format is AUTRE (other)
if ($_SESSION['form']->format !== 'A') { if ($_SESSION['form']->format !== 'A') {
@ -67,8 +68,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
// Define expiration date // Define expiration date
$enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]); $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); $min_expiry_time = time() + (24 * 60 * 60);
$max_time = time() + (86400 * $config['default_poll_duration']);
if (!empty($enddate)) { if (!empty($enddate)) {
$registredate = explode('/', $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) { if (is_array($registredate) && count($registredate) == 3) {
$time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]);
if ($time < $min_time) { if ($time < $min_expiry_time) {
$_SESSION['form']->end_date = $min_time; $_SESSION['form']->end_date = $min_expiry_time;
} elseif ($max_time < $time) { } elseif ($max_expiry_time < $time) {
$_SESSION['form']->end_date = $max_time; $_SESSION['form']->end_date = $max_expiry_time;
} else { } else {
$_SESSION['form']->end_date = $time; $_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)) { if (empty($_SESSION['form']->end_date)) {
// By default, expiration date is 6 months after last day // 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 // 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 // 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
$summary = '<ol>'; $summary = '<ol>';
@ -180,7 +180,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
} }
$summary .= '</ol>'; $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 ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'create_classic_poll.php" method="POST" class="form-horizontal" role="form"> <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'); $smarty->display('error.tpl');
} else { } else {
$min_time = time() + 86400; // Min/Max archive date
$min_expiry_time = $pollService->minExpiryDate();
$max_expiry_time = $pollService->maxExpiryDate();
// The poll format is DATE // The poll format is DATE
if ($_SESSION['form']->format !== 'D') { if ($_SESSION['form']->format !== 'D') {
@ -62,10 +64,6 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
// Define expiration date // Define expiration date
$enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]); $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)) { if (!empty($enddate)) {
$registredate = explode('/', $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) { if (is_array($registredate) && count($registredate) == 3) {
$time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]);
if ($time < $min_time) { if ($time < $min_expiry_time) {
$_SESSION['form']->end_date = $min_time; $_SESSION['form']->end_date = $min_expiry_time;
} elseif ($max_archiving_date < $time) { } elseif ($max_expiry_time < $time) {
$_SESSION['form']->end_date = $max_archiving_date; $_SESSION['form']->end_date = $max_expiry_time;
} else { } else {
$_SESSION['form']->end_date = $time; $_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)) { if (empty($_SESSION['form']->end_date)) {
// By default, expiration date is 6 months after last day // 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 // 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)') ); Utils::print_header ( __('Step 3', 'Removal date and confirmation (3 on 3)') );
bandeau_titre(__('Step 3', 'Removal date and confirmation (3 on 3)')); bandeau_titre(__('Step 3', 'Removal date and confirmation (3 on 3)'));
$_SESSION['form']->sortChoices(); $end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_expiry_time)); // textual date
$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
// Summary // Summary
$summary = '<ul>'; $summary = '<ul>';
@ -187,7 +182,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
'. $summary .' '. $summary .'
</div> </div>
<div class="alert alert-info clearfix"> <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> <br />' . __('Step 3', 'You can set a closer archiving date for it.') .'</p>
<div class="form-group"> <div class="form-group">
<label for="enddate" class="col-sm-5 control-label">'. __('Step 3', 'Archiving date:') .'</label> <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.", "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.", "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", "Create the poll": "Umfrage erstellen",
"Your poll will automatically be archived": "Ihre Umfrage wird automatisch für", "Your poll will be automatically archived in %d days.": "Ihre Umfrage wird automatisch in %d Tage archiviert werden.",
"after the last date of your poll.": "nach dem letzten Tag der Abstimmung archiviert werden.",
"You can set a closer archiving date for it.": "Sie können das Datum der Archivierung vorverlegen.", "You can set a closer archiving date for it.": "Sie können das Datum der Archivierung vorverlegen.",
"Archiving date:": "Tag der Archivierung:" "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.", "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.", "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", "Create the poll": "Create the poll",
"Your poll will automatically be archived": "Your poll will automatically be archived", "Your poll will be automatically archived in %d days.": "Your poll will be automatically archived in %d days.",
"after the last date of your poll.": "after the last date of your poll.",
"You can set a closer archiving date for it.": "You can set a specific expiry date for the poll.", "You can set a closer archiving date for it.": "You can set a specific expiry date for the poll.",
"Archiving date:": "Expiry date:" "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.", "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.", "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", "Create the poll": "Crear la encuesta",
"Your poll will automatically be archived": "ES_Votre sondage sera automatiquement archivé", "Your poll will be automatically archived in %d days.": "ES_Votre sondage sera automatiquement archivé dans %d jours.",
"after the last date of your poll.": "ES_après la date la plus tardive.",
"You can set a closer archiving date for it.": "ES_Vous pouvez décider d'une date d'archivage plus proche.", "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 :" "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.", "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.", "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", "Create the poll": "Créer le sondage",
"Your poll will automatically be archived": "Votre sondage sera automatiquement archivé", "Your poll will be automatically archived in %d days.": "Votre sondage sera automatiquement archivé dans %d jours.",
"after the last date of your poll.": "après la date la plus tardive.",
"You can set a closer archiving date for it.": "Vous pouvez décider d'une date d'archivage plus proche.", "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 :" "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.", "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.", "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", "Create the poll": "Creare il sondaggio",
"Your poll will automatically be archived": "La vostra indagine verrà archiviata automaticamente", "Your poll will be automatically archived in %d days.": "Il vostro sondaggio verrà archiviata automaticamente in %d giorni.",
"after the last date of your poll.": "dopo l'ultima data.",
"You can set a closer archiving date for it.": "Si può decidere su una data più vicina di archiviazione.", "You can set a closer archiving date for it.": "Si può decidere su una data più vicina di archiviazione.",
"Archiving date:": "Archivio Data:" "Archiving date:": "Archivio Data:"
}, },