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.

Method of the class: DataStore{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->add_order_by_params( $query_args, $from_arg, $id_cell );
$query_args(array) (required)
Parameters supplied by the user.
$from_arg(string) (required)
Target of the JOIN sql param.
$id_cell(string) (required)
ID cell identifier, like table_name.id_column_name.

DataStore::add_order_by_params() code WC 9.3.3

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 );
		}
	}
}