From f399b9e543840881fc5daf8ff01017b2ae117784 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Tue, 30 Dec 2014 17:03:43 +0100 Subject: [PATCH] admin: fix deleteion a slot from a classical poll --- adminstuds.php | 14 +++++++- .../Framadate/Services/AdminPollService.php | 35 ++++++++++++++++--- tpl/part/vote_table_classic.tpl | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 812df0c..cc8aefd 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -287,7 +287,19 @@ if (isset($_POST['confirm_delete_poll'])) { if (!empty($_POST['delete_column'])) { $column = filter_input(INPUT_POST, 'delete_column', FILTER_DEFAULT); - if ($adminPollService->deleteSlot($poll_id, $column)) { + if ($poll->format === 'D') { + $ex = explode('@', $column); + + $slot = new stdClass(); + $slot->title = $ex[0]; + $slot->moment = $ex[1]; + + $result = $adminPollService->deleteDateSlot($poll_id, $slot); + } else { + $result = $adminPollService->deleteClassicSlot($poll_id, $column); + } + + if ($result) { $message = new Message('success', _('Column deleted.')); } else { $message = new Message('danger', _('Failed to delete the column.')); diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index 48d2502..3926362 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -92,14 +92,14 @@ class AdminPollService { * Delete a slot from a poll. * * @param $poll_id int The ID of the poll - * @param $slot string The name of the slot + * @param $slot object The slot informations (datetime + moment) * @return bool true if action succeeded */ - public function deleteSlot($poll_id, $slot) { + public function deleteDateSlot($poll_id, $slot) { $this->logService->log('DELETE_SLOT', 'id:' . $poll_id . ', slot:' . json_encode($slot)); - $ex = explode('@', $slot); - $datetime = $ex[0]; - $moment = $ex[1]; + + $datetime = $slot->title; + $moment = $slot->moment; $slots = $this->pollService->allSlotsByPollId($poll_id); @@ -136,6 +136,31 @@ class AdminPollService { return true; } + public function deleteClassicSlot($poll_id, $slot_title) { + $this->logService->log('DELETE_SLOT', 'id:' . $poll_id . ', slot:' . $slot_title); + + $slots = $this->pollService->allSlotsByPollId($poll_id); + + $index = 0; + $indexToDelete = -1; + + // Search the index of the slot to delete + foreach ($slots as $aSlot) { + if ($slot_title == $aSlot->title) { + $indexToDelete = $index; + } + $index++; + } + + // Remove votes + $this->connect->beginTransaction(); + $this->connect->deleteVotesByIndex($poll_id, $indexToDelete); + $this->connect->deleteSlot($poll_id, $slot_title); + $this->connect->commit(); + + return true; + } + /** * Add a new slot to the poll. And insert default values for user's votes. *