blocked_period.php
1 year ago
booked_period.php
1 year ago
booking_request.php
1 year ago
booking_resource.php
1 year ago
booking_slot.php
1 year ago
filter.php
1 year ago
process_action.php
1 year ago
process_event.php
1 year ago
role.php
1 year ago
router.php
1 year ago
step.php
1 year ago
stripe_connect_customer.php
1 year ago
time_period.php
1 year ago
user.php
1 year ago
work_period.php
1 year ago
work_period.php
53 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2021 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | namespace LatePoint\Misc; |
| 7 | |
| 8 | class WorkPeriod{ |
| 9 | public ?string $custom_date = null; |
| 10 | public int $week_day; |
| 11 | public int $start_time = 0; |
| 12 | public int $end_time = 0; |
| 13 | public int $service_id = 0; |
| 14 | public int $agent_id = 0; |
| 15 | public int $location_id = 0; |
| 16 | public int $weight = 0; |
| 17 | |
| 18 | function calculate_weight(): int{ |
| 19 | if($this->service_id) $this->weight++; |
| 20 | if($this->agent_id) $this->weight++; |
| 21 | if($this->location_id) $this->weight++; |
| 22 | if($this->custom_date) $this->weight = $this->weight + 3; |
| 23 | return $this->weight; |
| 24 | } |
| 25 | |
| 26 | function __construct($args = []){ |
| 27 | $allowed_props = self::allowed_props(); |
| 28 | foreach($args as $key => $arg){ |
| 29 | if(in_array($key, $allowed_props)) $this->$key = $arg; |
| 30 | } |
| 31 | $this->calculate_weight(); |
| 32 | } |
| 33 | |
| 34 | public static function create_from_work_period_model(\OsWorkPeriodModel $work_period): WorkPeriod{ |
| 35 | return new WorkPeriod([ 'custom_date' => $work_period->custom_date, |
| 36 | 'week_day' => $work_period->week_day, |
| 37 | 'start_time' => $work_period->start_time, |
| 38 | 'end_time' => $work_period->end_time, |
| 39 | 'agent_id' => $work_period->agent_id, |
| 40 | 'location_id' => $work_period->location_id, |
| 41 | 'service_id' => $work_period->service_id]); |
| 42 | } |
| 43 | |
| 44 | public static function allowed_props(): array{ |
| 45 | return ['custom_date', |
| 46 | 'week_day', |
| 47 | 'start_time', |
| 48 | 'end_time', |
| 49 | 'agent_id', |
| 50 | 'location_id', |
| 51 | 'service_id']; |
| 52 | } |
| 53 | } |