Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableQuery::join
JOINs the main orders table with another table.
Метод класса: OrdersTableQuery{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->join( $table, $alias, $on, $join_type, $alias_once );
- $table(строка) (обязательный)
- Table name (including prefix).
- $alias(строка)
- Table alias to use.
По умолчанию:$table - $on(строка)
- ON clause.
По умолчанию:"wc_orders.id = {$alias}.order_id" - $join_type(строка)
- JOIN type: LEFT, RIGHT or INNER.
По умолчанию:'inner' - $alias_once(true|false)
- If TRUE, table won't be JOIN'ed again if already JOIN'ed.
По умолчанию:false
Код OrdersTableQuery::join() OrdersTableQuery::join WC 11.1.1
private function join( string $table, string $alias = '', string $on = '', string $join_type = 'inner', bool $alias_once = false ) {
$alias = empty( $alias ) ? $table : $alias;
$join_type = strtoupper( trim( $join_type ) );
if ( $this->tables['orders'] === $alias ) {
// translators: %s is a table name.
throw new \Exception( sprintf( __( '%s can not be used as a table alias in OrdersTableQuery', 'woocommerce' ), $alias ) );
}
if ( empty( $on ) ) {
if ( $this->tables['orders'] === $table ) {
$on = "`{$this->tables['orders']}`.id = `{$alias}`.id";
} else {
$on = "`{$this->tables['orders']}`.id = `{$alias}`.order_id";
}
}
if ( isset( $this->join[ $alias ] ) ) {
if ( ! $alias_once ) {
// translators: %s is a table name.
throw new \Exception( sprintf( __( 'Can not re-use table alias "%s" in OrdersTableQuery.', 'woocommerce' ), $alias ) );
}
return;
}
if ( '' === $join_type || ! in_array( $join_type, array( 'LEFT', 'RIGHT', 'INNER' ), true ) ) {
$join_type = 'INNER';
}
$sql_join = '';
$sql_join .= "{$join_type} JOIN `{$table}` ";
$sql_join .= ( $alias !== $table ) ? "AS `{$alias}` " : '';
$sql_join .= "ON ( {$on} )";
$this->join[ $alias ] = $sql_join;
}