null, 'day_of_week' => null, 'opening_mode' => 'fixed', 'opens_at' => null, 'closes_at' => null, 'sunrise_offset_minutes' => null, 'sunset_offset_minutes' => null, 'min_open_time' => null, 'max_close_time' => null, 'is_closed' => false ], $current, $input ); $data['resource_id'] = ScheduleValidator::resource( $data['resource_id'], $this->resources ); $data['day_of_week'] = CatalogValidator::integer( $data['day_of_week'], 'day_of_week', 1, 7 ); $data['opening_mode'] = CatalogValidator::choice( $data['opening_mode'], 'opening_mode', [ 'fixed', 'sun' ] ); $data['is_closed'] = CatalogValidator::boolean( $data['is_closed'], 'is_closed' ); foreach ( [ 'sunrise_offset_minutes', 'sunset_offset_minutes' ] as $field ) { $data[ $field ] = CatalogValidator::integer( $data[ $field ], $field, -32768, 32767, true ); } foreach ( [ 'min_open_time', 'max_close_time' ] as $field ) { $data[ $field ] = ScheduleValidator::clock( $data[ $field ], $field ); } if ( null !== $data['min_open_time'] && null !== $data['max_close_time'] && $data['min_open_time'] >= $data['max_close_time'] ) { CatalogValidator::invalid( 'max_close_time', __( 'Closing time must be after opening time on the same day.', 'abece-booking' ) ); } if ( 'fixed' === $data['opening_mode'] || $data['is_closed'] ) { $data = ScheduleValidator::fixed( $data ); foreach ( [ 'sunrise_offset_minutes', 'sunset_offset_minutes', 'min_open_time', 'max_close_time' ] as $field ) { $data[ $field ] = null; } } else { // Unused fixed times must not influence sun mode. foreach ( [ 'opens_at', 'closes_at' ] as $field ) { ScheduleValidator::clock( $data[ $field ], $field ); $data[ $field ] = null; } } return $data; } }