From f9194df3322ef12b1bee2bf7a000816849470c43 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Aug 2021 00:39:32 -0600 Subject: [PATCH] Update PollService --- app/Services/PollService.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Services/PollService.php b/app/Services/PollService.php index 1cb4b56b2..8c30af7dc 100644 --- a/app/Services/PollService.php +++ b/app/Services/PollService.php @@ -63,6 +63,31 @@ class PollService ->exists(); } + public static function votedStory($id, $profileId = false) + { + return !$profileId ? false : PollVote::whereStoryId($id) + ->whereProfileId($profileId) + ->exists(); + } + + public static function storyResults($sid) + { + $key = self::CACHE_KEY . 'story_poll_results:' . $sid; + return Cache::remember($key, 60, function() use($sid) { + return Poll::whereStoryId($sid) + ->firstOrFail() + ->cached_tallies; + }); + } + + public static function storyChoice($id, $profileId = false) + { + return !$profileId ? false : PollVote::whereStoryId($id) + ->whereProfileId($profileId) + ->pluck('choice') + ->first(); + } + public static function ownVotes($id, $profileId = false) { return !$profileId ? [] : PollVote::whereStatusId($id)