/** * Saves an answer to the database, for the specified vote type * * @param $answer The answer to save to database * @param $vtid ID of the vote type that this answer belongs to */ public function saveVoteTypeAnswer($answer, $vtid) { if ($answer != '') { VoteTypeAnswer::create(['type' => $vtid, 'answer' => $answer]); } }
/** * Gathers all the votes of a voting * * @param $voting The voting to gather votes for * @param $useName Set true if you want to use name to identify members, or false if you want to use the id * @return array The formatted array */ private function gatherMemberVotes($voting, $useName) { $memberVotes = []; if ($voting->votes->count() > 0) { $members = Member::orderBy('district_id')->orderBy('order')->get(); // get members sorted based on their district, then order $votingId = $voting->id; foreach ($members as $member) { // Create member info array and add full name to it $m = []; if ($useName) { $m['fullname'] = $member->first_name . ' ' . $member->last_name; } else { $m['id'] = $member->id; } // Add the votes of this member for each voting item $votes = Vote::where(['member_id' => $member->id, 'voting_id' => $votingId])->get(); foreach ($votes as $vote) { $ansId = $vote->answer_id; if ($ansId != null) { $m[$vote->voting_item_id] = VoteTypeAnswer::findOrFail($ansId)->answer; } else { $m[$vote->voting_item_id] = null; } } $memberVotes[] = $m; } } return $memberVotes; }