Automattic\WooCommerce\Admin\API\Reports\Categories

DataStore::add_order_by_params()protectedWC 1.0

Fills ORDER BY clause of SQL request based on user supplied parameters.

Метод класса: DataStore{}

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_order_by_params( $query_args, $from_arg, $id_cell );
$query_args(массив) (обязательный)
Parameters supplied by the user.
$from_arg(строка) (обязательный)
Target of the JOIN sql param.
$id_cell(строка) (обязательный)
ID cell identifier, like table_name.id_column_name.

Код DataStore::add_order_by_params() WC 8.7.0

protected function add_order_by_params( $query_args, $from_arg, $id_cell ) {
	global $wpdb;

	// Sanitize input: guarantee that the id cell in the join is quoted with backticks.
	$id_cell_segments   = explode( '.', str_replace( '`', '', $id_cell ) );
	$id_cell_identifier = '`' . implode( '`.`', $id_cell_segments ) . '`';

	$lookup_table    = self::get_db_table_name();
	$order_by_clause = $this->add_order_by_clause( $query_args, $this );
	$this->add_orderby_order_clause( $query_args, $this );

	if ( false !== strpos( $order_by_clause, '_terms' ) ) {
		$join = "JOIN {$wpdb->terms} AS _terms ON {$id_cell_identifier} = _terms.term_id";
		if ( 'inner' === $from_arg ) {
			// Even though this is an (inner) JOIN, we're adding it as a `left_join` to
			// affect its order in the query statement. The SqlQuery::$sql_filters variable
			// determines the order in which joins are concatenated.
			// See: https://github.com/woocommerce/woocommerce-admin/blob/1f261998e7287b77bc13c3d4ee2e84b717da7957/src/API/Reports/SqlQuery.php#L46-L50.
			$this->subquery->add_sql_clause( 'left_join', $join );
		} else {
			$this->add_sql_clause( 'join', $join );
		}
	}
}