blocked_period.php
3 months ago
booked_period.php
3 months ago
booking_request.php
3 months ago
booking_resource.php
3 months ago
booking_slot.php
3 months ago
filter.php
3 months ago
process_action.php
1 month ago
process_event.php
1 month ago
role.php
2 weeks ago
router.php
3 months ago
step.php
3 months ago
stripe_connect_customer.php
3 months ago
time_period.php
3 months ago
user.php
3 months ago
work_period.php
3 months ago
work_period.php
70 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 ) { |
| 20 | $this->weight++; |
| 21 | } |
| 22 | if ( $this->agent_id ) { |
| 23 | $this->weight++; |
| 24 | } |
| 25 | if ( $this->location_id ) { |
| 26 | $this->weight++; |
| 27 | } |
| 28 | if ( $this->custom_date ) { |
| 29 | $this->weight = $this->weight + 3; |
| 30 | } |
| 31 | return $this->weight; |
| 32 | } |
| 33 | |
| 34 | function __construct( $args = [] ) { |
| 35 | $allowed_props = self::allowed_props(); |
| 36 | foreach ( $args as $key => $arg ) { |
| 37 | if ( in_array( $key, $allowed_props ) ) { |
| 38 | $this->$key = $arg; |
| 39 | } |
| 40 | } |
| 41 | $this->calculate_weight(); |
| 42 | } |
| 43 | |
| 44 | public static function create_from_work_period_model( \OsWorkPeriodModel $work_period ): WorkPeriod { |
| 45 | return new WorkPeriod( |
| 46 | [ |
| 47 | 'custom_date' => $work_period->custom_date, |
| 48 | 'week_day' => $work_period->week_day, |
| 49 | 'start_time' => $work_period->start_time, |
| 50 | 'end_time' => $work_period->end_time, |
| 51 | 'agent_id' => $work_period->agent_id, |
| 52 | 'location_id' => $work_period->location_id, |
| 53 | 'service_id' => $work_period->service_id, |
| 54 | ] |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | public static function allowed_props(): array { |
| 59 | return [ |
| 60 | 'custom_date', |
| 61 | 'week_day', |
| 62 | 'start_time', |
| 63 | 'end_time', |
| 64 | 'agent_id', |
| 65 | 'location_id', |
| 66 | 'service_id', |
| 67 | ]; |
| 68 | } |
| 69 | } |
| 70 |