connect = $connect; $this->pollService = $pollService; $this->logService = $logService; } function updatePoll($poll) { return $this->connect->updatePoll($poll); } /** * Delete a comment from a poll. * * @param $poll_id int The ID of the poll * @param $comment_id int The ID of the comment * @return mixed true is action succeeded */ function deleteComment($poll_id, $comment_id) { return $this->connect->deleteComment($poll_id, $comment_id); } /** * Remove all comments of a poll. * * @param $poll_id int The ID a the poll * @return bool|null true is action succeeded */ function cleanComments($poll_id) { $this->logService->log("CLEAN_COMMENTS", "id:$poll_id"); return $this->connect->deleteCommentsByPollId($poll_id); } /** * Delete a vote from a poll. * * @param $poll_id int The ID of the poll * @param $vote_id int The ID of the vote * @return mixed true is action succeeded */ function deleteVote($poll_id, $vote_id) { return $this->connect->deleteVote($poll_id, $vote_id); } /** * Remove all votes of a poll. * * @param $poll_id int The ID of the poll * @return bool|null true is action succeeded */ function cleanVotes($poll_id) { $this->logService->log('CLEAN_VOTES', 'id:' . $poll_id); return $this->connect->deleteVotesByPollId($poll_id); } /** * Delete the entire given poll. * * @param $poll_id int The ID of the poll * @return bool true is action succeeded */ function deleteEntirePoll($poll_id) { $poll = $this->connect->findPollById($poll_id); $this->logService->log('DELETE_POLL', "id:$poll->id, format:$poll->format, admin:$poll->admin_name, mail:$poll->admin_mail"); // Delete the entire poll $this->connect->deleteVotesByPollId($poll_id); $this->connect->deleteCommentsByPollId($poll_id); $this->connect->deleteSlotsByPollId($poll_id); $this->connect->deletePollById($poll_id); return true; } /** * Delete a slot from a poll. * * @param $poll_id int The ID of the poll * @param $slot object The slot informations (datetime + moment) * @return bool true if action succeeded */ public function deleteDateSlot($poll_id, $slot) { $this->logService->log('DELETE_SLOT', 'id:' . $poll_id . ', slot:' . json_encode($slot)); $datetime = $slot->title; $moment = $slot->moment; $slots = $this->pollService->allSlotsByPollId($poll_id); $index = 0; $indexToDelete = -1; $newMoments = []; // Search the index of the slot to delete foreach ($slots as $aSlot) { $moments = explode(',', $aSlot->moments); foreach ($moments as $rowMoment) { if ($datetime == $aSlot->title) { if ($moment == $rowMoment) { $indexToDelete = $index; } else { $newMoments[] = $rowMoment; } } $index++; } } // Remove votes $this->connect->beginTransaction(); $this->connect->deleteVotesByIndex($poll_id, $indexToDelete); if (count($newMoments) > 0) { $this->connect->updateSlot($poll_id, $datetime, implode(',', $newMoments)); } else { $this->connect->deleteSlot($poll_id, $datetime); } $this->connect->commit(); 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. *