From 2ad2f32d07b5cb4009950afea063927b4f8723eb Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 18 Jan 2018 15:15:31 +0100 Subject: [PATCH] Working on Manual Payout Winner Selection --- .../Http/Controllers/SeasonsController.php | 35 ++++++++++++++++--- pfosten/app/ManualPayout.php | 30 +++++++++++++++- pfosten/app/User.php | 9 +++++ pfosten/public/css/dropdown.css | 8 +++-- .../resources/views/seasons/index.blade.php | 12 ++++--- pfosten/routes/web.php | 4 +++ 6 files changed, 85 insertions(+), 13 deletions(-) diff --git a/pfosten/app/Http/Controllers/SeasonsController.php b/pfosten/app/Http/Controllers/SeasonsController.php index 7bac3157..efb90c6f 100644 --- a/pfosten/app/Http/Controllers/SeasonsController.php +++ b/pfosten/app/Http/Controllers/SeasonsController.php @@ -9,6 +9,7 @@ use App\Quota; use App\User; use App\Game; use App\Tipp; +use App\ManualPayout; use Carbon; use DB; use Auth; @@ -22,7 +23,7 @@ class SeasonsController extends Controller $seasons = DB::table('seasons')->get(); $currentSeason=Season::getCurrent(); - $users = User::getActives(); + $users = User::getActivesSortedByName(); $active_user_count = sizeof( $users ); $currentSeasonId=-1; @@ -31,7 +32,16 @@ class SeasonsController extends Controller $payouts = Quota::getPayouts(); } - return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts', 'users')); + $winnerNames=array(); + $manualPayoutTypes=array('liga_platz1','liga_platz2','liga_platz3', 'liga_platz2_1', 'liga_platz3_1', 'pokal'); + foreach($manualPayoutTypes as $payoutType) { + $user = ManualPayout::getWinner($payoutType); + $name="Festlegen"; + if ($user) $name = $user->name; + $winnerNames[$payoutType] = $name; + } + + return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts', 'users', 'winnerNames')); } public function create() { @@ -187,12 +197,27 @@ class SeasonsController extends Controller // Redirect to the home page return redirect('/seasons'); } - public function setcurrent($new_season_id) { - if (Auth::guest()) { return redirect("/"); } - if (!Auth::user()->admin) { return redirect("/"); } + public function setcurrent($new_season_id) + { + if (Auth::guest()) { + return redirect("/"); + } + if (!Auth::user()->admin) { + return redirect("/"); + } Season::setCurrent($new_season_id); return redirect("/seasons"); } + public function set_winner( $userId, $quotaName) { + if (Auth::guest()) { return redirect("/"); } + if (!Auth::user()->admin) { return redirect("/"); } + + ManualPayout::setWinner( $userId, $quotaName); + return redirect('/seasons'); + + } + + } \ No newline at end of file diff --git a/pfosten/app/ManualPayout.php b/pfosten/app/ManualPayout.php index 011aa6a1..5095a276 100644 --- a/pfosten/app/ManualPayout.php +++ b/pfosten/app/ManualPayout.php @@ -3,8 +3,36 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use App\Season; +use App\User; class ManualPayout extends Model { - // + protected $fillable = [ + 'season_id','quota_name','user_id' + ]; + + public static function getWinner($quotaName) { + $season = Season::getCurrent(); + + $entry = ManualPayout::where('season_id','=', $season->id)->where('quota_name','=',$quotaName)->first(); + if (!$entry) return null; + $user = User::where('id','=',$entry->user_id); + return $user->first(); + } + + public static function setWinner( $userId, $quotaName) { + + $season = Season::getCurrent(); + + $entry = ManualPayout::where('season_id','=',$season->id)->where('quota_name','=',$quotaName)->first(); + if (!$entry) { + $entry = new ManualPayout; + $entry->user_id = $userId; + $entry->season_id = $season->id; + $entry->quota_name = $quotaName; + } + $entry->user_id = $userId; + $entry->save(); + } } diff --git a/pfosten/app/User.php b/pfosten/app/User.php index 30a4c630..e9c0aff1 100644 --- a/pfosten/app/User.php +++ b/pfosten/app/User.php @@ -219,6 +219,15 @@ class User extends Authenticatable return $userlist; } + public static function getActivesSortedByName($seasonId=-1) { + $users = User::getActives($seasonId); + usort($users, array("App\User","cmpName")); + return $users; + } + + public static function cmpName($user1, $user2) { + return ($user1['lastname']." ".$user1['firstname'] > $user2['lastname']." ".$user2['firstname']); + } public static function isDeleted($user_id) { $user=User::where('id','=',$user_id)->first(); diff --git a/pfosten/public/css/dropdown.css b/pfosten/public/css/dropdown.css index 933b2a62..81327041 100644 --- a/pfosten/public/css/dropdown.css +++ b/pfosten/public/css/dropdown.css @@ -13,6 +13,7 @@ border-color:grey; border-radius: 4px; cursor: pointer; + } /* Dropdown button on hover & focus */ @@ -25,6 +26,7 @@ .dropdown { position: relative; display: inline-block; + } /* Dropdown Content (Hidden by Default) */ @@ -35,6 +37,7 @@ min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; + } /* Links inside the dropdown */ @@ -43,10 +46,11 @@ padding: 2px; text-decoration: none; display: block; + } /* Change color of dropdown links on hover */ -.dropdown-content a:hover {background-color: #f1f1f1} +.dropdown-content a:hover {background-color: #f1f1f1; width:100%;} /* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */ -.show {display:block;} \ No newline at end of file +.show {display:inline;} \ No newline at end of file diff --git a/pfosten/resources/views/seasons/index.blade.php b/pfosten/resources/views/seasons/index.blade.php index 725fd7ff..b4caee25 100644 --- a/pfosten/resources/views/seasons/index.blade.php +++ b/pfosten/resources/views/seasons/index.blade.php @@ -148,10 +148,10 @@ - -