imagina / ischedulable-module
10.0.0
2024-06-11 20:54 UTC
Requires
- php: ^8.1
- composer/installers: ~1.0
- imagina/core-module: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2024-09-21 04:36:38 UTC
README
多态模块,用于关联调度实体
使用时,运行迁移和种子。
安装
composer require imagina/ischedulable-module=v8.x-dev
启用模块
php artisan module:enable Ischedulable
特性
-
schedulable
同步与您的模型相关的调度。监听事件createdWithBindings
和updatedWithBindings
来执行此操作。-
关系
- schedule
morphOne
返回您模型的所有相关调度。 - schedule.workTimes
hasMany
返回所有相关调度及其工作时间。 - schedule.workTimes.day
belongsTo
返回所有相关调度及其工作时间及其星期。
- schedule
-
使用
在您的实体中使用
Schedulable
特性。use Modules\Ischedulable\Support\Traits\Schedulable; class YourEntityClass extends CrudModel { use Translatable, Schedulable; // Your entity code... }
当您创建或更新实体时,添加调度数据以同步。
同步:只有当实体数据具有
schedule
属性时,特性才会进行同步。删除:要删除实体的调度,请在实体数据中将属性
schedule
设置为false
。//Entity Data { // Your entity attributes/data.. // Schedule data to sync with the entity "schedule": { "zone": "main", "status": 1, "from_date" : "2021-03-08 08:00", "to_date" : "2021-03-08 08:00", "work_times": [ { "day_id": 2, "start_hour": "2021-03-08 08:00", "end_hour": "2021-03-08 10:00", "shift_time" : "60", }, { "day_id": 1, "start_hour": "2021-03-08 07:00", "end_hour": "2021-03-08 12:30", "shift_time" : "60", } ] } }
-
实体
-
调度
保存多态调度
-
关系
- worktimes
hasMany
返回调度相关的所有工作时间。
- worktimes
-
方法
- getShifts(['dateRange','busyShifts']) 根据调度的工作时间以分钟间隔返回所有班次。
要获取带有日模型的班次,请在请求中添加关系
workTimes.day
。- 参数
- dateRange
Array
一个包含要生成班次的日期范围的数组,如果不存在此参数,将加载当前日期直到未来6天。//Obtain the shifts to 2021-09-01 until 2021-09-03 according to workTimes by day of the shedule model $scheduleModel->getShifts(['dateRange' => ['2021-09-01', '2021-09-03']])
- busyShifts
Array of Arrays
包含忙碌班次引用的数组,以验证由方法生成的班次是否忙碌。$scheduleModel->getShifts([ 'busyShifts' => [ ['startTime' => '06:00:00', 'endTime' => '08:22:00', 'calendarDate' => '2021-09-06'], ['startTime' => '06:00:00', 'endTime' => '07:22:00', 'calendarDate' => '2021-09-02'], ['startTime' => '08:00:00', 'endTime' => '09:00:00', 'calendarDate' => '2021-09-03'], ] ]);
- dateRange
- 响应
按日历日期、日ID和开始时间升序排列班次。//You get a array of arrays with shifts on this format [▼ "busyBy" => [/*busy model set on parameter busyShift*/] "calendarDate" => "2021-09-06" "day" => //Modules\Ischedulable\Entities\Day Model "dayId" => 1 //Iso Day "endTime" => "09:00:00" "isBusy" => 1 "scheduleId" => 7 "startTime" => "08:00:00" ]
- 参数
- getShifts(['dateRange','busyShifts']) 根据调度的工作时间以分钟间隔返回所有班次。
-
-
工作时间
保存一个或多个工作时间到调度
-
日
具有以ISO数字表示的可翻译星期。