Tour-Überbuchung verhindern

This commit is contained in:
Torsten 2023-01-12 13:50:48 +01:00
parent 134ac6478f
commit 4253194117
6 changed files with 621 additions and 560 deletions

View file

@ -3,7 +3,9 @@
namespace App\Http\Controllers;
use App\Page;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class PageController extends Controller
{
@ -84,17 +86,23 @@ class PageController extends Controller
}
public function page_home() {
public function page_home()
{
$page = Page::where('name', 'home')->first();
$content = $page->content;
$content = rtrim(ltrim($content, '"'), '"');
$user = Auth::user();
if ($user) {
Log::info("Home page display for user " . $user->name . "[" . $user->id . "]");
}
return view('home')->with('content', $content);
}
public function page_activities() {
public function page_activities()
{
$page = Page::where('name', 'activities')->first();
$content = $page->content;
return view('activities')->with('content', $content);

View file

@ -149,7 +149,8 @@ class TourController extends Controller
* @return \Illuminate\Http\Response
*/
private function fetch_rooms($tour_id) {
private function fetch_rooms($tour_id)
{
// - all existing rooms with booked users (if any)
// - all users without room
$sql = "
@ -212,15 +213,17 @@ class TourController extends Controller
$rooms = DB::select($sql);
Log::info("TourController.fetch_rooms, returning rooms result:");
Log::info($rooms);
//Log::info("TourController.fetch_rooms, returning rooms result:");
//Log::info($rooms);
return ($rooms);
}
public function edit(Tour $tour)
{
if (Auth::user()->role != 'ADMIN') {return redirect('/tour');}
if (Auth::user()->role != 'ADMIN') {
return redirect('/tour');
}
error_log("Tour:edit");
if ($tour->start < Carbon::now()) {
return view('tour.edit_old')->with('tour', $tour);
@ -232,7 +235,6 @@ class TourController extends Controller
$rooms = $this->fetch_rooms($tour->id);
return view('tour.edit')
->with('tour', $tour)
->with('rooms', $rooms);
@ -303,7 +305,8 @@ class TourController extends Controller
}
*/
public function upload_gallery(Request $request, Tour $tour){
public function upload_gallery(Request $request, Tour $tour)
{
dd($request);
}
@ -319,13 +322,16 @@ class TourController extends Controller
//
}
public function join_room($tour_id,$room_id) {
public function join_room($tour_id, $room_id)
{
Log::info("TourController::join_room");
$user_id = Auth::user()->id;
Tour::join_room($tour_id, $user_id, $room_id);
return redirect('/tour/' . $tour_id);
}
public function join_room4user($tour_id,$room_id,$user_id) {
public function join_room4user($tour_id, $room_id, $user_id)
{
Log::info("TourController::join_room");
Tour::join_room($tour_id, $user_id, $room_id);
@ -341,13 +347,16 @@ class TourController extends Controller
return redirect('/tour/' . $tour_id);
}
public function cancelBooking($tour_id) {
public function cancelBooking($tour_id)
{
$user = Auth::user();
Booking::where('tour_id', $tour_id)->where('user_id', $user->id)->delete();
return redirect('/tour');
}
public function cancelBookingAdmin($tour_id, $user_id) {
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();
@ -355,13 +364,16 @@ class TourController extends Controller
return redirect('/tour/' . $tour_id);
}
public function create_room($tour_id,$capacity) {
public function create_room($tour_id, $capacity)
{
Log::info("create_room Controller started");
$user = Auth::user();
Tour::create_room($tour_id, $capacity);
return redirect('tour/' . $tour_id . '/edit');
}
public function delete_room($tour_id,$room_id) {
public function delete_room($tour_id, $room_id)
{
Log::info("create_room Controller started");
$user = Auth::user();

View file

@ -10,25 +10,39 @@ use Log;
class Tour extends Model
{
protected $fillable = [
'id', 'name', 'beschreibung','user_id','start','deadline','is_cancelled', 'status'
'id', 'name', 'beschreibung', 'user_id', 'start', 'deadline', 'is_cancelled', 'status', 'bericht', 'max_participants'
];
public static function getBookings($tour_id) {
public static function getBookings($tour_id)
{
error_log("getBookings for tour_id: " . $tour_id);
$bookings = Booking::where('tour_id', $tour_id)->get();
return $bookings;
}
public static function has_participant($tour_id, $user_id) {
public static function has_participant($tour_id, $user_id)
{
$booking = Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->first();
if ($booking) return true;
return false;
}
public static function has_space($tour_id)
{
//$tour = Tour::where("id", $tour_id)->get();
//Log::info($tour[0]);
$tour = Tour::find($tour_id);
//Log::info($tour);
$bookings = Booking::where('tour_id', $tour_id)->get();
if (count($bookings) >= $tour->max_participants) return false;
return true;
}
// new join with room parameter
public static function join_room($tour_id, $user_id, $room_id) {
public static function join_room($tour_id, $user_id, $room_id)
{
Log::info("Tour::join_room, tour_id=" . $tour_id . ", user_id=" . $user_id . ", room_id=" . $room_id);
$booking = Booking::firstOrCreate(
['tour_id' => $tour_id, 'user_id' => $user_id], // Retrieve if existing
@ -40,20 +54,25 @@ class Tour extends Model
//Log::info($booking);
}
public static function cancel($tour_id, $user_id) {
public static function cancel($tour_id, $user_id)
{
Booking::where('tour_id', $tour_id)->where('user_id', $user_id)->delete();
}
public static function is_over($tour_id) {
public static function is_over($tour_id)
{
$tour = Tour::find($tour_id);
if ($tour->start < Carbon::now()) return true;
return false;
}
public static function create_room($tour_id,$capacity) {
public static function create_room($tour_id, $capacity)
{
$tour = Tour::find($tour_id);
$name = "Einzelzimmer";
if ($capacity!=1) { $name="Doppelzimmer";}
if ($capacity != 1) {
$name = "Doppelzimmer";
}
$sql = "INSERT INTO tour_rooms (name,tour_id,capacity,created_at,updated_at) VALUES ('" . $name . "'," . $tour_id . "," . $capacity . ",now(),now());";
DB::insert($sql);
}

View file

@ -37,9 +37,10 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
];
public static function has_tour($tour_id, $user_id) {
$tour=Tour::find($tour_id);
$user=User::first($user_id);
public static function has_tour($tour_id, $user_id)
{
// $tour=Tour::find($tour_id);
// $user=User::first($user_id);
$booking = Booking::where('tour_id', $tour_id)->where('user_id', $user_id);
if ($booking) return true;
return false;

View file

@ -12,33 +12,41 @@
<div class="card-body">
<form style="background-color: #fff;" class="text-dark" method="post" action="" enctype="multipart/form-data">
<form style="background-color: #fff;" class="text-dark" method="post" action=""
enctype="multipart/form-data">
@csrf
<div class="" style="display:flex;">
<!-- label class="ml-2 mt-4 col-form-label col-form-label-sm" style="width:150px; text-align:left;" for="name"><h4>Name:</h4></label> -->
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Name:</label>
<input class="mr-1 form-control" type="text" id="name" name="name" value="{{ old('name') ?? $tour->name }}" readonly >
<input class="mr-1 form-control" type="text" id="name" name="name"
value="{{ old('name') ?? $tour->name }}" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Start:</label>
<input class="mr-1 form-control" type="text" id="start" name="start" value="{{ old('start') ?? $tour->start }}" readonly >
<input class="mr-1 form-control" type="text" id="start" name="start"
value="{{ old('start') ?? $tour->start }}" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="creator">Ansprechpartner:</label>
<input class="mr-1 form-control" type="text" id="creator" name="creator" value="{{ old('creator') ?? $creator->name }}" readonly >
<input class="mr-1 form-control" type="text" id="creator" name="creator"
value="{{ old('creator') ?? $creator->name }}" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Anmeldeschluss:</label>
<input class="mr-1 form-control" type="text" id="anmeldeschluss" style="font-size:16px;" name="deadline" value="{{ old('anmeldeschluss') ?? $tour->deadline }}" readonly >
<input class="mr-1 form-control" type="text" id="anmeldeschluss" style="font-size:16px;"
name="deadline" value="{{ old('anmeldeschluss') ?? $tour->deadline }}" readonly>
</div>
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Max Teilnehmer:</label>
<input class="mr-1 form-control" type="text" id="max_participants" style="font-size:16px;" name="max_participants" value="{{ old('max_participants') ?? $tour->max_participants }}" required >
<label class="ml-2" style="width:180px; text-align:left;font-size:18px;" for="name">Max
Teilnehmer:</label>
<input class="mr-1 form-control" type="text" id="max_participants"
style="font-size:16px;" name="max_participants"
value="{{ old('max_participants') ?? $tour->max_participants }}" required>
</div>
@if(App\Tour::has_participant($tour->id, Auth::user()->id))
@ -50,7 +58,8 @@
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
<!--File exists -->
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg"
data-title="{{ $tour->name }}">
<img src="/img/tour/{{$tour->id}}.jpg" class="mt-3 ml-3">
</a>
@else
@ -58,8 +67,10 @@
@endif
<div class="mt-1" style="display:flex;">
<label class="ml-2" style="width:140px; text-align:left;font-size:18px;" for="is_cancelled">Storniert:</label>
<input class="mr-1 form-control" type="checkbox" id="is_cancelled" style="font-size:10px;width:20px;" name="is_cancelled"
<label class="ml-2" style="width:140px; text-align:left;font-size:18px;"
for="is_cancelled">Storniert:</label>
<input class="mr-1 form-control" type="checkbox" id="is_cancelled"
style="font-size:10px;width:20px;" name="is_cancelled"
@if($tour->is_cancelled)
checked
@endif
@ -74,15 +85,20 @@
<!-- TODO: Only if owner or admin -->
@if(Auth::user()->role=="ADMIN")
<a href="/tour/{{$tour->id}}/edit"><div type="submit" class="btn btn-danger col-3 mb-2 float-left mr-2">Bearbeiten</div></a>
<a href="/tour/{{$tour->id}}/edit">
<div type="submit" class="btn btn-danger col-3 mb-2 float-left mr-2">Bearbeiten
</div>
</a>
@endif
<a href="/tour" type="submit" class="btn btn-success col-3 mb-2 float-right mr-2">Ok</a>
@if(!App\Tour::has_participant($tour->id, Auth::user()->id))
@if(!App\Tour::has_participant($tour->id, Auth::user()->id) && App\Tour::has_space($tour->id))
<!-- Connected to Modal -->
<button id="myBtn" class="btn btn-danger float-left">Teilnehmen</button>
@else
<a href="/tour/{{$tour->id}}/cancelBooking" type="submit" class="btn btn-danger col-3 mb-2 float-right mr-2">Absagen</a>
@endif
@if(App\Tour::has_participant($tour->id, Auth::user()->id))
<a href="/tour/{{$tour->id}}/cancelBooking" type="submit"
class="btn btn-danger col-3 mb-2 float-right mr-2">Absagen</a>
@endif
</form>
@ -102,14 +118,16 @@
<!-- Intentional Assignment ! -->
@if ($room_id="") @endif
@foreach($rooms as $room)
@if( $room->room_id != 0 and $room->free_slots >0) <!-- Dont show "Ungebucht", room_id=0 and only with available slots -->
@if( $room->room_id != 0 and $room->free_slots >0)
<!-- Dont show "Ungebucht", room_id=0 and only with available slots -->
@if ($room_id != $room->room_id)
@if(strlen($room_id))
<hr/>
@endif
<p style="list-style-type: none;">[{{$room->room_id}}]
<span>{{$room->room_name}}
</span><b><a href="/tour/{{$tour->id}}/join/{{$room->room_id}}"> ==> Buchen</a></b>
</span><b><a href="/tour/{{$tour->id}}/join/{{$room->room_id}}">
==> Buchen</a></b>
</p>
<!-- Intentional Assignment ! -->
@ -149,9 +167,11 @@
@if ($room_id != $room->room_id)
@if($room_id!="")
@if($room->room_name=="Ungebucht")
</div> <div style="height:30px;"></div>
</div>
<div style="height:30px;"></div>
@else
</div> <div style="height:2px;"></div>
</div>
<div style="height:2px;"></div>
@endif
@endif
@ -172,7 +192,8 @@
@endif
@endforeach
</div> <div style="height:2px;"></div>
</div>
<div style="height:2px;"></div>
</div>

0
motorradig/setenv.sh Normal file → Executable file
View file