Am developing a system for booking a venuesfor meeting conducting, where some departments can book after other finished for the same day.
I tried creating a function to to return false when the start time requested is less or equal to booked time and the same for requested end time,
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Venue;
use App\VenueRequest;
use Carbon\Carbon;
class CheckAvailability extends Controller
{
public function checkAvailability(Request $request){
if(!is_numeric($request->id)){
echo "Choose among of the listed venues";
}
else{
$requested_venue = VenueRequest::where('venue_id',$request->id)->get();
// first time request
if($requested_venue->isEmpty()){
//allowed to book
$available = "Available!";
return $available;
}
elseif(count($requested_venue) > 0 ){
// start check
foreach ($requested_venue as $venue) {
$rstart = strtotime($request->meeting_start_time);
$rend = strtotime($request->meeting_end_time);
$rdate = strtotime($request->meeting_date);
$venue_ = $venue->venue->name;
$depart = $venue->department->alias;
$start = strtotime($venue->stime);
$end = strtotime($venue->etime);
$date = strtotime($venue->book_date);
if($rdate == $date){
$is_start_allowed = $this->timeAvailabilty($rstart, $start, $end);
if($is_start_allowed){
$is_end_allowed = $this->timeAvailabilty($rend, $start, $end);
if($is_end_allowed){
echo "Available!";
}
else{
echo "Venue occupied by ".$depart;
}
}
else{
echo "Venue occupied by ".$depart;
}
}
else{
echo "Available!";
}
}
}
else{
echo "not known";
}
}
}
public function timeAvailabilty($request_time, $booked_start_time, $booked_end_time)
{
return $request_time >= $booked_start_time && $request_time <= $booked_end_time ? false : true ;
}
}
Expected to restrict the time collision but the system allows some one to book if still thereis a meeting conducted, such as if booked start at 08.00 to 10.00 the other ca book at 07.00 to 11.00 which is not required