From 49a5350f90d296f6f50041bd28c0d321c443b273 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ <olivier@olivierperez.fr> Date: Mon, 12 Oct 2015 22:42:07 +0200 Subject: [PATCH] Fix #83 Stop sorting moments at new slot insertion --- .../Framadate/Services/AdminPollService.php | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index a5f147fe..35e40c7e 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) { -- GitLab