Yoast\WP\Lib
ORM::add_simple_condition
Compiles a simple COLUMN SEPARATOR VALUE style HAVING or WHERE condition into a string and value ready to be passed to the add_condition method.
Avoids duplication of the call to quote_identifier. If column_name is an associative array, it will add a condition for each column.
Метод класса: ORM{}
Хуков нет.
Возвращает
ORM.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->add_simple_condition( $type, $column_name, $separator, $value );
- $type(строка) (обязательный)
- The type.
- $column_name(строка|массив) (обязательный)
- The table column.
- $separator(строка) (обязательный)
- The separator.
- $value(разное) (обязательный)
- The value.
Код ORM::add_simple_condition() ORM::add simple condition Yoast 26.7
protected function add_simple_condition( $type, $column_name, $separator, $value ) {
$multiple = \is_array( $column_name ) ? $column_name : [ $column_name => $value ];
$result = $this;
foreach ( $multiple as $key => $val ) {
// Add the table name in case of ambiguous columns.
if ( \count( $result->join_sources ) > 0 && \strpos( $key, '.' ) === false ) {
$table = $result->table_name;
if ( $result->table_alias !== null ) {
$table = $result->table_alias;
}
$key = "{$table}.{$key}";
}
$key = $result->quote_identifier( $key );
$placeholder = ( $val === null ) ? 'NULL' : '%s';
$result = $result->add_condition( $type, "{$key} {$separator} {$placeholder}", $val );
}
return $result;
}