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') -