Working on Manual Payout Winner Selection
This commit is contained in:
parent
9c1b334fe8
commit
2ad2f32d07
6 changed files with 85 additions and 13 deletions
|
|
@ -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');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
8
pfosten/public/css/dropdown.css
vendored
8
pfosten/public/css/dropdown.css
vendored
|
|
@ -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;}
|
||||
.show {display:inline;}
|
||||
|
|
@ -148,10 +148,10 @@
|
|||
<input type="text" class="form-control" id="liga_platz1" name="liga_platz1" value="{{ $quotas['Liga Platz 1'] }}" style="float:left; width:75px;"required>
|
||||
|
||||
<span class="dropdown" id="dropdown1">
|
||||
<button id="btn_winner" onclick="toggleDropdown('dropdown_winner'); return false;" class="dropbtn">Sieger festlegen</button>
|
||||
<div id="dropdown_winner" class="dropdown-content">
|
||||
<button id="btn_winner" onclick="toggleDropdown('dropdown_winner'); return false;" class="dropbtn">{{ $winnerNames['liga_platz1'] }}</button>
|
||||
<div id="dropdown_winner" class="dropdown-content" style="width:250px;">
|
||||
@foreach($users as $user)
|
||||
<a onclick="setWinner('{{$user->id}}',{{$user->name}});return false;" >{{$user->name}}</a>
|
||||
<a onclick=" setWinner('{{$user->id}}','liga_platz1');return false;" style="width:250px";>{{$user->name}}</a>
|
||||
@endforeach
|
||||
</div>
|
||||
</span>
|
||||
|
|
@ -218,8 +218,10 @@
|
|||
|
||||
<script>
|
||||
|
||||
function setWinner($user_id, $user_name, $elem_name="btn_winner") {
|
||||
var global_winner_id = document.getElementById($elem_winner).innerHTML=$roundname;
|
||||
function setWinner($user_id, $quota_name, $elem_name="btn_winner") {
|
||||
//alert($user_id+","+ $quota_name);
|
||||
//var global_winner_id = document.getElementById($elem_winner).innerHTML=$roundname;
|
||||
window.location.href = '/seasons/set_winner/'+$user_id+'/'+$quota_name;
|
||||
}
|
||||
|
||||
// When the user clicks on the button,toggle between hiding and showing the dropdown content
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ Route::post('/seasons/store','SeasonsController@store');
|
|||
Route::get('/seasons/setcurrent/{new_season_id}','SeasonsController@setcurrent');
|
||||
Route::post('/seasons/store_quota','SeasonsController@store_quota');
|
||||
|
||||
Route::get('/seasons/set_winner/{user_id}/{quota_name}','SeasonsController@set_winner');
|
||||
|
||||
Route::get('/rounds','RoundsController@index');
|
||||
Route::get('/rounds/create','RoundsController@create');
|
||||
Route::post('/rounds/store','RoundsController@store');
|
||||
|
|
@ -33,6 +35,8 @@ Route::post('/rounds/store_report','RoundsController@store_report');
|
|||
Route::get('/rounds/editname/{round_id}','RoundsController@editname');
|
||||
Route::post('/rounds/storename', 'RoundsController@storename');
|
||||
|
||||
|
||||
|
||||
Route::get('/games/edit/{game_id}', 'GamesController@edit');
|
||||
Route::post('/games/store', 'GamesController@store');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue