Merge branch 'master' into develop

This commit is contained in:
Olivier PEREZ 2015-10-12 23:58:57 +02:00
commit fe8f779217
10 changed files with 45 additions and 61 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

@ -202,7 +202,7 @@ class AdminPollService {
$this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment); $this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment);
$slots = $this->slotRepository->listByPollId($poll_id); $slots = $this->slotRepository->listByPollId($poll_id);
$result = $this->findInsertPosition($slots, $datetime, $new_moment); $result = $this->findInsertPosition($slots, $datetime);
// Begin transaction // Begin transaction
$this->connect->beginTransaction(); $this->connect->beginTransaction();
@ -221,7 +221,6 @@ class AdminPollService {
// Update found slot // Update found slot
$moments[] = $new_moment; $moments[] = $new_moment;
sort($moments);
$this->slotRepository->update($poll_id, $datetime, implode(',', $moments)); $this->slotRepository->update($poll_id, $datetime, implode(',', $moments));
} else { } else {
@ -284,10 +283,9 @@ class AdminPollService {
* *
* @param $slots array All the slots of the poll * @param $slots array All the slots of the poll
* @param $datetime int The datetime of the new slot * @param $datetime int The datetime of the new slot
* @param $moment string The moment's name
* @return null|\stdClass An object like this one: {insert:X, slot:Y} where Y can be null. * @return null|\stdClass An object like this one: {insert:X, slot:Y} where Y can be null.
*/ */
private function findInsertPosition($slots, $datetime, $moment) { private function findInsertPosition($slots, $datetime) {
$result = new \stdClass(); $result = new \stdClass();
$result->slot = null; $result->slot = null;
$result->insert = -1; $result->insert = -1;
@ -299,21 +297,10 @@ class AdminPollService {
$moments = explode(',', $slot->moments); $moments = explode(',', $slot->moments);
if ($datetime == $rowDatetime) { if ($datetime == $rowDatetime) {
$result->slot = $slot; $i += count($moments);
foreach ($moments as $rowMoment) {
$strcmp = strcmp($moment, $rowMoment);
if ($strcmp < 0) {
// Here we have to insert at First place or middle of the slot
break(2);
} elseif ($strcmp == 0) {
// Here we dont have to insert at all
return null;
}
$i++;
}
// Here we have to insert at the end of a slot // Here we have to insert at the end of a slot
$result->slot = $slot;
$result->insert = $i; $result->insert = $i;
break; break;
} elseif ($datetime < $rowDatetime) { } elseif ($datetime < $rowDatetime) {

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,6 @@ 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);
$max_time = time() + (86400 * $config['default_poll_duration']);
if (!empty($enddate)) { if (!empty($enddate)) {
$registredate = explode('/', $enddate); $registredate = explode('/', $enddate);
@ -76,10 +75,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 +87,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 +144,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;
// Summary // Summary
$summary = '<ol>'; $summary = '<ol>';
@ -180,7 +179,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

@ -251,8 +251,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

@ -251,8 +251,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

@ -251,8 +251,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

@ -251,8 +251,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

@ -251,8 +251,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:"
}, },