PHP Класс FOF30\Model\DataModel\Filter\Number

Наследование: extends AbstractFilter
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
between ( mixed $from, mixed $to, boolean $include = true ) : string Perform a between limits match. When $include is true the condition tested is: $from <= VALUE <= $to When $include is false the condition tested is: $from < VALUE < $to
interval ( integer | float $value, integer | float $interval, boolean $include = true ) : string Perform an interval match. It's similar to a 'between' match, but the from and to values are calculated based on $value and $interval: $value - $interval < VALUE < $value + $interval
modulo ( integer | float $value, integer | float $interval, boolean $include = true ) : string Perform an interval match. It's similar to a 'between' match, but the from and to values are calculated based on $value and $interval: $value - $interval < VALUE < $value + $interval
outside ( mixed $from, mixed $to, boolean $include = false ) : string Perform an outside limits match. When $include is true the condition tested is: (VALUE <= $from) || (VALUE >= $to) When $include is false the condition tested is: (VALUE < $from) || (VALUE > $to)
partial ( mixed $value ) : string The partial match is mapped to an exact match
range ( mixed $from, mixed $to, boolean $include = true ) : string Perform a range limits match. When $include is true the condition tested is: $from <= VALUE <= $to When $include is false the condition tested is: $from < VALUE < $to
sanitiseValue ( mixed $value ) : mixed Sanitises float values. Really ugly and desperate workaround. Read below.
search ( mixed $value, string $operator = '=' ) : string Overrides the parent to handle floats in locales where the decimal separator is a comma instead of a dot

Описание методов

between() публичный Метод

Perform a between limits match. When $include is true the condition tested is: $from <= VALUE <= $to When $include is false the condition tested is: $from < VALUE < $to
public between ( mixed $from, mixed $to, boolean $include = true ) : string
$from mixed The lowest value to compare to
$to mixed The higherst value to compare to
$include boolean Should we include the boundaries in the search?
Результат string The SQL where clause for this search

interval() публичный Метод

Perform an interval match. It's similar to a 'between' match, but the from and to values are calculated based on $value and $interval: $value - $interval < VALUE < $value + $interval
public interval ( integer | float $value, integer | float $interval, boolean $include = true ) : string
$value integer | float The center value of the search space
$interval integer | float The width of the search space
$include boolean Should I include the boundaries in the search?
Результат string The SQL where clause

modulo() публичный Метод

Perform an interval match. It's similar to a 'between' match, but the from and to values are calculated based on $value and $interval: $value - $interval < VALUE < $value + $interval
public modulo ( integer | float $value, integer | float $interval, boolean $include = true ) : string
$value integer | float The starting value of the search space
$interval integer | float The interval period of the search space
$include boolean Should I include the boundaries in the search?
Результат string The SQL where clause

outside() публичный Метод

Perform an outside limits match. When $include is true the condition tested is: (VALUE <= $from) || (VALUE >= $to) When $include is false the condition tested is: (VALUE < $from) || (VALUE > $to)
public outside ( mixed $from, mixed $to, boolean $include = false ) : string
$from mixed The lowest value of the excluded range
$to mixed The higherst value of the excluded range
$include boolean Should we include the boundaries in the search?
Результат string The SQL where clause for this search

partial() публичный Метод

The partial match is mapped to an exact match
public partial ( mixed $value ) : string
$value mixed The value to compare to
Результат string The SQL where clause for this search

range() публичный Метод

Perform a range limits match. When $include is true the condition tested is: $from <= VALUE <= $to When $include is false the condition tested is: $from < VALUE < $to
public range ( mixed $from, mixed $to, boolean $include = true ) : string
$from mixed The lowest value to compare to
$to mixed The higherst value to compare to
$include boolean Should we include the boundaries in the search?
Результат string The SQL where clause for this search

sanitiseValue() публичный Метод

Some locales, such as el-GR, use a comma as the decimal separator. This means that $x = 1.23; echo (string) $x; will yield 1,23 (with a comma!) instead of 1.23 (with a dot!). This affects the way the SQL WHERE clauses are generated. All database servers expect a dot as the decimal separator. If they see a decimal with a comma as the separator they throw a SQL error. This method will try to replace commas with dots. I tried working around this with locale switching and the %F (capital F) format option in sprintf to no avail. I'm pretty sure I was doing something wrong, but I ran out of time trying to find an academically correct solution. The current implementation of sanitiseValue is a silly hack around the problem. If you have a proper –and better performing– solution please send in a PR and I'll put it to the test.
public sanitiseValue ( mixed $value ) : mixed
$value mixed A string representing a number, integer, float or array of them.
Результат mixed The sanitised value, or null if the input wasn't numeric.