activity_model.php
3 months ago
agent_meta_model.php
3 months ago
agent_model.php
3 months ago
booking_meta_model.php
3 months ago
booking_model.php
1 week ago
bundle_meta_model.php
3 months ago
bundle_model.php
1 week ago
cart_item_model.php
3 months ago
cart_meta_model.php
3 months ago
cart_model.php
2 weeks ago
connector_model.php
3 months ago
customer_meta_model.php
3 months ago
customer_model.php
1 month ago
invoice_model.php
2 weeks ago
join_bundles_services_model.php
3 months ago
location_category_model.php
3 months ago
location_model.php
3 months ago
meta_model.php
3 months ago
model.php
3 months ago
off_period_model.php
3 months ago
order_intent_meta_model.php
3 months ago
order_intent_model.php
1 week ago
order_item_model.php
3 months ago
order_meta_model.php
3 months ago
order_model.php
1 month ago
otp_model.php
3 months ago
payment_request_model.php
3 months ago
process_job_model.php
3 months ago
process_model.php
1 month ago
recurrence_model.php
3 months ago
service_category_model.php
3 months ago
service_meta_model.php
3 months ago
service_model.php
3 months ago
session_model.php
3 months ago
settings_model.php
3 months ago
step_settings_model.php
3 months ago
transaction_intent_model.php
3 months ago
transaction_model.php
3 months ago
transaction_refund_model.php
3 months ago
work_period_model.php
3 months ago
off_period_model.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | class OsOffPeriodModel extends OsModel { |
| 4 | var $id, |
| 5 | $summary, |
| 6 | $start_date, |
| 7 | $end_date, |
| 8 | $start_time, |
| 9 | $end_time, |
| 10 | $start_datetime_utc, |
| 11 | $end_datetime_utc, |
| 12 | $service_id, |
| 13 | $agent_id, |
| 14 | $location_id, |
| 15 | $server_timezone, |
| 16 | $created_at, |
| 17 | $updated_at; |
| 18 | |
| 19 | function __construct( $id = false ) { |
| 20 | parent::__construct(); |
| 21 | $this->table_name = LATEPOINT_TABLE_BLOCKED_PERIODS; |
| 22 | $this->nice_names = array(); |
| 23 | |
| 24 | if ( $id ) { |
| 25 | $this->load_by_id( $id ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function set_utc_datetimes( bool $save = false ) { |
| 30 | if ( empty( $this->start_date ) || empty( $this->end_date ) || empty( $this->start_time ) || empty( $this->end_time ) ) { |
| 31 | return; |
| 32 | } |
| 33 | $this->start_datetime_utc = $this->get_start_datetime( 'UTC' )->format( LATEPOINT_DATETIME_DB_FORMAT ); |
| 34 | $this->end_datetime_utc = $this->get_end_datetime( 'UTC' )->format( LATEPOINT_DATETIME_DB_FORMAT ); |
| 35 | if ( $save ) { |
| 36 | $this->update_attributes( |
| 37 | [ |
| 38 | 'start_datetime_utc' => $this->start_datetime_utc, |
| 39 | 'end_datetime_utc' => $this->end_datetime_utc, |
| 40 | ] |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | protected function before_save() { |
| 47 | $this->set_utc_datetimes(); |
| 48 | $this->server_timezone = OsTimeHelper::get_wp_timezone(); |
| 49 | } |
| 50 | |
| 51 | public function get_start_datetime( string $set_timezone = 'UTC' ): OsWpDateTime { |
| 52 | try { |
| 53 | // start_time and start_date is legacy stored in wordpress timezone |
| 54 | $dateTime = new OsWpDateTime( $this->start_date . ' 00:00:00', OsTimeHelper::get_wp_timezone() ); |
| 55 | if ( $this->start_time > 0 ) { |
| 56 | $dateTime->modify( '+' . $this->start_time . ' minutes' ); |
| 57 | } |
| 58 | if ( $set_timezone ) { |
| 59 | $dateTime->setTimezone( new DateTimeZone( $set_timezone ) ); |
| 60 | } |
| 61 | return $dateTime; |
| 62 | } catch ( Exception $e ) { |
| 63 | return new OsWpDateTime( 'now' ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public function get_end_datetime( string $set_timezone = 'UTC' ): OsWpDateTime { |
| 68 | try { |
| 69 | // start_time and start_date is legacy stored in wordpress timezone |
| 70 | $dateTime = new OsWpDateTime( $this->end_date . ' 00:00:00', OsTimeHelper::get_wp_timezone() ); |
| 71 | if ( $this->end_time > 0 ) { |
| 72 | $dateTime->modify( '+' . $this->end_time . ' minutes' ); |
| 73 | } |
| 74 | if ( $set_timezone ) { |
| 75 | $dateTime->setTimezone( new DateTimeZone( $set_timezone ) ); |
| 76 | } |
| 77 | return $dateTime; |
| 78 | } catch ( Exception $e ) { |
| 79 | return new OsWpDateTime( 'now' ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | protected function allowed_params( $role = 'admin' ) { |
| 85 | $allowed_params = array( |
| 86 | 'id', |
| 87 | 'summary', |
| 88 | 'start_date', |
| 89 | 'end_date', |
| 90 | 'start_time', |
| 91 | 'end_time', |
| 92 | 'start_datetime_utc', |
| 93 | 'end_datetime_utc', |
| 94 | 'service_id', |
| 95 | 'agent_id', |
| 96 | 'location_id', |
| 97 | 'server_timezone', |
| 98 | 'created_at', |
| 99 | 'updated_at', |
| 100 | ); |
| 101 | return $allowed_params; |
| 102 | } |
| 103 | |
| 104 | protected function params_to_save( $role = 'admin' ) { |
| 105 | $params_to_save = array( |
| 106 | 'id', |
| 107 | 'summary', |
| 108 | 'start_date', |
| 109 | 'end_date', |
| 110 | 'start_time', |
| 111 | 'end_time', |
| 112 | 'start_datetime_utc', |
| 113 | 'end_datetime_utc', |
| 114 | 'service_id', |
| 115 | 'agent_id', |
| 116 | 'location_id', |
| 117 | 'server_timezone', |
| 118 | 'created_at', |
| 119 | 'updated_at', |
| 120 | ); |
| 121 | return $params_to_save; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | protected function properties_to_validate() { |
| 127 | $validations = array( |
| 128 | 'start_date' => array( 'presence' ), |
| 129 | 'end_date' => array( 'presence' ), |
| 130 | ); |
| 131 | return $validations; |
| 132 | } |
| 133 | } |
| 134 |