From 79b3720e8f318bcee1bba3769d238f87df67e1b0 Mon Sep 17 00:00:00 2001 From: TorstenS Date: Mon, 12 Oct 2020 10:09:54 +0200 Subject: [PATCH] Teilnehmeranzahl in Tourenliste anzeigen, Teilnahme, Absage, Admin-Absage --- .../app/Http/Controllers/TourController.php | 44 +++++++++----- .../app/Http/Controllers/UserController.php | 2 + motorradig/database/seeds/BookingSeeder.php | 2 +- .../resources/views/tour/index.blade.php | 2 +- .../views/tour/index_bookings.blade.php | 31 ---------- .../resources/views/tour/show.blade.php | 60 ++++++++++++++++++- .../resources/views/users/edit.blade.php | 5 +- .../resources/views/users/show.blade.php | 6 +- motorradig/routes/web.php | 1 + 9 files changed, 100 insertions(+), 53 deletions(-) delete mode 100644 motorradig/resources/views/tour/index_bookings.blade.php diff --git a/motorradig/app/Http/Controllers/TourController.php b/motorradig/app/Http/Controllers/TourController.php index 782c038..423271b 100644 --- a/motorradig/app/Http/Controllers/TourController.php +++ b/motorradig/app/Http/Controllers/TourController.php @@ -4,11 +4,13 @@ namespace App\Http\Controllers; use App\Tour; use App\Booking; +use App\User; use Illuminate\Http\Request; use Illuminate\Http\File; use Illuminate\Support\Facades\Storage; use Intervention\Image\Facades\Image; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class TourController extends Controller { @@ -21,21 +23,16 @@ class TourController extends Controller { error_log("Tour:index"); $tours=Tour::all(); - return view('tour.index')->with('tours',$tours); - } - - - public function index_bookings($tour_id) - { - $tour=Tour::find($tour_id); - $bookings=array(); - foreach($tour->getBookings($tour_id) as $booking) { - array_push($bookings,$booking); + $participantCount=array(); + foreach($tours as $tour) { + $result = DB::select('select count(*) as cnt from bookings where tour_id=?', [$tour->id]); + $participantCount[$tour->id] = $result[0]->cnt; } - error_log("Tour:index_bookings, tour_id=".$tour->id); - return view('tour.index_bookings')->with('tour',$tour)->with('bookings',$bookings); + return view('tour.index')->with('tours',$tours)->with('participantCount',$participantCount); } +/* + /** * Show the form for creating a new resource. @@ -96,7 +93,18 @@ class TourController extends Controller */ public function show(Tour $tour) { - return view('tour.show')->with('tour',$tour); + $creator = User::find($tour->user_id); + $bookings = Booking::where('tour_id',$tour->id)->get(); + $users = array(); + foreach($bookings as $booking) { + $user=User::find($booking->user_id); + array_push($users, $user); + } + return view('tour.show') + ->with('tour',$tour) + ->with('users', $users) + ->with('creator', $creator); + } /** @@ -181,7 +189,7 @@ class TourController extends Controller public function join($tour_id) { $user=Auth::user(); Tour::join($tour_id,$user->id); - return redirect('/tour'); + return redirect('/tour/'.$tour_id); } public function cancelBooking($tour_id) { @@ -190,4 +198,12 @@ class TourController extends Controller return redirect('/tour'); } + public function cancelBookingAdmin($tour_id, $user_id) { + $user=Auth::user(); + if (Auth::user()->role == "ADMIN") { + Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->delete(); + } + return redirect('/tour/'.$tour_id); + } + } diff --git a/motorradig/app/Http/Controllers/UserController.php b/motorradig/app/Http/Controllers/UserController.php index 2c83477..019b3b7 100644 --- a/motorradig/app/Http/Controllers/UserController.php +++ b/motorradig/app/Http/Controllers/UserController.php @@ -122,6 +122,8 @@ class UserController extends Controller $user->mobile=$request->input('mobile'); $user->save(); + error_log("User role: ".$user->role); + return redirect('/member/'); } diff --git a/motorradig/database/seeds/BookingSeeder.php b/motorradig/database/seeds/BookingSeeder.php index 14992de..d33c13b 100644 --- a/motorradig/database/seeds/BookingSeeder.php +++ b/motorradig/database/seeds/BookingSeeder.php @@ -1,7 +1,7 @@ - {{ $tour->start }} - {{ $tour->name }} [?/?] + {{ $tour->start }} - {{ $tour->name }} [{{$participantCount[$tour->id]}}/{{$tour->max_participants}}] @if(App\Tour::has_participant($tour->id, Auth::user()->id)==true) diff --git a/motorradig/resources/views/tour/index_bookings.blade.php b/motorradig/resources/views/tour/index_bookings.blade.php deleted file mode 100644 index c3b3743..0000000 --- a/motorradig/resources/views/tour/index_bookings.blade.php +++ /dev/null @@ -1,31 +0,0 @@ -@extends('layouts.app') - -@section('content') -
-

Teilnehmer

- -
- . - - - - -
- @if(Auth::user()->role=="ADMIN" or Auth::user()->rolde=="MEMBER") - - @endif - -
-@endsection diff --git a/motorradig/resources/views/tour/show.blade.php b/motorradig/resources/views/tour/show.blade.php index f93b6e4..e78be37 100644 --- a/motorradig/resources/views/tour/show.blade.php +++ b/motorradig/resources/views/tour/show.blade.php @@ -5,7 +5,7 @@
-
{{ $tour->name }}
+
{{ $tour->name }}
@@ -23,6 +23,11 @@
+
+ + +
+
@@ -74,13 +79,64 @@ Absagen @endif - +
+
+
+ +
+
+
Teilnehmer
+ +
+ +
    + @foreach($users as $user) +
  • {{ $user->name }}   + @if(Auth::user()->role=="ADMIN") + (X) + @endif +
  • + @endforeach +
+
+
+ + + + + + @endsection diff --git a/motorradig/resources/views/users/edit.blade.php b/motorradig/resources/views/users/edit.blade.php index 3a909c2..21323b6 100644 --- a/motorradig/resources/views/users/edit.blade.php +++ b/motorradig/resources/views/users/edit.blade.php @@ -13,7 +13,10 @@ - +
+ + +
diff --git a/motorradig/resources/views/users/show.blade.php b/motorradig/resources/views/users/show.blade.php index cb95c36..5aec285 100644 --- a/motorradig/resources/views/users/show.blade.php +++ b/motorradig/resources/views/users/show.blade.php @@ -9,17 +9,17 @@
- +
- +
- +
diff --git a/motorradig/routes/web.php b/motorradig/routes/web.php index 9ff9d6b..694d1a7 100644 --- a/motorradig/routes/web.php +++ b/motorradig/routes/web.php @@ -46,6 +46,7 @@ Route::post('/admin/store_activities', 'AdminController@store_activities'); Route::resource('/tour', TourController::class); Route::get('/tour/{tour_id}/join', 'TourController@join'); Route::get('/tour/{tour_id}/cancelBooking', 'TourController@cancelBooking'); +Route::get('/tour/{tour_id}/cancelBookingAdmin/{user_id}', 'TourController@cancelBookingAdmin'); Auth::routes();