Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::process_date_args()privateWC 1.0

Processes date-related query args and merges the result into 'date_query'.

{} Это метод класса: OrdersTableQuery{}

Хуков нет.

Возвращает

null. Ничего.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->process_date_args(): void;

Код OrdersTableQuery::process_date_args() WC 6.9.1

private function process_date_args(): void {
	$valid_operators = array( '>', '>=', '=', '<=', '<', '...' );
	$date_queries    = array();
	$gmt_date_keys   = array(
		'date_created_gmt',
		'date_updated_gmt',
		'date_paid_gmt',
		'date_completed_gmt',
	);

	foreach ( array_filter( $gmt_date_keys, array( $this, 'arg_isset' ) ) as $date_key ) {
		$date_value = $this->args[ $date_key ];
		$operator   = '=';
		$dates      = array();

		if ( is_string( $date_value ) && preg_match( self::REGEX_SHORTHAND_DATES, $date_value, $matches ) ) {
			$operator = in_array( $matches[2], $valid_operators, true ) ? $matches[2] : '';

			if ( ! empty( $matches[1] ) ) {
				$dates[] = $this->date_to_date_query_arg( $matches[1] );
			}

			$dates[] = $this->date_to_date_query_arg( $matches[3] );
		} else {
			$dates[] = $this->date_to_date_query_arg( $date_value );
		}

		if ( empty( $dates ) || ! $operator || ( '...' === $operator && count( $dates ) < 2 ) ) {
			throw new \Exception( 'Invalid date_query' );
		}

		$operator_to_keys = array();

		if ( in_array( $operator, array( '>', '>=', '...' ), true ) ) {
			$operator_to_keys[] = 'after';
		}

		if ( in_array( $operator, array( '<', '<=', '...' ), true ) ) {
			$operator_to_keys[] = 'before';
		}

		$date_queries[] = array_merge(
			array(
				'column'    => $date_key,
				'inclusive' => ! in_array( $operator, array( '<', '>' ), true ),
			),
			'=' === $operator
				? end( $dates )
				: array_combine( $operator_to_keys, $dates )
		);
	}

	// Add top-level date parameters to the date_query.
	$tl_query = array();
	foreach ( array( 'hour', 'minute', 'second', 'year', 'monthnum', 'week', 'day', 'year' ) as $tl_key ) {
		if ( $this->arg_isset( $tl_key ) ) {
			$tl_query[ $tl_key ] = $this->args[ $tl_key ];
			unset( $this->args[ $tl_key ] );
		}
	}

	if ( $tl_query ) {
		$tl_query['column'] = 'date_created_gmt';
		$date_queries[]     = $tl_query;
	}

	if ( $date_queries ) {
		if ( ! $this->arg_isset( 'date_query' ) ) {
			$this->args['date_query'] = array();
		}

		$this->args['date_query'] = array_merge(
			array( 'relation' => 'AND' ),
			$date_queries,
			$this->args['date_query']
		);
	}

	$this->process_date_query_columns();
}