From 93b9411c99866c56a3fcc52238758d95cc4f4050 Mon Sep 17 00:00:00 2001 From: RundelhausCode Date: Fri, 5 Mar 2021 13:00:07 +0100 Subject: [PATCH] voting --- Backend/Models/GameData.php | 2 +- Backend/Models/Group.php | 4 ++++ Backend/Models/Password.php | 2 +- Backend/Models/Vote.php | 19 +++++++++++++++++ Backend/Polls/1vote.php | 27 ++++++++++++++++++++++++ Backend/Polls/321vote.php | 38 ++++++++++++++++++++++++++++++++++ Backend/Polls/VoteChecking.php | 10 +++++++++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 Backend/Models/Vote.php create mode 100644 Backend/Polls/1vote.php create mode 100644 Backend/Polls/321vote.php create mode 100644 Backend/Polls/VoteChecking.php diff --git a/Backend/Models/GameData.php b/Backend/Models/GameData.php index c368455..f43a687 100644 --- a/Backend/Models/GameData.php +++ b/Backend/Models/GameData.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model as Eloquent; class GameData extends Eloquent { protected $fillable = [ - 'gameLink', 'isWebBased' + 'gameLink', 'isWebBased', "img" ]; public function group(){ diff --git a/Backend/Models/Group.php b/Backend/Models/Group.php index dd0df3f..a7681c5 100644 --- a/Backend/Models/Group.php +++ b/Backend/Models/Group.php @@ -19,4 +19,8 @@ class Group extends Eloquent public function password(){ return $this->hasOne(Password::class); } + public function vote(){ + return $this->hasMany(Vote::class); + } + } diff --git a/Backend/Models/Password.php b/Backend/Models/Password.php index 58e9b42..730a308 100644 --- a/Backend/Models/Password.php +++ b/Backend/Models/Password.php @@ -3,7 +3,7 @@ namespace Backend\Models; use Illuminate\Database\Eloquent\Model as Eloquent; class Password extends Eloquent{ protected $fillable =[ - 'password' + 'password', 'remember_token' ]; diff --git a/Backend/Models/Vote.php b/Backend/Models/Vote.php new file mode 100644 index 0000000..f2a67b2 --- /dev/null +++ b/Backend/Models/Vote.php @@ -0,0 +1,19 @@ +belongsTo(Group::class); + } + +} \ No newline at end of file diff --git a/Backend/Polls/1vote.php b/Backend/Polls/1vote.php new file mode 100644 index 0000000..41d274d --- /dev/null +++ b/Backend/Polls/1vote.php @@ -0,0 +1,27 @@ +group()->associate(Group::find($_POST['groupId'])); + $vote->points += 1; + if(!empty($_POST['comment'])){ + $vote->comment = $_POST['comment']; + } + $vote->save(); + +} + + + + + + + + diff --git a/Backend/Polls/321vote.php b/Backend/Polls/321vote.php new file mode 100644 index 0000000..018a550 --- /dev/null +++ b/Backend/Polls/321vote.php @@ -0,0 +1,38 @@ +group()->associate(Group::find($_POST['1pGroupId'])); + $vote->points += 1; + if(!empty($_POST['1pComment'])){ + $vote->comment = $_POST['1pComment']; + } + $vote->save(); + //give 2 point + $vote = new Vote(); + $vote->group()->associate(Group::find($_POST['2pGroupId'])); + $vote->points += 2; + if(!empty($_POST['2pComment'])){ + $vote->comment = $_POST['2pComment']; + } + $vote->save(); + //give 3 point + $vote = new Vote(); + $vote->group()->associate(Group::find($_POST['3pGroupId'])); + $vote->points += 3; + if(!empty($_POST['3pComment'])){ + $vote->comment = $_POST['3pComment']; + } + $vote->save(); + + + +} diff --git a/Backend/Polls/VoteChecking.php b/Backend/Polls/VoteChecking.php new file mode 100644 index 0000000..c8dbc35 --- /dev/null +++ b/Backend/Polls/VoteChecking.php @@ -0,0 +1,10 @@ +