Added HTML Helpers from Laravelcollective
This commit is contained in:
parent
0736ecf29f
commit
b5c1f40a45
31 changed files with 614 additions and 220 deletions
|
|
@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Game extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'id','round_id','team1','team2','score1','score2','kickoff'
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GameController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
43
pfosten/app/Http/Controllers/GamesController.php
Normal file
43
pfosten/app/Http/Controllers/GamesController.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Game;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class GamesController extends Controller
|
||||
{
|
||||
public function edit($game_id) {
|
||||
$game=Game::where('id',$game_id)->first();
|
||||
//$testdate=str_replace(' UTC ','T',date('Y-m-d h:m'));
|
||||
|
||||
return view('games.edit',compact('game'));
|
||||
}
|
||||
|
||||
public function store() {
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
'team1' => 'required',
|
||||
'team2' => 'required',
|
||||
'score1' => 'required',
|
||||
'score2' => 'required',
|
||||
'kickoff' => 'required'
|
||||
]);
|
||||
|
||||
// Fetch, modify, save game
|
||||
$game = Game::where('id', request('id'))->first(); // Only for editing existing. New games get created in RoundsController.
|
||||
$game->team1 = request('team1');
|
||||
$game->team2 = request('team2');
|
||||
$game->score1= request('score1');
|
||||
$game->score2= request('score2');
|
||||
$game->kickoff=request('kickoff');
|
||||
$game->save();
|
||||
|
||||
// Redirect to the Rounds Index
|
||||
return redirect('/rounds');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Season;
|
||||
use App\Round;
|
||||
use App\Game;
|
||||
use DB;
|
||||
|
||||
class RoundsController extends Controller
|
||||
|
|
@ -25,4 +26,96 @@ class RoundsController extends Controller
|
|||
//return view('rounds.index');
|
||||
//return view ('welcome');
|
||||
}
|
||||
|
||||
|
||||
public function create() {
|
||||
$currentSeason = Season::getCurrent();
|
||||
if ($currentSeason) {
|
||||
return view('rounds.create', compact('currentSeason'));
|
||||
}
|
||||
redirect()->home()->withErrors('Es muss zuerst eine Saison angelegt werden');
|
||||
}
|
||||
|
||||
|
||||
public function store() {
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'name' => 'required',
|
||||
'game1_team1' => 'required',
|
||||
'game1_team2' => 'required',
|
||||
'game1_kickoff' => 'required',
|
||||
'game2_team1' => 'required',
|
||||
'game2_team2' => 'required',
|
||||
'game2_kickoff' => 'required',
|
||||
'game3_team1' => 'required',
|
||||
'game3_team2' => 'required',
|
||||
'game3_kickoff' => 'required',
|
||||
'game4_team1' => 'required',
|
||||
'game4_team2' => 'required',
|
||||
'game4_kickoff' => 'required'
|
||||
]);
|
||||
|
||||
$seasonId = Season::getCurrent()->id;
|
||||
|
||||
$round = Round::create([
|
||||
'name' => request('name'),
|
||||
'season_id' => $seasonId
|
||||
]);
|
||||
$round->save();
|
||||
$round_id = $round->id;
|
||||
|
||||
$game1 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game1_team1'),
|
||||
'team2' => request('game1_team2'),
|
||||
'kickoff' => request('game1_kickoff')
|
||||
]);
|
||||
|
||||
$game2 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game2_team1'),
|
||||
'team2' => request('game2_team2'),
|
||||
'kickoff' => request('game2_kickoff')
|
||||
]);
|
||||
|
||||
$game3 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game3_team1'),
|
||||
'team2' => request('game3_team2'),
|
||||
'kickoff' => request('game3_kickoff')
|
||||
]);
|
||||
|
||||
$game4 = Game::create([
|
||||
'round_id' => $round_id,
|
||||
'team1' => request('game4_team1'),
|
||||
'team2' => request('game4_team2'),
|
||||
'kickoff' => request('game4_kickoff')
|
||||
]);
|
||||
// Sign them in
|
||||
|
||||
// Redirect to the home page
|
||||
return redirect()->home();
|
||||
}
|
||||
|
||||
public function editname($round_id)
|
||||
{
|
||||
$round = Round::where('id', $round_id)->first();
|
||||
return view('rounds.editname', compact('round'));
|
||||
}
|
||||
|
||||
public function storename()
|
||||
{
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'round_id' => 'required',
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$round = Round::where('id', request('round_id'))->first();
|
||||
$round->name = request('name');
|
||||
$round->save();
|
||||
|
||||
return redirect('/rounds');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,25 +4,22 @@ namespace App\Http\Controllers;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use App\User;
|
||||
use App\Season;
|
||||
use App\Payment;
|
||||
use DB;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
public function main() {
|
||||
return view('main');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$users = DB::table('users')->get();
|
||||
$users = DB::table('users')->where('deleted',null)->get();
|
||||
return view('users.index', compact('users'));
|
||||
}
|
||||
|
||||
|
||||
public function mypage() {
|
||||
return view('mypage');
|
||||
}
|
||||
|
||||
public function getAllUsersAsJson() {
|
||||
$users = DB::table('users')->get();
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function showUsers() {
|
||||
$users = DB::table('users')->get();
|
||||
return view('users.list', compact('users'));
|
||||
|
|
@ -36,4 +33,46 @@ class UsersController extends Controller
|
|||
//$user = DB::table('users')->find($id);
|
||||
return view('users.show', compact('userObject'));
|
||||
}
|
||||
|
||||
|
||||
public function edit($user_id) {
|
||||
$user = User::where('id',$user_id)->first();
|
||||
$season_id = Season::getCurrent()->id;
|
||||
|
||||
$paid_date_str="";
|
||||
$val=User::payment_date($user_id, $season_id);
|
||||
if ($val) { $paid_date_str=$val;}
|
||||
|
||||
return view ('users.edit', compact('user','paid_date_str'));
|
||||
}
|
||||
|
||||
public function store() {
|
||||
$season_id = Season::getCurrent()->id;
|
||||
|
||||
// Validate form
|
||||
$this->validate(request(), [
|
||||
'id' => 'required',
|
||||
'name' => 'required',
|
||||
'email'=> 'required'
|
||||
]);
|
||||
|
||||
// Create and save the season
|
||||
|
||||
$user=User::where('id', request('id'))->first();
|
||||
|
||||
$user->name=request('name');
|
||||
$user->email=request('email');
|
||||
|
||||
if (request()->has('admin')) { $user->admin=request('admin'); }
|
||||
$user->save();
|
||||
|
||||
|
||||
if (request()->has('paid')) {
|
||||
Payment::set_payment_date(request('id'), $season_id, request('paid'));
|
||||
}
|
||||
|
||||
// Redirect to the home page
|
||||
return redirect('/users');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,31 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Payment extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'season_id', 'user_id', 'paid_date'
|
||||
];
|
||||
|
||||
public static function set_payment_date($user_id,$season_id,$paid_date) {
|
||||
|
||||
$payment = Payment::where([
|
||||
['user_id', '=', $user_id],
|
||||
['season_id', '=', $season_id]
|
||||
])->first();
|
||||
|
||||
if (!$payment) {
|
||||
$payment= Payment::create([
|
||||
'user_id' => $user_id,
|
||||
'season_id'=> $season_id,
|
||||
'paid_date'=> $paid_date
|
||||
]);
|
||||
|
||||
} else {
|
||||
$payment->user_id = $user_id;
|
||||
$payment->season_id = $season_id;
|
||||
$payment->paid_date = $paid_date;
|
||||
}
|
||||
|
||||
$payment->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Round extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'name','season_id'
|
||||
];
|
||||
|
||||
public function games() {
|
||||
return $this->hasMany('App\Game');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace App;
|
|||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use App\Season;
|
||||
use App\Payment;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
|
@ -26,4 +28,37 @@ class User extends Authenticatable
|
|||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
|
||||
// Only the current season.
|
||||
public static function is_season_paid($user_id) {
|
||||
$retval="Ja";
|
||||
if (User::payment_date($user_id, Season::getCurrent()->id)==null) { $retval="Nein"; }
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
public static function payment_date($user_id,$season_id) {
|
||||
$season = Season::getCurrent();
|
||||
if ($season) {
|
||||
$payment = Payment::where([
|
||||
['user_id', '=', $user_id],
|
||||
['season_id', '=', $season->id]
|
||||
])->first();
|
||||
if ($payment) {
|
||||
if ($payment->paid_date) {
|
||||
return $payment->paid_date;
|
||||
}
|
||||
} else {
|
||||
$payment= Payment::create([
|
||||
'user_id' => $user_id,
|
||||
'season_id'=> $season->id,
|
||||
'paid_date'=> null
|
||||
]);
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue