/** * Execute the console command. * * @return mixed */ public function handle() { $voteoptions = Voteoption::all(); $votes = Vote::all(); $members = Votemember::all(); $groups = Votegroup::all(); $score = []; foreach ($votes as $vote) { foreach ($voteoptions as $voteoption) { if ($vote['voteoption_hash'] == $voteoption['hash']) { $score[] = $voteoption['votemember_id']; } } } $score = array_count_values($score); foreach ($score as $key => $vote) { foreach ($members as $member) { if ($member['id'] == $key) { $member['votes'] = $vote; } foreach ($groups as $group) { if ($group['id'] == $member['votegroup_id']) { $member['group'] = $group['name']; } } } foreach ($members as $member) { if (!isset($member['votes'])) { $member['votes'] = 0; } } } Storage::disk('local')->put('votes.json', json_encode($members)); $groups = $members; $groupscore = []; foreach ($groups as $group) { if (isset($groupscore[$group['group']])) { $groupscore[$group['group']]['votes'] = $groupscore[$group['group']]['votes'] + $group['votes']; } else { $rand = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; $color = '#' . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)]; $groupscore[$group['group']] = ['votes' => $group['votes'], 'color' => $color]; } } $totalvotes = Vote::count(); foreach ($groupscore as $key => $group) { $groupscore[$key]['cut'] = $groupscore[$key]['votes'] / $totalvotes * 100; } Storage::disk('local')->put('groupvotes.json', json_encode($groupscore)); $this->info("All votes are counted and saved in votes.json"); }
/** * Show the application dashboard to the user. * * @return Response */ public function getindex() { //$number = Voteoption::orderBy('created_at', 'desc')->first()->versionnumber; $options = Votegroup::all(); return view('voting')->with('options', $options); }
public function run() { $votegroups = [['id' => 1, 'name' => 'CDA'], ['id' => 2, 'name' => 'PVV'], ['id' => 3, 'name' => '50PLUS'], ['id' => 4, 'name' => 'PvdA'], ['id' => 5, 'name' => 'VVD'], ['id' => 6, 'name' => 'SP'], ['id' => 7, 'name' => 'GroenLinks'], ['id' => 8, 'name' => 'D66'], ['id' => 9, 'name' => 'ChristenUnie'], ['id' => 10, 'name' => 'Partij voor de Dieren'], ['id' => 11, 'name' => 'SGP'], ['id' => 12, 'name' => 'OSF']]; Votegroup::insert($votegroups); }