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/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index a5f147f..35e40c7 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -202,7 +202,7 @@ class AdminPollService { $this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment); $slots = $this->slotRepository->listByPollId($poll_id); - $result = $this->findInsertPosition($slots, $datetime, $new_moment); + $result = $this->findInsertPosition($slots, $datetime); // Begin transaction $this->connect->beginTransaction(); @@ -221,7 +221,6 @@ class AdminPollService { // Update found slot $moments[] = $new_moment; - sort($moments); $this->slotRepository->update($poll_id, $datetime, implode(',', $moments)); } else { @@ -284,10 +283,9 @@ class AdminPollService { * * @param $slots array All the slots of the poll * @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. */ - private function findInsertPosition($slots, $datetime, $moment) { + private function findInsertPosition($slots, $datetime) { $result = new \stdClass(); $result->slot = null; $result->insert = -1; @@ -299,21 +297,10 @@ class AdminPollService { $moments = explode(',', $slot->moments); if ($datetime == $rowDatetime) { - $result->slot = $slot; - - 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++; - } + $i += count($moments); // Here we have to insert at the end of a slot + $result->slot = $slot; $result->insert = $i; break; } elseif ($datetime < $rowDatetime) { 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..ffaaeca 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,6 @@ 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']); if (!empty($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) { $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 +87,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 +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 - $_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 = '
    '; @@ -180,7 +179,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 = '