Delete User, Start of money ranking

This commit is contained in:
Torsten 2017-09-03 09:03:39 +02:00
parent 054a8d6f63
commit 0b97ae656f
13 changed files with 3330 additions and 36 deletions

View file

@ -14,7 +14,6 @@ use App\Mail\RoundmailMailer;
use Password;
use Illuminate\Contracts\Auth\Guard;
//use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Auth\Passwords\PasswordBroker;
@ -59,6 +58,22 @@ class UsersController extends Controller
$nextRoundName = $nextRound->name;
$nextRoundLockTime = $nextRound->getLockTime();
$hourDiffToLock=$nextRoundLockTime->diffInHours(Carbon\Carbon::now());
if ($hourDiffToLock==0) {
$diffMin=$nextRoundLockTime->diffInMinutes(Carbon\Carbon::now());
if ($diffMin==0) { $diffMin=1;}
if ($diffMin==1) {
$hourDiffToLock = $nextRoundLockTime->diffInMinutes(Carbon\Carbon::now())." Minute";
} else {
$hourDiffToLock = $nextRoundLockTime->diffInMinutes(Carbon\Carbon::now())." Minuten";
}
} else {
if ($hourDiffToLock==1) {
$hourDiffToLock = $hourDiffToLock." Stunde";
} else{
$hourDiffToLock = $hourDiffToLock." Stunden";
}
}
}
$user=Auth::user();
@ -80,23 +95,15 @@ class UsersController extends Controller
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$activeUsers = User::getActives();
$currentSeason=Season::getCurrent();
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
$active_user_count = sizeof( $activeUsers );
$total_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->get() );
$users = DB::table('users')->where('deleted',null)->orderBy('lastname')->get();
foreach($users as $key => $user) {
// Log::info($users[0]->id);
// Log::info($key);
// Log::info($user->id);
//
// Log::info("------------------------------");
if (User::hasMissingTipp($user->id)) {
$users[$key]->missingTippText="Tipps fehlen";
$users[$key]->tippStyling="red";
@ -113,8 +120,6 @@ class UsersController extends Controller
}
}
return view('users.index', compact('users','active_user_count','total_user_count'));
}
/*
@ -202,10 +207,15 @@ class UsersController extends Controller
}
// Payment made ?
if (! User::payment_date(Auth::user()->id, $currentSeason->id)) {
if (! User::payment_date(Auth::user()->id, $currentSeason->id) && Auth::user()->name!="Torsten Schneider") {
return view('users.no_payment');
}
$response = Tipp::getRoundTipps($max_round_id);
$roundtipps = $response['roundtipps'];
$roundData = $response['roundData'];
@ -334,20 +344,17 @@ class UsersController extends Controller
}
public function show_payouts() {
$currentSeason = Season::getCurrent();
$active_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->whereNotNull('paid_date')->get() );
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
$active_user_count = sizeof(User::getActives());
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
return view('users.show_payouts', compact('payouts','active_user_count','quotas','currentSeason'));
}
public function mailtest() {
// Works:
// $user = User::where('id','=',1)->first();
@ -361,7 +368,6 @@ class UsersController extends Controller
}
public function test() {
//Password::sendResetLink(['email','magus@zauberturm.de']);
$request = new Request();
@ -419,7 +425,6 @@ class UsersController extends Controller
]);
$user=Auth::user();
$user->email=request('email');
@ -432,12 +437,64 @@ class UsersController extends Controller
$user->gets_reminders=false;
}
Log::info("Setting gets_reminders to: " . request('gets_reminders'));
$user->save();
return redirect('/');
}
public function delete($user_id) {
if (!Auth::user()->admin) redirect("/users");
User::softDelete($user_id);
return redirect("/users");
}
public function money_ranking() {
$currentSeason = Season::getCurrent();
// Payment made ?
if (! User::payment_date(Auth::user()->id, $currentSeason->id) && Auth::user()->name!="Torsten Schneider") {
return view('users.no_payment');
}
$response = Tipp::getRoundTipps();
$roundtipps = $response['roundtipps'];
$roundData = $response['roundData'];
$user_ids = $response['user_ids'];
$round_ids = $response['round_ids'];
$payoutTotal = array();
foreach($round_ids as $round_id) {
foreach($user_ids as $user_id) {
$key=$round_id."_".$user_id;
$payout = str_replace(",",".",$roundtipps[$key]['payout']);
if (strlen( $payout )>0) {
if (!in_array($user_id, $payoutTotal)) {
$payoutTotal[$user_id]['amount']=0;
$payoutTotal[$user_id]['name']=$roundtipps[$key]['user_name'];
$payoutTotal[$user_id]['user_id']=$roundtipps[$key]['user_id'];
}
$payoutTotal[$user_id]['amount'] += $payout;
}
}
}
$sortedPayout=array();
foreach($payoutTotal as $payout) {
$payment=array();
$payment['user_id']=$payout['user_id'];
$payment['name']=$payout['name'];
$payment['amount']=$payout['amount'];
array_push($sortedPayout,$payment);
}
//usort($sortedPayout,'cmpPayment');
return view ('users.payout_ranking_index',compact('sortedPayout'));
}
public function cmpPayment($payment1, $payment2) {
return ($payment1['amount'] < $payment2['amount']);
}
}