Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $this->call('VoteGroupTableSeeder');
     $this->call('VoteMemberTableSeeder');
     Voteoption::create(['versionnumber' => '0', 'hash' => '-', 'votemember_id' => '0']);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info("Generating new hashes");
     $members = Votemember::all();
     if (!($versionnumber = Voteoption::orderBy('created_at', 'desc')->first()->versionnumber + 1)) {
         $versionnumber = 0;
     }
     foreach ($members as $member) {
         $voteopt = new Voteoption();
         $voteopt->hash = Hash::make(date('Yis') . str_random(20) . date('siY'));
         $voteopt->form_hash = Hash::make(date('Yis') . str_random(20) . date('siY'));
         $voteopt->votemember_id = $member->id;
         $voteopt->versionnumber = $versionnumber;
         $voteopt->save();
     }
     $this->info("Done!");
 }
Example #3
0
 /**
  * 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");
 }
Example #4
0
 public function postindex()
 {
     $request = Request::input('voteoption');
     $number = Voteoption::orderBy('created_at', 'desc')->first()->versionnumber;
     $check = Voteoption::where('form_hash', $request)->first();
     if ($number != $check->versionnumber) {
         return view('voting')->with('errors', ['Er is een fout opgetreden. Probeer het opnieuw. code: h4cx']);
     }
     $vote = new Vote();
     $vote->voteoption_hash = $check->hash;
     $vote->ip = $_SERVER['REMOTE_ADDR'];
     $vote->save();
     return redirect('voted');
 }
Example #5
0
 static function gethash($id)
 {
     $number = Voteoption::orderBy('created_at', 'desc')->first()->versionnumber;
     return Voteoption::where('versionnumber', $number)->where('votemember_id', $id)->first()->form_hash;
 }