Teilnehmeranzahl in Tourenliste anzeigen, Teilnahme, Absage, Admin-Absage

This commit is contained in:
TorstenS 2020-10-12 10:09:54 +02:00
parent 2f0a54ed77
commit 79b3720e8f
9 changed files with 100 additions and 53 deletions

View file

@ -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);
}
}