From c6c9546669396f29e3156146eaf1ac570db15665 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Mon, 12 Oct 2015 21:42:59 +0200 Subject: [PATCH] Fix #83 Stop sorting moments at poll creation --- app/classes/Framadate/Form.php | 5 ---- .../Framadate/Services/PollService.php | 19 +++++++++++--- create_classic_poll.php | 22 ++++++++-------- create_date_poll.php | 25 ++++++++----------- locale/de.json | 3 +-- locale/en.json | 3 +-- locale/es.json | 3 +-- locale/fr.json | 3 +-- locale/it.json | 3 +-- 9 files changed, 42 insertions(+), 44 deletions(-) diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index f73cd9e..339f9e3 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -80,9 +80,4 @@ class Form usort($this->choices, array('Framadate\Choice', 'compare')); } - public function lastChoice() - { - return end($this->choices); - } - } \ No newline at end of file diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 7ca2921..120ae97 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -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; + } + } diff --git a/create_classic_poll.php b/create_classic_poll.php index c9da495..b26a298 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -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 = '
    '; @@ -180,7 +180,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( } $summary .= '
'; - $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 '
diff --git a/create_date_poll.php b/create_date_poll.php index 1cd1b57..4b6e2b9 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -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 = '