|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
Lib::loadClass('TypespecialBase');
|
|
|
+Lib::loadClass('SqlQueryWhereBuilder');
|
|
|
|
|
|
class TypespecialVariable extends TypespecialBase {
|
|
|
|
|
|
@@ -508,48 +509,70 @@ jQuery(document).ready(function(){
|
|
|
}
|
|
|
case '__ZASOB': {
|
|
|
$db = DB::getDB();
|
|
|
- $query = trim($query, ' %');
|
|
|
- $query = $db->_($query);
|
|
|
- $sqlLimit = 20;
|
|
|
- $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
|
|
|
- $sqlWhere = "";
|
|
|
+ $sqlQuery = new stdClass();
|
|
|
+ $sqlQuery->limit = 20;
|
|
|
+ $sqlQuery->orderBy = "";
|
|
|
+ $sqlQuery->selectLabel = "concat(z.`TYPE`, ' ', z.`DESC`)";
|
|
|
+ $sqlQuery->selectAddBestFit = "";
|
|
|
+ $sqlQuery->whereAddQueryByWords = "";
|
|
|
+
|
|
|
+ $sqlWhereAddType = "";
|
|
|
if (!empty($params['zasob_type_in'])) {
|
|
|
if (is_scalar($params['zasob_type_in'])) $params['zasob_type_in'] = array($params['zasob_type_in']);
|
|
|
- $sqlWhere = " and z.`TYPE` IN('" . implode("','", $params['zasob_type_in']) . "') ";
|
|
|
+ $sqlWhereAddType = " and z.`TYPE` IN('" . implode("','", $params['zasob_type_in']) . "') ";
|
|
|
|
|
|
if (in_array('KOMORKA', $params['zasob_type_in'])) {
|
|
|
- $sqlSelectLabel = "concat(z.`TYPE`, ' ', z.`DESC` , ' (', (select zp.`DESC` from `CRM_LISTA_ZASOBOW` as zp where zp.`ID`=z.`PARENT_ID` limit 1), ')')";
|
|
|
+ $sqlQuery->selectLabel = "concat(z.`TYPE`, ' ', z.`DESC` , ' (', (select zp.`DESC` from `CRM_LISTA_ZASOBOW` as zp where zp.`ID`=z.`PARENT_ID` limit 1), ')')";
|
|
|
}
|
|
|
}
|
|
|
+ $query = trim($query, ' %');
|
|
|
+ $sqlQuery->_queryByWords = array();
|
|
|
if (is_numeric($query)) {
|
|
|
- $sql = "select z.`ID`
|
|
|
- , {$sqlSelectLabel} as `LABEL`
|
|
|
- , IF (z.`ID`='{$query}', 1000,
|
|
|
- IF (z.`ID` like '{$query}%', 900, 100)
|
|
|
- ) as _bestFit
|
|
|
- from `CRM_LISTA_ZASOBOW` as z
|
|
|
- where z.`A_STATUS` in('NORMAL', 'WAITING')
|
|
|
- and (z.`ID` like '%{$query}%' or z.`DESC` like '%{$query}%')
|
|
|
- {$sqlWhere}
|
|
|
- order by _bestFit DESC
|
|
|
- limit {$sqlLimit}
|
|
|
+ $sqlQueryNum = intval($query);
|
|
|
+ $sqlQuery->_queryByWords[] = "z.`ID` like '%{$sqlQueryNum}%'";
|
|
|
+ $sqlQuery->selectAddBestFit = "
|
|
|
+ , IF (z.`ID`='{$sqlQueryNum}', 1000,
|
|
|
+ IF (z.`ID` like '{$sqlQueryNum}%', 900, 100)
|
|
|
+ ) as _bestFit
|
|
|
";
|
|
|
+ $sqlQuery->orderBy = "order by _bestFit DESC";
|
|
|
} else {
|
|
|
- $sql = "select z.`ID`
|
|
|
- , {$sqlSelectLabel} as `LABEL`
|
|
|
- from `CRM_LISTA_ZASOBOW` as z
|
|
|
- where z.`A_STATUS` in('NORMAL', 'WAITING')
|
|
|
- and (z.`ID` like '%{$query}%' or z.`DESC` like '%{$query}%')
|
|
|
- {$sqlWhere}
|
|
|
- limit {$sqlLimit}
|
|
|
- ";
|
|
|
+ $queryWhereBuilder = new SqlQueryWhereBuilder();
|
|
|
+ $searchWords = $queryWhereBuilder->splitQueryToWords($query);
|
|
|
+ DBG::_('DBG_TS', '>2', "SqlQueryWhereBuilder->splitQueryToWords({$query})", $searchWords, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ $sqlWords = array();
|
|
|
+ if (!empty($searchWords)) {
|
|
|
+ foreach ($searchWords as $word) {
|
|
|
+ if (is_numeric($word)) {
|
|
|
+ $sqlWord = intval($word);
|
|
|
+ $sqlQuery->_queryByWords[] = " ( z.`ID` like '%{$sqlWord}%' or z.`DESC` like '%{$sqlWord}%' ) ";
|
|
|
+ } else {
|
|
|
+ $sqlWord = $db->_($word);
|
|
|
+ $sqlQuery->_queryByWords[] = "z.`DESC` like '%{$sqlWord}%'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
|
|
|
+ if (!empty($sqlQuery->_queryByWords)) {
|
|
|
+ $sqlQuery->whereAddQueryByWords = " and (" . implode(" and ", $sqlQuery->_queryByWords) . ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ $sql = "select z.`ID`
|
|
|
+ , {$sqlQuery->selectLabel} as `LABEL`
|
|
|
+ {$sqlQuery->selectAddBestFit}
|
|
|
+ from `CRM_LISTA_ZASOBOW` as z
|
|
|
+ where z.`A_STATUS` in('NORMAL', 'WAITING')
|
|
|
+ {$sqlQuery->whereAddQueryByWords}
|
|
|
+ {$sqlWhereAddType}
|
|
|
+ {$sqlQuery->orderBy}
|
|
|
+ limit {$sqlQuery->limit}
|
|
|
+ ";
|
|
|
+ DBG::_('DBG_TS', '>2', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
$res = $db->query($sql);
|
|
|
while ($r = $db->fetch($res)) {
|
|
|
$values[] = (object)array('id'=>$r->ID, 'param_out'=>$r->LABEL);
|
|
|
}
|
|
|
- if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">values (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($values);echo'</pre>';}
|
|
|
+ DBG::_('DBG_TS', '>2', "values", $values, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
break;
|
|
|
}
|
|
|
case '__PROCES': {
|