Yoast\WP\Lib

ORM::call_aggregate_db_function()protectedYoast 1.0

Executes an aggregate query on the current connection.

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

Хуков нет.

Возвращает

int.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->call_aggregate_db_function( $sql_function, $column );
$sql_function(строка) (обязательный)
The aggregate function to call eg. MIN, COUNT, etc.
$column(строка) (обязательный)
The column to execute the aggregate query against.

Код ORM::call_aggregate_db_function() Yoast 22.4

protected function call_aggregate_db_function( $sql_function, $column ) {
	$alias        = \strtolower( $sql_function );
	$sql_function = \strtoupper( $sql_function );
	if ( $column !== '*' ) {
		$column = $this->quote_identifier( $column );
	}
	$result_columns       = $this->result_columns;
	$this->result_columns = [];
	$this->select_expr( "{$sql_function}({$column})", $alias );
	$result               = $this->find_one();
	$this->result_columns = $result_columns;
	$return_value         = 0;
	if ( $result !== false && isset( $result->{$alias} ) ) {
		if ( ! \is_numeric( $result->{$alias} ) ) {
			$return_value = $result->{$alias};
		}
		// phpcs:ignore Universal.Operators.StrictComparisons -- Reason: This loose comparison seems intentional.
		elseif ( (int) $result->{$alias} == (float) $result->{$alias} ) {
			$return_value = (int) $result->{$alias};
		}
		else {
			$return_value = (float) $result->{$alias};
		}
	}

	return $return_value;
}