|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
Lib::loadClass('ACL');
|
|
Lib::loadClass('ACL');
|
|
|
|
|
+Lib::loadClass('SqlQueryWhereBuilder');
|
|
|
|
|
|
|
|
// usage: (Acl class)::buildQuery($params): return new AclQueryFeatures($this, $params);
|
|
// usage: (Acl class)::buildQuery($params): return new AclQueryFeatures($this, $params);
|
|
|
// (view): $queryFeatures = $acl->buildQuery($params);
|
|
// (view): $queryFeatures = $acl->buildQuery($params);
|
|
@@ -24,7 +25,7 @@ class AclQueryFeatures {
|
|
|
// TODO: _legacyMode = ($from instanceof simple schema or another programmed objects)
|
|
// TODO: _legacyMode = ($from instanceof simple schema or another programmed objects)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function parseQueryValue($searchQuery, $fieldType = 'xsd:string') {
|
|
|
|
|
|
|
+ public function parseQueryValue($fieldName, $searchQuery, $fieldType = 'xsd:string') {
|
|
|
if ('!NULL' === $searchQuery) return ['is not null', null];
|
|
if ('!NULL' === $searchQuery) return ['is not null', null];
|
|
|
if ('IS NOT NULL' === $searchQuery) return ['is not null', null];
|
|
if ('IS NOT NULL' === $searchQuery) return ['is not null', null];
|
|
|
if ('NULL' === $searchQuery) return ['is null', null];
|
|
if ('NULL' === $searchQuery) return ['is null', null];
|
|
@@ -61,23 +62,20 @@ class AclQueryFeatures {
|
|
|
default: return ['not like', substr($searchQuery, 1)];
|
|
default: return ['not like', substr($searchQuery, 1)];
|
|
|
}
|
|
}
|
|
|
default: {
|
|
default: {
|
|
|
- if (false !== strpos($searchQuery, '%')) return ['like', $searchQuery];
|
|
|
|
|
- if ('xsd:number' === $fieldType) return ['=', $searchQuery];
|
|
|
|
|
- // if ($acl->isColTypeNumber($fieldName)) return ['=', $searchQuery];
|
|
|
|
|
- // else {
|
|
|
|
|
- // $queryWhereBuilder = new SqlQueryWhereBuilder();
|
|
|
|
|
- // $searchWords = $queryWhereBuilder->splitQueryToWords($v);
|
|
|
|
|
- // $sqlWhereWords = array();
|
|
|
|
|
- // if (!empty($searchWords)) {
|
|
|
|
|
- // foreach ($searchWords as $word) {
|
|
|
|
|
- // $sqlWord = $this->_db->_($word);
|
|
|
|
|
- // $sqlWhereWords[] = "t.`{$fldName}` like '%{$sqlWord}%'";
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // if (!empty($searchWords)) {
|
|
|
|
|
- // $sql_where_and[] = "(" . implode(" and ", $sqlWhereWords) . ")";
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ switch ($fieldType) {
|
|
|
|
|
+ case 'xsd:number':
|
|
|
|
|
+ case 'xsd:integer': return ['=', $searchQuery];
|
|
|
|
|
+ default: {
|
|
|
|
|
+ if (false !== strpos($searchQuery, '%')) return ['like', $searchQuery];
|
|
|
|
|
+ $queryWhereBuilder = new SqlQueryWhereBuilder();
|
|
|
|
|
+ return ['and'
|
|
|
|
|
+ , array_map(function ($word) use ($fieldName) {
|
|
|
|
|
+ return [$fieldName, 'like', "%{$word}%"];
|
|
|
|
|
+ }, $queryWhereBuilder->splitQueryToWords($searchQuery)
|
|
|
|
|
+ )
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return ['=', $searchQuery];
|
|
return ['=', $searchQuery];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -147,7 +145,7 @@ class AclQueryFeatures {
|
|
|
if ('f_' === substr($k, 0, 2) && strlen($k) > 3) {
|
|
if ('f_' === substr($k, 0, 2) && strlen($k) > 3) {
|
|
|
$fieldName = substr($k, 2);
|
|
$fieldName = substr($k, 2);
|
|
|
$fieldType = $this->_acl->getXsdFieldType($fieldName);
|
|
$fieldType = $this->_acl->getXsdFieldType($fieldName);
|
|
|
- list($comparisonSign, $value) = $this->parseQueryValue($v, $fieldType);
|
|
|
|
|
|
|
+ list($comparisonSign, $value) = $this->parseQueryValue($fieldName, $v, $fieldType);
|
|
|
DBG::log([ $fieldName, $fieldType, $comparisonSign, $value ], 'array', "parseQueryValue");
|
|
DBG::log([ $fieldName, $fieldType, $comparisonSign, $value ], 'array', "parseQueryValue");
|
|
|
$this->_query->where($fieldName, $comparisonSign, $value);
|
|
$this->_query->where($fieldName, $comparisonSign, $value);
|
|
|
} else if ('sf_' === substr($k, 0, 3) && strlen($k) > 4) {
|
|
} else if ('sf_' === substr($k, 0, 3) && strlen($k) > 4) {
|