SearchKey Properties
|
$field |
Database table field name
If $field is empty, the condition itself is ignored. The rest of properties is evaluated, anyway.
|
$value |
Value to be compared
Value type should correspond to the database field type, although simple conversions are performed automatically.
String values may contain wildcard character "∗", defined as SearchKey::STRING_WILDCARD constant. These have effect when combined with comparators SearchKey::CMP_LIKE or SearchKey::CMP_NOTLIKE.
A special case is value of type array(). Together with SearchKey::CMP_EQUAL or SearchKey::CMP_NOTEQUAL comparator, it is interpreted as SQL "[field name] IN (...)" or "NOT [field name] IN (...)" respectively.
An empty array will be interpreted as "IN (0)". Handle this case in the caller's code if it is not convenient for you.
|
$comparator |
field : value comparator, one of following constants:
SearchKey::CMP_EQUAL = 0 (default) SearchKey::CMP_LESS = 1 SearchKey::CMP_LESSEQUAL = 2 SearchKey::CMP_GREATER = 3 SearchKey::CMP_GREATEREQUAL = 4 SearchKey::CMP_NOTEQUAL = 5 SearchKey::CMP_LIKE = 6 (string values only) SearchKey::CMP_NOTLIKE = 7 (string values only)
|
$orderBy |
Optional ordering field like "created" or "created desc". May also contain expressions like "COUNT(DISTINCT mark_id) desc".
More ordering fields may be concatenated either by comas or in an array.
Multiple $orderBy ordering is given by the SearchKey structure and maybe does not fit the ordering desired. Therefore, it is possible to fix it by explicite setting the $orderBy position like "(1)name", "(2)created desc" etc.
|
$andKey |
Optional another SearchKey related with SQL "AND"
|
$orKey |
Optional another SearchKey related with SQL "OR"
|
SearchKey Methods
|
function __construct ($field = '', $value = 0, $cmp = self::CMP_EQUAL, $partial = false) |
Constructor
Arguments $field, $value and $cmp set corresponding fields.
The argument $partial is used together with string values and if true, it inserts SearchKey::STRING_WILDCARD before and after the value.
|
function AddAndKey (SearchKey $key) |
Inserts the $key as the last element of the andKey chain
|
function AddOrKey (SearchKey $key) |
Inserts the $key as the last element of the orKey chain
|
Examples:
(assumed interpretation by MySqlDataProvider)
|
$key = new SearchKey('occurrence'); |
interprets to "WHERE 'occurrence'=0"
|
$key = new SearchKey('created', '2017-01-25 01:30', SearchKey::CMP_GREATEREQUAL); |
Case field 'created' is of MySql type
- date: interprets to "WHERE `created`=>'2017-1-25'"
- time: interprets to "WHERE `created`=>'01:30:00'"
- datetime: interprets to "WHERE `created`=>'2017-1-25 01:30:00'"
|
$key = new SearchKey('id', array(22,28,46)); |
interprets to "WHERE `id` IN (22,28,46)" |
$key1 = new SearchKey('name', 'ann', SearchKey::LIKE, true);
$key1->AddOrKey(new SearchKey('name', 'john', SearchKey::LIKE));
$key = new SearchKey('age', 18, SearchKey::CMP_GREATEREQUAL);
$key->AddAndKey($key1);
$key->orderBy = 'name, age desc';
|
$key interprets to "WHERE `age` >=18 AND (`name` LIKE '%ann%" OR `name` LIKE 'john') ORDER BY `name`, `age` desc" |