1. Go to this page and download the library: Download puntodev/bookables library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$schedule = WeeklySchedule::fromJson(
'{"hours_in_advance": 24, "disable_all": false, "daily": {"Sun":[{"start":"14:00","end":"15:00"}]}}'
);
$schedule->toJson(); // serialize back to a JSON string
$schedule->toArray(); // or to an array
use Carbon\CarbonImmutable;
use Puntodev\Bookables\Agenda\WeeklyScheduleAgenda;
$agenda = new WeeklyScheduleAgenda($schedule);
$ranges = $agenda->possibleRanges(
CarbonImmutable::parse('2020-01-20'),
CarbonImmutable::parse('2020-01-21'),
);
foreach ($ranges as $range) {
echo $range->toIso8601(), PHP_EOL;
// 2020-01-20T08:00:00.000000Z/2020-01-20T12:00:00.000000Z
// 2020-01-20T14:00:00.000000Z/2020-01-20T18:00:00.000000Z
// ...
}
use Puntodev\Bookables\Agenda\SingleDateRangeAgenda;
$agenda = new SingleDateRangeAgenda(
CarbonImmutable::parse('2020-01-20 09:00'),
CarbonImmutable::parse('2020-01-20 17:00'),
);
use Puntodev\Bookables\Slots\AgendaSlotter;
// 30-minute slots, back to back
$slotter = new AgendaSlotter($agenda, duration: 30);
$slots = $slotter->makeSlotsForDates(
CarbonImmutable::parse('2020-01-23'),
CarbonImmutable::parse('2020-01-23'),
);
// 2020-01-23T08:00:00.000000Z/2020-01-23T08:30:00.000000Z
// 2020-01-23T08:30:00.000000Z/2020-01-23T09:00:00.000000Z
// ...
// 50-minute appointments with a 10-minute gap after each → slots every 60 minutes
$slotter = new AgendaSlotter($agenda, duration: 50, timeAfter: 10);
// 2020-01-23T08:00:00.000000Z/2020-01-23T08:50:00.000000Z
// 2020-01-23T09:00:00.000000Z/2020-01-23T09:50:00.000000Z
// ...
use Puntodev\Bookables\Slots\DaySlotter;
// 30-minute slots starting every 15 minutes
$slotter = new DaySlotter(duration: 30, step: 15);
$slots = $slotter->makeSlotsForDates(
CarbonImmutable::parse('2020-01-23'),
CarbonImmutable::parse('2020-01-23'),
);
// 2020-01-23T00:00:00.000000Z/2020-01-23T00:30:00.000000Z
// 2020-01-23T00:15:00.000000Z/2020-01-23T00:45:00.000000Z
// 2020-01-23T00:30:00.000000Z/2020-01-23T01:00:00.000000Z
// ...
use Puntodev\Bookables\Contracts\Agenda;
use Puntodev\Bookables\Contracts\HasAgenda;
class Professional implements HasAgenda
{
public function agenda(): Agenda
{
return new WeeklyScheduleAgenda($this->weeklySchedule());
}
}
use Puntodev\Bookables\Exceptions\DateRangeTooLargeException;
$agenda = new WeeklyScheduleAgenda($schedule, maxDays: 92);
$slotter = new AgendaSlotter($agenda, duration: 30, maxDays: 92);
$slotter = new DaySlotter(duration: 30, step: 15, maxDays: 92);
try {
$slots = $slotter->makeSlotsForDates($from, $to);
} catch (DateRangeTooLargeException $e) {
// reject the request (e.g. HTTP 422)
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.