- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
public function buildCriteria($table, $conditions)
{
$source_table = $table->getTableName();
$criteria = new criteria($source_table, 'keyword');
foreach ($conditions as $field => $conds) {
if (is_array($conds)) {
if (isset($conds['plus'])) {
$word = array_shift($conds['plus']);
$like_criterion = new criterion($field, '%' . $word . '%', criteria::LIKE);
foreach ($conds['plus'] as $word) {
$like_criterion->addOr(new criterion($field, '%' . $word . '%', criteria::LIKE));
}
}
if (isset($conds['minus'])) {
$word = array_shift($conds['minus']);
$not_like_criterion = new criterion($field, '%' . $word . '%', criteria::NOT_LIKE);
foreach ($conds['minus'] as $word) {
$not_like_criterion->addAnd(new criterion($field, '%' . $word . '%', criteria::NOT_LIKE));
}
}
if (isset($conds['less'])) {
if (!is_array($conds['less'])) {
$conds['less'] = array($conds['less']);
}
$word = array_shift($conds['less']);
$less_criterion = new criterion($field, $word, criteria::LESS);
foreach ($conds['less'] as $word) {
$less_criterion->addAnd(new criterion($field, $word, criteria::LESS));
}
}
if (isset($conds['less_eq'])) {
if (!is_array($conds['less_eq'])) {
$conds['less_eq'] = array($conds['less_eq']);
}
$word = array_shift($conds['less_eq']);
$less_eq_criterion = new criterion($field, $word, criteria::LESS_EQUAL );
foreach ($conds['less_eq'] as $word) {
$less_eq_criterion->addAnd(new criterion($field, $word, criteria::LESS_EQUAL));
}
}
}
}
$main_criterion = new criterion();
if (!empty($like_criterion)) {
$main_criterion->add($like_criterion);
$add_method = 'addAnd';
}
if (!empty($not_like_criterion)) {
if (empty($add_method)) {
$add_method = 'add';
}
$main_criterion->$add_method($not_like_criterion);
}
if (!empty($less_criterion)) {
if (empty($add_method)) {
$add_method = 'add';
}
$main_criterion->$add_method($less_criterion);
}
if (!empty($less_eq_criterion)) {
if (empty($add_method)) {
$add_method = 'add';
}
$main_criterion->$add_method($less_eq_criterion);
}
$criteria->add($main_criterion);
return $criteria;
}
public function testBuildCriteria()
{
$table = new mockStubKeywordTable();
$table->setReturnValue('getTableName', 'test_table');
$query = $this->keywordQuery;
$data['field1']['less'] = 5;
$data['field2']['less_eq'] = 10;
/* $data['field2']['greater_eq'] = 11;
$data['field3']['greater'] = 12;
guest 10.01.2009 13:24 # 0
Тебе требуется - ты и делай.
guest8 25.09.2019 22:45 # −999