applicazza / 任命
检查所需的预约时段是否开放或提供最近的可用时段
0.6.4
2017-07-10 11:31 UTC
Requires
- php: >=5.6.0
- nesbot/carbon: ^1.22.1
Requires (Dev)
- phpunit/phpunit: ^6.2.0
README
安装
composer require applicazza/appointed
用法
- 设置默认时区,例如
date_default_timezone_set('Asia/Jerusalem');
- 实例化工作日
use Applicazza\Appointed\BusinessDay; // ... $business_day = new BusinessDay;
- 创建一些运营时段并将它们添加到工作日。如果某些运营时段无法添加,则返回false,并且不会应用任何更改
use Applicazza\Appointed\Period; // ... $period_0900_1400 = Period::make(today( 9, 00), today(14, 00)); $period_1600_1900 = Period::make(today(16, 00), today(19, 00)); $business_day->addOperatingPeriods( $period_1600_1900, $period_0900_1400 );
- 创建一些预约并将它们添加到工作日。如果某些预约无法添加,则返回false,并且不会应用任何更改
use Applicazza\Appointed\Appointment; // ... $appointment_1100_1130 = Appointment::make(today( 11, 00), today(11, 30)); $appointment_1200_1330 = Appointment::make(today( 12, 00), today(13, 30)); $business_day->addAppointments( $appointment_1100_1130, $appointment_1200_1330 );
- 为了适应之前失败的预约,使用
BusinessDay::fit(Appointment $appointment, $direction = 'forward')
,它将返回null或推荐的预约
$business_day->fit($appointment_1300_1330, 'backward'); $business_day->fit($appointment_1300_1330);
- 要删除预约(s),使用
BusinessDay::deleteAppointments(Appointment ...$appointment)
,它将返回布尔值
$business_day->deleteAppointments($appointment_1300_1330);
- 要删除运营时段,使用
BusinessDay::deleteOperatingPeriod(Period $period)
,它将返回布尔值
$business_day->deleteOperatingPeriod($period_0900_1400)
- 要编辑运营时段,使用
BusinessDay::editOperatingPeriod(Period $old_period, Period $new_period)
,它将返回布尔值
$business_day->editOperatingPeriod($period_1330_1400, $period_1330_1430)
- 要获取整个日历,使用
BusinessDay::getAgenda()
,它将返回按顺序排列的Period和/或Appointment的数组。由于底层类实现了JsonSerializable接口,这些数据可以轻松地编码为json。
$agenda = $business_day->getAgenda(); // To pretty print results echo json_encode($business_day->getAgenda(), JSON_PRETTY_PRINT), PHP_EOL;
辅助工具
use function Applicazza\Appointed\interval; use function Applicazza\Appointed\today; // ... interval($hours = 0, $minutes = 0, $seconds = 0); today($hours = 0, $minutes = 0, $seconds = 0);